Skip to content

Instantly share code, notes, and snippets.

@superstes
Last active December 4, 2023 10:37
Show Gist options
  • Save superstes/fe98354c51d919372546ee3c8bf9be6d to your computer and use it in GitHub Desktop.
Save superstes/fe98354c51d919372546ee3c8bf9be6d to your computer and use it in GitHub Desktop.
Script to download latest GitHub release
#!/bin/bash
# tested for downloading golang binaries
set -euo pipefail
GH_USER='superstes'
GH_REPO='geoip-lookup-service'
FILTER=''
FILTER_EXCLUDE='$%&'
CPU_ARCH="$(uname -i)"
if [[ "$CPU_ARCH" == "x86_64" ]]
then
CPU_ARCH="amd64"
fi
TARGET_SYSTEM="linux-${CPU_ARCH}"
url="$(curl -s "https://api.github.com/repos/${GH_USER}/${GH_REPO}/releases/latest" | grep 'download_url' | grep "$TARGET_SYSTEM" | grep "$FILTER" | grep -Ev "$FILTER_EXCLUDE" | head -n 1 | cut -d '"' -f 4)"
if [[ -z "$url" ]]
then
echo "ERROR: No matching asset found!"
exit 1
fi
echo "DOWNLOADING ${url}"
cd '/tmp'
wget "$url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment