Skip to content

Instantly share code, notes, and snippets.

Created October 20, 2021 18:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Update a folder/file from the latest matching GitHub release
#!/usr/bin/env fish
# Declare some constants to be used later
set -g filename
set -g base_url
set -g release_file current_release.txt
if ! type -q wsl.exe
# Running on actual Linux
set filename omnisharp-linux-x64.tar.gz
# Declare some helper functions to be used later
functions -e dl 2>/dev/null
function dl
aria2c -j8 -x8 --min-split-size=4M --file-allocation=trunc \
--console-log-level=warn \
--conditional-get=true --allow-overwrite=true \
$argv # | command grep -v -e "Download Results" -e "Status Legend" -e "download completed"
function split_name
string match -iqr '^(?<basename>.*?)(?<extension>(?:\.[a-z]{3})?\.[^.]+)$' -- $argv[1]
echo $basename
echo $extension
function error
set_color red
echo $argv 1>&2
set_color normal
exit -1
function success
set_color green
echo $argv
set_color normal
exit 0
# Get the latest release's name
curl $base_url/releases/latest -H "Accept: application/json" -sLo - | jq -r .tag_name | read -l release_name
or error "Error checking for an updated release!"
# See if an update is required
if test -f $release_file \
&& read -l prev_release < $release_file \
&& string match -q -- $release_name $prev_release
success "No update is needed!"
if ! set -q prev_release
set -g prev_release unknown
echo "Upgrading from $prev_release to $release_name"
set name (split_name $filename)
set old_name $name[1].$prev_release$name[2]
set new_name $name[1].$release_name$name[2]
echo " * Downloading latest version"
dl $base_url/releases/download/$release_name/$filename -o $new_name
or error "Error downloading update!" 1>&2
set unarchive_cmd
if string match -qr '\.tar' -- $new_name
set unarchive_cmd tar -xf $new_name
else if string match -qr '\.zip' -- $new_name
set unarchive_cmd unzip -qqo $new_name
if set -q unarchive_cmd
echo " * Extracting $new_name"
command $unarchive_cmd
or error "Error extracting archive! \
You might need to restore from $old_name if archive was partially extracted!"
# Save the release name for future runs
echo $release_name > $release_file
success "Upgrade complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment