Skip to content

Commit

Permalink
docs: update install description
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 29, 2024
1 parent 49225b4 commit 260014b
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 45 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Change Log (go-package-manager)

## 0.22.0
## 0.22.1

- **BREAKING CHANGE**: default AI model for Open AI is `gpt-4o-mini` now
- **BREAKING CHANGE**: default AI model for Ollama is `llama3.3` now
- feat: `generate project` command that generates a Go project with natural language
- docs: can directly update `gpm` from `sh.kloubert.dev` server now

## 0.21.3

Expand Down
53 changes: 9 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

- [Overview](#overview-)
- [Installation](#installation-)
- [Linux / UNIX](#linux--unix-)
- [MacOS](#macos-)
- [MacOS / Linux / UNIX](#macos--linux--unix-)
- [Windows](#windows-)
- [Build from source](#build-from-source-)
- [Usage](#usage-)
Expand Down Expand Up @@ -76,60 +75,26 @@ However, it's not only limited to Go but can also be utilized for other project

You can install `gpm` from a [pre-build binary](https://github.com/mkloubert/go-package-manager/releases) or build it by your own:

### Linux / UNIX [<a href="#installation-">↑</a>]
### MacOS / Linux / UNIX [<a href="#installation-">↑</a>]

The following [curl operation(s)](https://curl.se/) will download the latest version [from GitHub](https://github.com/mkloubert/go-package-manager/releases) and extract it to `/usr/local/bin` as `gpm` executable, which should be part of the `$PATH` environment variable (this also requires [jq tool](https://github.com/jqlang/jq)):
You can simply execute the follow remote [shell script](https://sh.kloubert.dev/gpm.sh):

```bash
# replace "<!!!OS!!!>" with one of the following values:
# - "openbsd"
# - "linux"
# - "freebsd"
#
# replace "<!!!CPU!!!>" with one of the following values:
# - "386": Intel compatible (32-bit)
# - "amd64": Intel compatible (64-bit)
# - "arm": ARM (32-bit)
# - "arm64": ARM (64-bit)
curl -s https://api.github.com/repos/mkloubert/go-package-manager/releases/latest | jq -r '.assets[].browser_download_url | select(contains("<!!!OS!!!>") and contains("<!!!CPU!!!>") and (. | tostring | contains("sha256") | not))' | xargs curl -sL | tar xzOf - gpm | sudo tee /usr/local/bin/gpm > /dev/null && sudo chmod +x /usr/local/bin/gpm
wget -qO- "https://sh.kloubert.dev/gpm.sh" | sh
```

Later, you can also execute the following command, which will install a script named `gpm-update` in `$HOME/.gpm/bin` folder:

```bash
gpm setup updater
```

### MacOS [<a href="#installation-">↑</a>]

The following [curl operation(s)](https://formulae.brew.sh/formula/curl) will download the latest version [from GitHub](https://github.com/mkloubert/go-package-manager/releases) and extract it to `/usr/local/bin` as `gpm` executable, which should be part of the `$PATH` environment variable (this also requires [jq tool](https://formulae.brew.sh/formula/jq)):

```bash
# Apple Silicon
curl -s https://api.github.com/repos/mkloubert/go-package-manager/releases/latest | jq -r '.assets[].browser_download_url | select(contains("darwin") and contains("arm64") and (. | tostring | contains("sha256") | not))' | xargs curl -sL | tar xzOf - gpm | sudo tee /usr/local/bin/gpm > /dev/null && sudo chmod +x /usr/local/bin/gpm

# use the following commands if you use a legacy Intel 64-bit system
# curl -s https://api.github.com/repos/mkloubert/go-package-manager/releases/latest | jq -r '.assets[].browser_download_url | select(contains("darwin") and contains("amd64") and (. | tostring | contains("sha256") | not))' | xargs curl -sL | tar xzOf - gpm | sudo tee /usr/local/bin/gpm > /dev/null && sudo chmod +x /usr/local/bin/gpm
```

Later, you can also execute the following command, which will install a script named `gpm-update` in `$HOME/.gpm/bin` folder:

```bash
gpm setup updater
```
Later you can run the command again to update the tool as well.

### Windows [<a href="#installation-">↑</a>]

will download the latest version [from GitHub](https://github.com/mkloubert/go-package-manager/releases) and extract it to `C:\Program Files\gpm` as `gpm.exe` executable, which should be made part of the `PATH` environment variable:
You can simply execute the follow remote [PowerShell script](https://sh.kloubert.dev/gpm.ps1):

```powershell
# replace "<!!!CPU!!!>" with one of the following values:
# - "386": Intel compatible (32-bit)
# - "amd64": Intel compatible (64-bit)
# - "arm": ARM (32-bit)
Invoke-WebRequest 'https://api.github.com/repos/mkloubert/go-package-manager/releases/latest' -UseBasicParsing | ConvertFrom-Json | % { $_.assets | Where-Object { $_.browser_download_url -like '*windows*<!!!CPU!!!>*.zip' -and $_.browser_download_url -notlike '*sha256*' } | Select-Object -ExpandProperty browser_download_url -First 1 } | % { $url=$_; $output="gpm.zip"; Invoke-WebRequest $url -OutFile $output; Expand-Archive $output -DestinationPath "$env:TEMP\gpm" -Force; New-Item -ItemType Directory -Path "C:\Program Files\gpm" -Force | Out-Null; Copy-Item "$env:TEMP\gpm\gpm.exe" -Destination "C:\Program Files\gpm" }
Invoke-WebRequest -Uri "https://sh.kloubert.dev/gpm.ps1" | Select-Object -ExpandProperty Content | Invoke-Expression
```

Later you should be able to run the command again to update the tool as well.

### Build from source [<a href="#installation-">↑</a>]

```bash
Expand Down
123 changes: 123 additions & 0 deletions sh.kloubert.dev/gpm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
function Handle-Error {
param (
[string]$Message
)
Write-Host "Error: $Message" -ForegroundColor Red
exit 1
}

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" }
"X86" { $ARCH = "386" }
"Arm" { $ARCH = "arm" }
"Arm64" { $ARCH = "arm64" }
default {
$ARCH = "unknown"
Handle-Error "Unknown architecture detected!"
}
}

$ARCH = "386"

Write-Host "Your architecture: $ARCH"
Write-Host ""

Write-Host "Finding download URL and SHA256 URL ..."

# Fetch the latest release info
try {
$LatestReleaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/mkloubert/go-package-manager/releases/latest"
} catch {
Handle-Error "Could not fetch release infos"
}

$DownloadUrl = $LatestReleaseInfo.assets | Where-Object {
$_.browser_download_url -match "gpm" -and
$_.browser_download_url -match $OS -and
$_.browser_download_url -match $ARCH -and
$_.browser_download_url -notmatch "sha256"
} | Select-Object -ExpandProperty browser_download_url

$Sha256Url = $LatestReleaseInfo.assets | Where-Object {
$_.browser_download_url -match "gpm" -and
$_.browser_download_url -match $OS -and
$_.browser_download_url -match $ARCH -and
$_.browser_download_url -match "sha256"
} | Select-Object -ExpandProperty browser_download_url

if (-not $DownloadUrl) {
Handle-Error "No valid download URL found"
}
if (-not $Sha256Url) {
Handle-Error "No valid SHA256 URL found"
}

Write-Host "Downloading zip file from '$DownloadUrl'..."
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile "gpm.zip"
} catch {
Handle-Error "Failed to download zip file"
}

Write-Host "Downloading SHA256 file from '$Sha256Url'..."
try {
Invoke-WebRequest -Uri $Sha256Url -OutFile "gpm.zip.sha256"
} catch {
Handle-Error "Failed to download SHA256 file"
}

Write-Host "Verifying zip file ..."
try {
$Sha256Value = Get-Content "gpm.zip.sha256"
$CalculatedHash = (Get-FileHash -Path "gpm.zip" -Algorithm SHA256).Hash
if ($Sha256Value -ne $CalculatedHash) {
Handle-Error "SHA256 verification failed"
}
} catch {
Handle-Error "SHA256 verification failed"
}

Write-Host "Extracting binary ..."
try {
Expand-Archive -Path "gpm.zip" -DestinationPath "gpm_extracted" -Force
Move-Item -Path "gpm_extracted\gpm.exe" -Destination "gpm.exe"
} catch {
Handle-Error "Could not extract 'gpm.exe' binary"
}

# Prompt for installation directory
$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
}

Write-Host "Installing 'gpm.exe' to $Destination ..."
try {
$DestinationFolder = Split-Path -Path $Destination -Parent
if (-not (Test-Path $DestinationFolder)) {
New-Item -ItemType Directory -Path $DestinationFolder
}
Move-Item -Path gpm.exe -Destination $Destination -Force
} catch {
Handle-Error "Could not move 'gpm.exe' to '$Destination'"
}

Write-Host "Cleaning up ..."
try {
Remove-Item -Path "gpm.zip", "gpm.zip.sha256", "gpm_extracted" -Recurse -Force
} catch {
Handle-Error "Cleanups failed"
}

Write-Host "'gpm.exe' successfully installed or updated 👍" -ForegroundColor Green
97 changes: 97 additions & 0 deletions sh.kloubert.dev/gpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

handle_error() {
echo "Error: $1"
exit 1
}

echo "Go Package Manager Updater"
echo ""

case "$(uname -s)" in
Darwin)
OS="darwin"
;;
Linux)
OS="linux"
;;
FreeBSD)
OS="freebsd"
;;
OpenBSD)
OS="openbsd"
;;
CYGWIN*|MINGW*|MSYS*|Windows_NT)
OS="windows"
;;
*)
OS="unknown"
echo "Error: Unknown operating system detected!"
exit 1
;;
esac

echo "Your operating system: $OS"

# Detect the system architecture
case "$(uname -m)" in
x86_64)
ARCH="amd64"
;;
i*86)
ARCH="386"
;;
armv7*|armv6*|armv5*)
ARCH="arm"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
ARCH="unknown"
echo "Error: Unknown architecture detected!"
exit 1
;;
esac

echo "Your architecture: $ARCH"
echo ""

echo "Finding download URL and SHA256 URL ..."
latest_release_info=$(wget -qO- https://api.github.com/repos/mkloubert/go-package-manager/releases/latest) || handle_error "Could not fetch release infos"

download_url=$(echo "$latest_release_info" | jq -r \
".assets[].browser_download_url | select(contains(\"gpm\") and contains(\"$OS\") and contains(\"$ARCH\") and (. | tostring | contains(\"sha256\") | not))") \
|| handle_error "Could not parse download URL"
sha256_url=$(echo "$latest_release_info" | jq -r \
".assets[].browser_download_url | select(contains(\"gpm\") and contains(\"$OS\") and contains(\"$ARCH\") and contains(\"sha256\"))") \
|| handle_error "Could not parse SHA256 URL"

if [ -z "$download_url" ]; then
handle_error "No valid download URL found"
fi

if [ -z "$sha256_url" ]; then
handle_error "No valid SHA256 URL found"
fi

echo "Downloading tarball from '$download_url'..."
wget -q "$download_url" -O gpm.tar.gz || handle_error "Failed to download tarball"

echo "Downloading SHA256 file from '$sha256_url'..."
wget -q "$sha256_url" -O gpm.tar.gz.sha256 || handle_error "Failed to download SHA256 file"

echo "Verifying tarball ..."
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 "Cleaning up ..."
rm gpm.tar.gz gpm.tar.gz.sha256 || handle_error "Cleanups failed"

echo "'gpm' successfully installed or updated 👍"

0 comments on commit 260014b

Please sign in to comment.