Skip to content

Instantly share code, notes, and snippets.

@SamusAranX
Created March 24, 2025 00:45
Show Gist options
  • Save SamusAranX/00a34b96ac2e662f8c31c61dafd4a75c to your computer and use it in GitHub Desktop.
Save SamusAranX/00a34b96ac2e662f8c31c61dafd4a75c to your computer and use it in GitHub Desktop.
Shell script to download the most recent version of headscale for your platform and architecture
#!/usr/bin/env -S bash -l
set -e
OS="";
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux";
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="darwin";
elif [[ "$OSTYPE" == "freebsd"* ]]; then
OS="freebsd";
else
echo "unsupported os $OSTYPE";
exit 1;
fi
ARCH="$(dpkg --print-architecture)"
if ! [[ "$ARCH" =~ ^(amd64|arm64)$ ]]; then
echo "unsupported arch $ARCH";
exit 1;
fi
releases=$(curl -sSf "https://api.github.com/repos/juanfont/headscale/releases")
if [[ $? -ne 0 ]]; then
echo "Error getting GitHub releases";
exit 1;
fi
tag_name=$(jq -r 'first(.[] | [select (.prerelease == false)][]).tag_name' <<< "$releases")
deb_url=$(jq -r 'first(.[] | [select (.prerelease == false)][]).assets[] | select(.browser_download_url | endswith('"\"${OS}_$ARCH"'.deb")).browser_download_url' <<< "$releases")
echo "Latest release: $tag_name";
if [[ -z $deb_url ]]; then
echo "No .deb available for ${OS}_$ARCH";
exit 0;
fi
wget -q --output-document="headscale-$tag_name.deb" "$deb_url";
if [[ $? -ne 0 ]]; then
echo "Download failed!";
exit 1;
fi
echo "headscale-$tag_name.deb downloaded.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment