Skip to content

Commit 4e0d803

Browse files
authored
feat: update the cli to be cross platform (#624)
1 parent 52e5523 commit 4e0d803

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

download_cli.sh

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,44 @@
22
set -euo pipefail
33

44
REPO="block/goose"
5-
FILE="goose"
65
OUT_FILE="goose"
76
GITHUB_API_ENDPOINT="api.github.com"
87

98
function 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
1435
echo "Looking up the most recent goose binary release..."
1536
echo ""
1637
RELEASES=$(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
2040
ASSET_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
3857
fi
3958

4059
# Download the goose binary
41-
echo "Downloading goose..."
60+
echo "Downloading $FILE..."
4261
echo ""
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

4668
LOCAL_BIN="$HOME/.local/bin"
4769
if [ ! -d "$LOCAL_BIN" ]; then
@@ -53,8 +75,8 @@ fi
5375

5476
echo "Sending goose to $LOCAL_BIN/$OUT_FILE"
5577
echo ""
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
6082
if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then

0 commit comments

Comments
 (0)