22set -euo pipefail
33
44REPO=" block/goose"
5- FILE=" goose"
65OUT_FILE=" goose"
76GITHUB_API_ENDPOINT=" api.github.com"
87
98function gh_curl() {
109 curl -sL -H " Accept: application/vnd.github.v3.raw" $@
1110}
1211
13- # Find the goose binary asset id without using jq
12+ # Determine the operating system and architecture
13+ OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
14+ ARCH=$( uname -m)
15+
16+ case " $ARCH " in
17+ x86_64)
18+ ARCH=" x86_64"
19+ ;;
20+ arm64)
21+ ARCH=" aarch64"
22+ ;;
23+ * )
24+ echo " ERROR: Unsupported architecture: $ARCH "
25+ exit 1
26+ ;;
27+ esac
28+
29+ FILE=" goose-$ARCH -unknown-linux-gnu.tar.bz2"
30+ if [ " $OS " = " darwin" ]; then
31+ FILE=" goose-$ARCH -apple-darwin.tar.bz2"
32+ fi
33+
34+ # Find the goose binary asset id
1435echo " Looking up the most recent goose binary release..."
1536echo " "
1637RELEASES=$( gh_curl https://$GITHUB_API_ENDPOINT /repos/$REPO /releases)
1738
18- # Use awk to find the asset ID
19- # This script looks for the first prerelease and within it finds the asset with matching name
39+ # Parse JSON to find the asset ID
2040ASSET_ID=$( echo " $RELEASES " | awk -v file=" $FILE " '
21- BEGIN { found_prerelease = 0; found_asset = 0; }
22- /"prerelease"/ && /true/ { found_prerelease = 1; next }
23- found_prerelease && /"assets"/ { in_assets = 1; next }
41+ BEGIN { found_asset = 0; }
42+ /"assets"/ { in_assets = 1; next }
2443 in_assets && /"id":/ {
2544 match($0, /[0-9]+/);
2645 current_id = substr($0, RSTART, RLENGTH);
@@ -38,10 +57,13 @@ if [ -z "$ASSET_ID" ]; then
3857fi
3958
4059# Download the goose binary
41- echo " Downloading goose ..."
60+ echo " Downloading $FILE ..."
4261echo " "
43- curl -sL --header ' Accept: application/octet-stream' https://$GITHUB_API_ENDPOINT /repos/$REPO /releases/assets/$ASSET_ID > $OUT_FILE
44- chmod +x $OUT_FILE
62+ curl -sL --header ' Accept: application/octet-stream' https://$GITHUB_API_ENDPOINT /repos/$REPO /releases/assets/$ASSET_ID > $FILE
63+ tar -xjf $FILE
64+ echo " Cleaning up $FILE ..."
65+ rm $FILE
66+ chmod +x goose goosed
4567
4668LOCAL_BIN=" $HOME /.local/bin"
4769if [ ! -d " $LOCAL_BIN " ]; then
5375
5476echo " Sending goose to $LOCAL_BIN /$OUT_FILE "
5577echo " "
56- chmod +x $OUT_FILE
57- mv $OUT_FILE $LOCAL_BIN / $OUT_FILE
78+ mv goose $LOCAL_BIN / $OUT_FILE
79+ mv goosed $LOCAL_BIN
5880
5981# Check if the directory is in the PATH
6082if [[ " :$PATH :" != * " :$LOCAL_BIN :" * ]]; then
0 commit comments