Skip to content

Commit

Permalink
Merge pull request #19 from local-deploy/DL-T-21
Browse files Browse the repository at this point in the history
detect arm architecture when upgrading
  • Loading branch information
varrcan authored Aug 23, 2022
2 parents c5e5340 + f0857f1 commit af3fc12
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
46 changes: 41 additions & 5 deletions command/self_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"errors"
"fmt"
"io"
ioutil "io/ioutil"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -273,11 +274,26 @@ func extractArchive(archivePath string) error {
}

func copyBin() error {
var err error
var (
err error
system string
arch string
)

binPath, _ := helper.BinPath()
// TODO: Darwin
tmpLinuxBin := filepath.Join(os.TempDir(), "dl", "bin", "dl_linux_amd64")

system, err = getSystem()
if err != nil {
return err
}

arch, err = getArch()
if err != nil {
return err
}

tmpLinuxBin := strings.Join([]string{"dl", system, arch}, "_")
tmpBinPath := filepath.Join(os.TempDir(), "dl", "bin", tmpLinuxBin)

if helper.IsBinFileExists() {
err = os.Remove(binPath)
Expand All @@ -286,14 +302,34 @@ func copyBin() error {
}
}

bytesRead, err := ioutil.ReadFile(tmpLinuxBin)
bytesRead, err := ioutil.ReadFile(tmpBinPath)
err = ioutil.WriteFile(binPath, bytesRead, 0775) //nolint:gosec
if err != nil {
return err
}
return nil
}

func getSystem() (string, error) {
system := runtime.GOOS

switch system {
case "linux", "darwin":
return system, nil
}
return "", errors.New(fmt.Sprintf("This installer does not support %s platform at this time", system))
}

func getArch() (string, error) {
arch := runtime.GOARCH

switch arch {
case "amd64", "arm64":
return arch, nil
}
return "", errors.New(fmt.Sprintf("Your machine architecture %s is not currently supported", arch))
}

func copyConfigFiles() error {
confDir, _ := helper.ConfigDir()

Expand Down
2 changes: 1 addition & 1 deletion install_dl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case $(uname) in
Darwin) os="darwin" ;;
esac

if [[ $architecture == "" ]]; then
if [[ $os == "" ]]; then
printf "${RED}Sorry, this installer does not support %s platform at this time${RESET}\n" "$(uname)" && exit 1
fi

Expand Down

0 comments on commit af3fc12

Please sign in to comment.