From f070f939e125075b2e385ec39323d5f3ca9d2459 Mon Sep 17 00:00:00 2001 From: Elia Bracci Date: Tue, 20 Dec 2022 16:47:21 +0100 Subject: [PATCH] Added M1 fix for old tg version --- install.sh | 2 +- lib/install.go | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) mode change 100644 => 100755 install.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index d2a0c11..c187a03 --- a/install.sh +++ b/install.sh @@ -337,7 +337,7 @@ End of functions from https://github.com/client9/shlib EOF PROJECT_NAME="tgswitch" -OWNER=warrensbox +OWNER=EliaBracciSumo REPO="tgswitch" BINARY=tgswitch FORMAT=tar.gz diff --git a/lib/install.go b/lib/install.go index e71741c..fc0681d 100644 --- a/lib/install.go +++ b/lib/install.go @@ -9,6 +9,8 @@ import ( "regexp" "runtime" "strings" + + semver "github.com/hashicorp/go-version" ) const ( @@ -140,7 +142,7 @@ func GetRecentVersions() ([]string, error) { return nil, nil } -//CreateRecentFile : create a recent file +// CreateRecentFile : create a recent file func CreateRecentFile(requestedVersion string) { installLocation = GetInstallLocation() @@ -168,7 +170,7 @@ func ValidVersionFormat(version string) bool { return semverRegex.MatchString(version) } -//Install : Install the provided version in the argument +// Install : Install the provided version in the argument func Install(tgversion string, usrBinPath string, mirrorURL string) string { /* Check to see if user has permission to the default bin location which is "/usr/local/bin/terragrunt" * If user does not have permission to default bin location, proceed to create $HOME/bin and install the tgswitch there @@ -182,6 +184,15 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string { goarch := runtime.GOARCH goos := runtime.GOOS + versionObj, err := semver.NewVersion(tgversion) + + // Constraint for darwin M1. Terragrunt started release arm64 versions for linux and darwin OS from version 0.28.12 included. + // However, amd64 versions work on darwin arm64. To be tested on linux platforms. + darwinM1constraint, err := semver.NewConstraint("< 0.28.12") + if darwinM1constraint.Check(versionObj) && goarch == "arm64" && goos == "darwin" { + fmt.Printf("%s satisfies constraints %s", versionObj, darwinM1constraint) + goarch = "amd64" + } /* check if selected version already downloaded */ installFileVersionPath := ConvertExecutableExt(filepath.Join(installLocation, installVersion+tgversion)) @@ -244,9 +255,9 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string { return "" } -//InstallableBinLocation : Checks if terragrunt is installable in the location provided by the user. -//If not, create $HOME/bin. Ask users to add $HOME/bin to $PATH -//Return $HOME/bin as install location +// InstallableBinLocation : Checks if terragrunt is installable in the location provided by the user. +// If not, create $HOME/bin. Ask users to add $HOME/bin to $PATH +// Return $HOME/bin as install location func InstallableBinLocation(userBinPath string) string { usr, errCurr := user.Current() @@ -294,7 +305,7 @@ func PrintCreateDirStmt(unableDir string, writable string) { fmt.Printf("RUN `export PATH=$PATH:%s` to append bin to $PATH\n", writable) } -//ConvertExecutableExt : convert excutable with local OS extension +// ConvertExecutableExt : convert excutable with local OS extension func ConvertExecutableExt(fpath string) string { switch runtime.GOOS { case "windows":