Auto-Update?
Woolersuk opened this issue · comments
I noted you've been releasing a lot lately, so I wondered if it might be an idea to have an update option in pike where you can update to the latest release using the tool?
For Windows/Linux I wrote a couple of scripts that I've scheduled to check daily & pull the latest version, but might be an idea?
Scripts for info, or if you can't be bothered to do an auto-updater, maybe you could include these somewhere if someone else might want to use? (I'm don't have a Mac so can't write something for that).
Windows/Powershell: (uncommenting the last line if you want options to be different)
function GetLatestPike {
param (
[parameter(Mandatory = $false)]$Match = "windows_amd64",
[parameter(Mandatory = $false)]$Root = "$env:userprofile\Downloads",
[parameter(Mandatory = $false)]$Target = "C:\Windows"
)
$ProgressPreference = "SilentlyContinue"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$GithubUrl = "https://api.github.com/repos/JamesWoolfenden/pike/releases/latest"
$Response = Invoke-WebRequest -Uri $GithubUrl -MaximumRedirection 0 -ErrorAction SilentlyContinue
$LatestRelease = $Response.Content | ConvertFrom-Json
$LatestUrl = $LatestRelease.assets | Where-Object { $_.browser_download_url -like "*$Match*" }
$LatestName = $LatestUrl.name
$zipDownloadUrl = $LatestUrl.browser_download_url
$DLFol = Join-Path -Path $Root -ChildPath $LatestName.Replace(".zip", "")
if (-not (Test-Path -Path $DLFol -PathType Container)) {
New-Item -Path $DLFol -ItemType Directory | out-null
Write-Host "Folder: $DLFol created.." -Fore Cyan
} else {
Write-Host "The latest version is already present... exiting.." -Fore Yellow
break
}
$zipFilePath = Join-Path -Path $DLFol -ChildPath $LatestName
Invoke-WebRequest -Uri $zipDownloadUrl -OutFile $zipFilePath
Expand-Archive -Path $zipFilePath -DestinationPath $DLFol -Force
Remove-Item -Path $zipFilePath
Copy-Item -Path "$DLFol\pike.exe" -Destination "$Target\pike.exe" -Force
Write-Host "Latest pike installed from $DLFol.." -Fore Green
}
GetLatestPike #-Match windows_amd64 -Root C:\tmp -Target c:\Windows
Linux/Bash: (uncommenting the last line if you want options to be different)
#!/bin/bash
get_latest_pike() {
local Match="${1:-linux_amd64}"
local Root="${2:-/home/alex/Downloads}"
local Target="${3:-/usr/local/bin}"
local GithubUrl="https://api.github.com/repos/JamesWoolfenden/pike/releases/latest"
local LatestRelease
LatestRelease=$(curl -s "$GithubUrl")
local LatestUrl
LatestUrl=$(echo "$LatestRelease" | jq -r '.assets[] | select(.browser_download_url | contains("'"$Match"'")) | .browser_download_url')
if [ -z "$LatestUrl" ]; then
echo "No matching asset found for $Match"
exit 1
fi
local LatestName
LatestName=$(basename "$LatestUrl")
local ext=".tar.gz"
local zipDownloadUrl="$LatestUrl"
local DLFol="$Root/${LatestName%$ext}"
if [ ! -d "$DLFol" ]; then
mkdir -p "$DLFol"
echo "Folder: $DLFol created.."
else
echo "The latest version is already present... exiting.."
exit 0
fi
local zipFilePath="$DLFol/$LatestName"
curl -L -o "$zipFilePath" "$zipDownloadUrl"
tar -xzf "$zipFilePath" -C "$DLFol"
rm -f "$zipFilePath"
cp "$DLFol/pike" "$Target/pike"
echo "Latest pike installed from $DLFol.."
}
get_latest_pike #"other_match" "/path/to/root" "/path/to/target"
Cheers
id prefer a go based solution? pike is supported in both brew and scoop so updating should be pretty easy?
I'll leave that with you :)