Skip to content

Commit

Permalink
chore: improve update script
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 2, 2025
1 parent a7eeca7 commit 9615601
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Change Log (go-package-manager)

## 0.29.0
## 0.29.1

- feat: self-update by executing `gpm update --self`
- chore: improve (self-)update scripts

## 0.28.0

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ gpm update --self

if you have a valid [sh](https://en.wikipedia.org/wiki/Unix_shell) or [PowerShell](https://en.wikipedia.org/wiki/PowerShell) installed.

You are able to customize final directory with `GPM_BIN_PATH`, which is `C:\Program Files\gpm` on Windows and `/usr/local/bin` on POSIX-like systems by default e.g.

## Usage [<a href="#table-of-contents">↑</a>]

### Commands [<a href="#usage-">↑</a>]
Expand Down
11 changes: 6 additions & 5 deletions sh.kloubert.dev/gpm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ function Handle-Error {
Write-Host "Go Package Manager Updater"
Write-Host ""

# Detect the operating system
$OS = "windows"

Write-Host "Your operating system: $OS"

# Detect the system architecture
$ARCH = $null
switch ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) {
"X64" { $ARCH = "amd64" }
Expand Down Expand Up @@ -95,8 +93,11 @@ try {
Handle-Error "Could not extract 'gpm.exe' binary"
}

# Prompt for installation directory
$DefaultDestination = "C:\\Program Files\\gpm\\gpm.exe"
$DefaultDestination = $env:GPM_BIN_PATH
if ([string]::IsNullOrWhiteSpace($DefaultDestination)) {
$DefaultDestination = "C:\\Program Files\\gpm\\gpm.exe"
}

$Destination = Read-Host "Enter the installation directory (Press Enter to use the default: $DefaultDestination)"
if ([string]::IsNullOrWhiteSpace($Destination)) {
$Destination = $DefaultDestination
Expand All @@ -120,4 +121,4 @@ try {
Handle-Error "Cleanups failed"
}

Write-Host "'gpm.exe' successfully installed or updated πŸ‘" -ForegroundColor Green
Write-Host "'gpm.exe' successfully installed or updated πŸ‘" -ForegroundColor Green
10 changes: 6 additions & 4 deletions sh.kloubert.dev/gpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ handle_error() {
echo "Go Package Manager Updater"
echo ""

GPM_BIN_PATH=${GPM_BIN_PATH:-/usr/local/bin}

case "$(uname -s)" in
Darwin)
OS="darwin"
Expand Down Expand Up @@ -87,11 +89,11 @@ shasum -a 256 gpm.tar.gz.sha256 || handle_error "SHA256 verification failed"
echo "Extracting binary ..."
tar -xzOf gpm.tar.gz gpm > gpm || handle_error "Could not extract 'gpm' binary"

echo "Installing 'gpm' to /usr/local/bin ..."
sudo mv gpm /usr/local/bin/gpm || handle_error "Could not move 'gpm' to '/usr/local/bin'"
sudo chmod +x /usr/local/bin/gpm || handle_error "Could not update permissions of 'gpm' binary"
echo "Installing 'gpm' to $GPM_BIN_PATH ..."
sudo mv gpm "$GPM_BIN_PATH/gpm" || handle_error "Could not move 'gpm' to '$GPM_BIN_PATH'"
sudo chmod +x "$GPM_BIN_PATH/gpm" || handle_error "Could not update permissions of 'gpm' binary"

echo "Cleaning up ..."
rm gpm.tar.gz gpm.tar.gz.sha256 || handle_error "Cleanups failed"

echo "'gpm' successfully installed or updated πŸ‘"
echo "'gpm' successfully installed or updated πŸ‘"

0 comments on commit 9615601

Please sign in to comment.