1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq common-updater-scripts
6 cd "$(dirname "${BASH_SOURCE[0]}")"
8 # Fetch the latest stable version
9 LATEST_STABLE_TAG
=$
(curl
${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https
://api.github.com
/repos
/coder
/coder
/releases
/latest | jq
-r '.tag_name')
10 LATEST_STABLE_VERSION
=$
(echo ${LATEST_STABLE_TAG} |
sed 's/^v//')
12 # Fetch the latest mainline version
13 LATEST_MAINLINE_TAG
=$
(curl
${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https
://api.github.com
/repos
/coder
/coder
/releases | jq
-r '.[0].tag_name')
14 LATEST_MAINLINE_VERSION
=$
(echo ${LATEST_MAINLINE_TAG} |
sed 's/^v//')
16 # Define the platforms
17 declare -A ARCHS
=(["x86_64-linux"]="linux_amd64.tar.gz"
18 ["aarch64-linux"]="linux_arm64.tar.gz"
19 ["x86_64-darwin"]="darwin_amd64.zip"
20 ["aarch64-darwin"]="darwin_arm64.zip")
22 update_version_and_hashes
() {
26 # Update version number, using '#' as delimiter
27 sed -i "/${channel} = {/,/};/{
28 s#^\(\s*\)version = .*#\1version = \"$version\";#
31 # Update hashes for each architecture
32 for ARCH
in "${!ARCHS[@]}"; do
33 local URL
="https://github.com/coder/coder/releases/download/v${version}/coder_${version}_${ARCHS[$ARCH]}"
34 echo "Fetching hash for $channel/$ARCH..."
36 # Fetch the new hash using nix-prefetch-url
37 local NEW_HASH
=$
(nix-prefetch-url
--type sha256
$URL)
38 local SRI_HASH
=$
(nix
hash to-sri
--type sha256
$NEW_HASH)
40 # Update the Nix file with the new hash, using '#' as delimiter and preserving indentation
41 sed -i "/${channel} = {/,/};/{
42 s#^\(\s*\)${ARCH} = .*#\1${ARCH} = \"${SRI_HASH}\";#
47 # Update stable channel
48 update_version_and_hashes
$LATEST_STABLE_VERSION "stable"
50 # Update mainline channel
51 update_version_and_hashes
$LATEST_MAINLINE_VERSION "mainline"