Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect arm architecture when upgrading #19

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions command/self_update.go
Original file line number Diff line number Diff line change
@@ -7,10 +7,11 @@ import (
"errors"
"fmt"
"io"
ioutil "io/ioutil"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
"time"

@@ -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)
@@ -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()

2 changes: 1 addition & 1 deletion install_dl.sh
Original file line number Diff line number Diff line change
@@ -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