@@ -20,6 +20,29 @@ BIN_NAME="agentty"
2020err () { printf ' install.sh: %s\n' " $* " >&2 ; exit 1; }
2121info () { printf ' \033[1;34m::\033[0m %s\n' " $* " ; }
2222ok () { printf ' \033[1;32m✓\033[0m %s\n' " $* " ; }
23+ have () { command -v " $1 " > /dev/null 2>&1 ; }
24+
25+ # fetch URL to stdout, trying curl then wget
26+ fetch () {
27+ if have curl; then
28+ curl -fsSL " $1 "
29+ elif have wget; then
30+ wget -qO- " $1 "
31+ else
32+ err " need curl or wget installed"
33+ fi
34+ }
35+
36+ # download URL to a file ($2), trying curl then wget
37+ download () {
38+ if have curl; then
39+ curl -fsSL " $1 " -o " $2 "
40+ elif have wget; then
41+ wget -q " $1 " -O " $2 "
42+ else
43+ err " need curl or wget installed"
44+ fi
45+ }
2346
2447while [ $# -gt 0 ]; do
2548 case " $1 " in
@@ -49,26 +72,70 @@ case "$arch" in
4972 * ) err " unsupported arch: $arch " ;;
5073esac
5174
52- # --- pick asset ---------------------------------------------------------------
75+ # --- build candidate asset suffixes -------------------------------------------
76+ # Release assets are named like "agentty-<version>-<os>-<arch>" (and historically
77+ # a few unversioned "agentty-<os>-<arch>"). OS/arch tokens have varied across
78+ # releases (darwin vs macos, aarch64 vs arm64), so we try a list of plausible
79+ # suffixes in priority order and take the first match.
5380if [ " $os " = " windows" ]; then
54- asset= " agentty- windows-x86_64 .exe"
81+ suffixes= " windows- ${arch} .exe windows-amd64 .exe"
5582 BIN_NAME=" agentty.exe"
5683elif [ " $os " = " darwin" ]; then
57- err " macOS binaries are not yet pre-built. Build from source:
58- git clone --recursive https://github.com/ $REPO
59- cd agentty && cmake -B build && cmake --build build -j
60- Or use Homebrew once the tap lands: brew install 1ay1/tap/agentty "
84+ case " $arch " in
85+ aarch64) suffixes= " macos-arm64 darwin-arm64 macos-aarch64 darwin-aarch64 " ;;
86+ * ) suffixes= " macos- ${arch} darwin- ${arch} macos-amd64 darwin-amd64 " ;;
87+ esac
6188else
62- asset=" agentty-${os} -${arch} "
89+ case " $arch " in
90+ aarch64) suffixes=" linux-aarch64 linux-arm64" ;;
91+ * ) suffixes=" linux-${arch} linux-amd64" ;;
92+ esac
6393fi
6494
65- # --- resolve version ----------------------------------------------------------
95+ # --- resolve release + asset URL via GitHub API -------------------------------
96+ # The GitHub "latest/download/<name>" redirect only works for assets whose names
97+ # are stable across releases; ours embed the version, so we query the API to get
98+ # the real browser_download_url. Falls back to a constructed URL if the API is
99+ # unavailable (e.g. rate-limited).
66100if [ " $VERSION " = " latest" ]; then
67- base =" https://github.com/$REPO /releases/latest/download "
101+ api_url =" https://api. github.com/repos/ $REPO /releases/latest"
68102else
69- base =" https://github.com/$REPO /releases/download /$VERSION "
103+ api_url =" https://api. github.com/repos/ $REPO /releases/tags /$VERSION "
70104fi
71105
106+ info " resolving release ($VERSION ) for $os /$arch "
107+ api_json=$( fetch " $api_url " 2> /dev/null) || api_json=" "
108+
109+ asset_url=" "
110+ sums_url=" "
111+ if [ -n " $api_json " ]; then
112+ # Extract every browser_download_url, then pick the asset whose filename ends
113+ # in one of our candidate suffixes. The '-' before the suffix keeps
114+ # "linux-aarch64" from satisfying a "linux-x86_64" request, etc.
115+ urls=$( printf ' %s\n' " $api_json " \
116+ | grep -o ' "browser_download_url": *"[^"]*"' \
117+ | sed ' s/.*": *"//; s/"$//' )
118+ sums_url=$( printf ' %s\n' " $urls " | grep -E ' /SHA256SUMS\$' | head -n1)
119+ for sfx in $suffixes ; do
120+ asset_url=$( printf ' %s\n' " $urls " | grep -E " /agentty(-[0-9][^/]*)?-${sfx} \$ " | head -n1)
121+ [ -n " $asset_url " ] && break
122+ done
123+ fi
124+
125+ # Fallback: construct the legacy unversioned URL if the API gave us nothing.
126+ if [ -z " $asset_url " ]; then
127+ if [ " $VERSION " = " latest" ]; then
128+ base=" https://github.com/$REPO /releases/latest/download"
129+ else
130+ base=" https://github.com/$REPO /releases/download/$VERSION "
131+ fi
132+ set -- $suffixes
133+ asset_url=" $base /agentty-$1 "
134+ sums_url=" $base /SHA256SUMS"
135+ info " GitHub API unavailable — falling back to $asset_url "
136+ fi
137+
138+ asset=$( basename " $asset_url " )
72139# --- pick prefix --------------------------------------------------------------
73140if [ -z " $PREFIX " ]; then
74141 if [ " $( id -u) " -eq 0 ]; then
@@ -84,22 +151,37 @@ mkdir -p "$bindir"
84151tmp=$( mktemp -d)
85152trap ' rm -rf "$tmp"' EXIT
86153
87- info " downloading $asset from $base "
88- curl -fsSL " $base /$asset " -o " $tmp /$asset "
89- curl -fsSL " $base /SHA256SUMS" -o " $tmp /SHA256SUMS" 2> /dev/null || {
154+ info " downloading $asset "
155+ download " $asset_url " " $tmp /$asset " || err " download failed: $asset_url "
156+ [ -s " $tmp /$asset " ] || err " downloaded file is empty: $asset_url "
157+
158+ if [ -n " $sums_url " ] && download " $sums_url " " $tmp /SHA256SUMS" 2> /dev/null; then
159+ :
160+ else
90161 info " no SHA256SUMS published for $VERSION — skipping checksum verification"
91162 SKIP_SUMS=1
92- }
163+ fi
93164
94165if [ -z " ${SKIP_SUMS:- } " ]; then
95166 info " verifying SHA256"
96167 expected=$( grep " $asset \$ " " $tmp /SHA256SUMS" | awk ' {print $1}' )
97- [ -n " $expected " ] || err " no checksum line for $asset in SHA256SUMS"
98- actual=$( sha256sum " $tmp /$asset " | awk ' {print $1}' )
99- [ " $expected " = " $actual " ] || err " checksum mismatch
168+ if [ -z " $expected " ]; then
169+ info " no checksum line for $asset in SHA256SUMS — skipping verification"
170+ elif have sha256sum; then
171+ actual=$( sha256sum " $tmp /$asset " | awk ' {print $1}' )
172+ [ " $expected " = " $actual " ] || err " checksum mismatch
173+ expected $expected
174+ actual $actual "
175+ ok " checksum verified"
176+ elif have shasum; then
177+ actual=$( shasum -a 256 " $tmp /$asset " | awk ' {print $1}' )
178+ [ " $expected " = " $actual " ] || err " checksum mismatch
100179 expected $expected
101180 actual $actual "
102- ok " checksum verified"
181+ ok " checksum verified"
182+ else
183+ info " no sha256sum/shasum tool — skipping checksum verification"
184+ fi
103185fi
104186
105187# --- detect prior install (so updates announce themselves) -------------------
0 commit comments