This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#24 - Refactor install/update scripts
- Loading branch information
Showing
3 changed files
with
70 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
#!/bin/bash | ||
|
||
target_os=$1 | ||
zip_path="$HOME/Downloads/gdman.zip" | ||
install_dir="$HOME/gdman" | ||
t=$1 | ||
z="$HOME/Downloads/gdman.zip" | ||
d="$HOME/gdman" | ||
|
||
# Find the latest release for the target OS | ||
echo "Finding latest version" | ||
download_url=$(curl -s https://api.github.com/repos/devklick/GDMan/releases/latest | jq -r '.assets[] | select(.name | test("'${target_os}'")) | .browser_download_url') | ||
echo "Found $download_url"; | ||
echo Finding latest version | ||
r=$(curl -s https://api.github.com/repos/devklick/GDMan/releases/latest) | ||
u=$(echo "$r" | jq -r --arg t "$t" '.assets[] | select(.name | test($t)) | .browser_download_url') | ||
v=$(echo "$r" | jq -r '.tag_name') | ||
echo Found $v; | ||
|
||
# Download the zip file to the Downloads directory | ||
echo "Downloading" | ||
wget -q "$download_url" -O "$zip_path" | ||
echo Downloading | ||
wget -q "$u" -O "$z" | ||
|
||
# Extract the contents of the zip file to the installation directory | ||
echo "Extracting" | ||
unzip -qq -o "$zip_path" -d "$install_dir" | ||
echo Extracting | ||
unzip -qq -o "$z" -d "$d" | ||
|
||
# Remove the downloaded zip file | ||
rm "$zip_path" | ||
echo "Removing archive" | ||
rm "$z" | ||
echo Removing archive | ||
|
||
# Add gdman directory to the PATH if not already present | ||
if [[ ! ":$PATH:" == *":$install_dir:"* ]]; then | ||
if [[ ! ":$PATH:" == *":$d:"* ]]; then | ||
echo "Adding gdman directory to PATH" | ||
export PATH="$install_dir:$PATH" | ||
echo 'export PATH="'${install_dir}':$PATH"' >> "$HOME/.bashrc" | ||
export PATH="$PATH:$d" | ||
echo 'export PATH="$PATH:'${d}'"' >> "$HOME/.bashrc" | ||
|
||
if [ -e "$HOME/.zshrc" ]; then | ||
echo 'export PATH="'${install_dir}':$PATH"' >> "$HOME/.zshrc" | ||
echo 'export PATH="$PATH:'${d}'"' >> "$HOME/.zshrc" | ||
else | ||
echo ".zshrc not found" | ||
fi | ||
fi | ||
|
||
echo | ||
echo GDMan $v installed successfully | ||
echo For information on usage, invoke: | ||
echo | ||
echo gdman --help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
$r=iwr -useb https://api.github.com/repos/devklick/GDMan/releases/latest | ConvertFrom-Json;$p=($r.assets | where {$_.name -like '*win-x64.zip'}).browser_download_url; Invoke-WebRequest $p -OutFile "$HOME\Downloads\gdman.zip"; Expand-Archive -LiteralPath "$HOME\Downloads\gdman.zip" -DestinationPath "$Env:AppData\gdman" -Force; Remove-Item -Path "$HOME\Downloads\gdman.zip"; $path=[environment]::GetEnvironmentVariable("PATH", "USER"); if ($PATH -notlike "*C:\Users\user\AppData\Roaming\gdman") { [environment]::SetEnvironmentVariable("PATH", "$path;$Env:AppData\gdman", "USER")} | ||
$z = Join-Path -Path $env:USERPROFILE -ChildPath "Downloads\gdman.zip" | ||
$d = Join-Path -Path $env:USERPROFILE -ChildPath "gdman" | ||
|
||
Write-Host Finding latest version | ||
$r = (iwr -useb https://api.github.com/repos/devklick/GDMan/releases/latest | ConvertFrom-Json) | ||
$a = $r.assets | Where-Object { $_.name -match 'win-x64.zip' } | ||
$u = $a | Select-Object -ExpandProperty browser_download_url | ||
$v = $r.tag_name | ||
Write-Host Found $v | ||
|
||
Write-Host Downloading | ||
Invoke-WebRequest -Uri $u -OutFile $z | ||
|
||
Write-Host Extracting | ||
Expand-Archive -Path $z -DestinationPath $d -Force | ||
|
||
Remove-Item -Path $z | ||
Write-Host Removing archive | ||
|
||
if (-not ($env:PATH -split ";" -contains $d)) { | ||
Write-Host Adding gdman directory to PATH | ||
$env:PATH = "$env:PATH;$d" | ||
[System.Environment]::SetEnvironmentVariable("PATH", $env:PATH, [System.EnvironmentVariableTarget]::User) | ||
} | ||
|
||
Write-Host | ||
Write-Host GDMan $v installed successfully | ||
Write-Host "For information on usage, invoke:" | ||
Write-Host | ||
Write-Host gdman --help |