Skip to content

Commit

Permalink
align install and upgrade with XDG spec
Browse files Browse the repository at this point in the history
An existing install in the ~/.sst/bin dir is not removed during the `sst
upgrade` command nor is the $PATH modified by `sst upgrade`.

When there is an existing install of sst prior to this commit, the
safest upgrade path is to:
1. delete the ~/.sst dir
2. remove ~/.sst/bin from $PATH by editing the right shell cfg file
3. rerun the install script
  • Loading branch information
arockett committed May 4, 2024
1 parent 60fa76c commit 8b21eff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ case "$filename" in
;;
esac

INSTALL_DIR=$HOME/.sst/bin
INSTALL_DIR=${XDG_BIN_HOME:-$HOME/.local/bin}
mkdir -p "$INSTALL_DIR"

url="https://github.com/sst/ion/releases/latest/download/$filename"
Expand Down
31 changes: 22 additions & 9 deletions pkg/global/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,11 @@ func Upgrade(existingVersion string, nextVersion string) (string, error) {
return "", fmt.Errorf("unexpected HTTP status when downloading release: %s", resp.Status)
}

homeDir, err := os.UserHomeDir()
tmpReleaseDir, err := os.MkdirTemp("", "sst")
if err != nil {
return "", err
}

sstBinPath := filepath.Join(homeDir, ".sst", "bin")
os.RemoveAll(sstBinPath)
if err := os.MkdirAll(sstBinPath, os.ModePerm); err != nil {
return "", err
}
defer os.RemoveAll(tmpReleaseDir)

// Assuming we have a variable `resp` which is the response from a *http.Request
body, err := gzip.NewReader(resp.Body)
Expand All @@ -93,11 +88,29 @@ func Upgrade(existingVersion string, nextVersion string) (string, error) {
}
defer body.Close()

if err := untar(body, sstBinPath); err != nil {
if err := untar(body, tmpReleaseDir); err != nil {
return "", err
}

binHome := os.Getenv("XDG_BIN_HOME")
if binHome == "" {
// Default to ~/.local/bin if $XDG_BIN_HOME not set
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
binHome = filepath.Join(homeDir, ".local", "bin")
}
if err := os.MkdirAll(binHome, os.ModePerm); err != nil {
return "", err
}
sstBinPath := filepath.Join(binHome, "sst")

if err := os.Rename(filepath.Join(tmpReleaseDir, "sst"), sstBinPath); err != nil {
return "", err
}

if err := os.Chmod(filepath.Join(sstBinPath, "sst"), 0755); err != nil {
if err := os.Chmod(sstBinPath, 0755); err != nil {
return "", err
}

Expand Down

0 comments on commit 8b21eff

Please sign in to comment.