Skip to content

Commit

Permalink
Add an install aws cli function
Browse files Browse the repository at this point in the history
So that we allow this package to manage aws installation on cloud.gov
when it needs it.
  • Loading branch information
asteel-gsa committed May 3, 2024
1 parent 87cb2f0 commit a7518b9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
49 changes: 49 additions & 0 deletions internal/util/installaws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package util

import (
"os"
"strings"

"github.com/bitfield/script"
"gov.gsa.fac.cgov-util/internal/logging"
)

func InstallAWS() {
// curl -x $https_proxy -L "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
getaws := []string{
"curl",
"-x",
os.Getenv("https_proxy"),
"-L",
"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip",
"-o",
"awscliv2.zip",
}
curlaws := strings.Join(getaws[:], " ")
logging.Logger.Printf("Fetching aws cli via curl...")
script.Exec(curlaws)

// unzip awscliv2.zip && rm awscliv2.zip
unzipaws := []string{
"unzip",
"awscliv2.zip",
"&&",
"rm",
"awscliv2.zip",
}
logging.Logger.Printf("Unzipping aws cli...")
unzip := strings.Join(unzipaws[:], " ")
script.Exec(unzip)

// ./aws/install -i ~/usr -b ~/bin
installaws := []string{
"./aws/install",
"-i",
"~/usr",
"-b",
"~/bin",
}
logging.Logger.Printf("Installing aws to bin...")
install := strings.Join(installaws[:], " ")
script.Exec(install)
}
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"golang.org/x/exp/slices"

"gov.gsa.fac.cgov-util/cmd"
"gov.gsa.fac.cgov-util/internal/logging"
"gov.gsa.fac.cgov-util/internal/util"
"gov.gsa.fac.cgov-util/internal/vcap"
)

Expand All @@ -34,7 +36,13 @@ func readConfig() {
}

func main() {

if slices.Contains([]string{"DEV", "PREVIEW", "STAGING", "PRODUCTION"}, os.Getenv("ENV")) {
logging.Logger.Printf("ENV detected to be a cloud.gov environment. Installing AWS CLI.")
util.InstallAWS()
} else {
logging.Logger.Printf("ENV set to local, aws not necessary to install.")
}
readConfig()
util.SetPaths(os.Getenv("ENV"))
cmd.Execute()
}

0 comments on commit a7518b9

Please sign in to comment.