1- import { Resource , ResourceSettings , getPty , SpawnStatus } from 'codify-plugin-lib' ;
1+ import { Resource , ResourceSettings , getPty , SpawnStatus , Utils } from 'codify-plugin-lib' ;
22import { OS , StringIndexedObject } from 'codify-schemas' ;
33import fs from 'node:fs/promises' ;
4+ import os from 'node:os' ;
5+ import path from 'node:path' ;
46
5- import { Utils } from '../../../utils/index.js' ;
67import Schema from './aws-cli-schema.json' ;
78
89export interface AwsCliConfig extends StringIndexedObject {
@@ -16,7 +17,7 @@ export class AwsCliResource extends Resource<AwsCliConfig> {
1617 getSettings ( ) : ResourceSettings < AwsCliConfig > {
1718 return {
1819 schema : Schema ,
19- operatingSystems : [ OS . Darwin ] ,
20+ operatingSystems : [ OS . Darwin , OS . Linux ] ,
2021 id : 'aws-cli' ,
2122 } ;
2223 }
@@ -41,22 +42,24 @@ export class AwsCliResource extends Resource<AwsCliConfig> {
4142 // Amazon has not released a standalone way to install arm aws-cli. See: https://github.com/aws/aws-cli/issues/7252
4243 // Prefer the homebrew version on M1
4344 const isArmArch = await Utils . isArmArch ( ) ;
44- const isRosettaInstalled = await Utils . isRosetta2Installed ( )
45- const isHomebrewInstalled = await Utils . isHomebrewInstalled ( ) ;
46-
47- if ( isArmArch && isHomebrewInstalled ) {
48- console . log ( 'Resource: \'aws-cli\'. Detected that mac is aarch64. Installing AWS-CLI via homebrew' )
49- await $ . spawn ( 'HOMEBREW_NO_AUTO_UPDATE=1 brew install awscli' , { interactive : true } )
50-
51- } else if ( ! isArmArch || isRosettaInstalled ) {
52- console . log ( 'Resource: \'aws-cli\'. Detected that mac is not ARM or Rosetta is installed. Installing AWS-CLI standalone version' )
53- await $ . spawn ( 'curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"' ) ;
54- await $ . spawn ( 'installer -pkg ./AWSCLIV2.pkg -target /' , { requiresRoot : true } )
55- await fs . rm ( './AWSCLIV2.pkg' , { recursive : true , force : true } ) ;
56-
57- } else {
58- // This covers arm arch + Homebrew is not installed
59- throw new Error ( `Resource: 'aws-cli'. This plugin prefers installing AWS-CLI via homebrew for M1 macs.
45+
46+ if ( Utils . isMacOS ( ) ) {
47+ const isRosettaInstalled = await Utils . isRosetta2Installed ( )
48+ const isHomebrewInstalled = await Utils . isHomebrewInstalled ( ) ;
49+
50+ if ( isArmArch && isHomebrewInstalled ) {
51+ console . log ( 'Resource: \'aws-cli\'. Detected that mac is aarch64. Installing AWS-CLI via homebrew' )
52+ await $ . spawn ( 'HOMEBREW_NO_AUTO_UPDATE=1 brew install awscli' , { interactive : true } )
53+
54+ } else if ( ! isArmArch || isRosettaInstalled ) {
55+ console . log ( 'Resource: \'aws-cli\'. Detected that mac is not ARM or Rosetta is installed. Installing AWS-CLI standalone version' )
56+ await $ . spawn ( 'curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"' ) ;
57+ await $ . spawn ( 'installer -pkg ./AWSCLIV2.pkg -target /' , { requiresRoot : true } )
58+ await fs . rm ( './AWSCLIV2.pkg' , { recursive : true , force : true } ) ;
59+
60+ } else {
61+ // This covers arm arch + Homebrew is not installed
62+ throw new Error ( `Resource: 'aws-cli'. This plugin prefers installing AWS-CLI via homebrew for M1 macs.
6063AWS has not updated the standalone installer to support M1 macs. See: https://github.com/aws/aws-cli/issues/7252.
6164
6265Homebrew can be installed by adding:
@@ -68,6 +71,14 @@ Or enable rosetta 2 using the below command and re-run:
6871
6972softwareupdate --install-rosetta
7073 ` ) ;
74+ }
75+ } else if ( Utils . isLinux ( ) ) {
76+ const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'codify-aws-cli' ) ) ;
77+
78+ await $ . spawn ( 'curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"' , { cwd : tmpDir } ) ;
79+ await $ . spawn ( 'unzip -q awscliv2.zip' , { cwd : tmpDir } ) ;
80+ await $ . spawn ( './aws/install' , { cwd : tmpDir , requiresRoot : true } ) ;
81+ await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
7182 }
7283 }
7384
@@ -78,17 +89,17 @@ softwareupdate --install-rosetta
7889 if ( ! installLocation ) {
7990 return ;
8091 }
81-
92+
8293 if ( installLocation . includes ( 'homebrew' ) ) {
8394 await $ . spawn ( 'brew uninstall awscli' , { interactive : true , env : { HOMEBREW_NO_AUTO_UPDATE : 1 } } ) ;
8495 return ;
8596 }
86-
97+
8798 await $ . spawn ( `rm ${ installLocation } ` , { requiresRoot : true } ) ;
8899 await $ . spawn ( `rm ${ installLocation } _completer` , { requiresRoot : true } ) ;
89100 await $ . spawn ( 'rm -rf $HOME/.aws/' ) ;
90101 }
91-
102+
92103 private async findInstallLocation ( ) : Promise < null | string > {
93104 const $ = getPty ( ) ;
94105 const query = await $ . spawnSafe ( 'which aws' , { interactive : true } ) ;
0 commit comments