This repository was archived by the owner on Aug 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathinstall.sh
More file actions
151 lines (125 loc) · 4.27 KB
/
install.sh
File metadata and controls
151 lines (125 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env sh
# Minimal installer for "av" — downloads the correct binary from GitHub Releases
# Inspired by uv's installer style: https://astral.sh/uv/install.sh
set -eu
# ----------------------- Configurable knobs -----------------------
# Override via env when needed
AV_REPO_SLUG="${AV_INSTALL_REPO:-${AV_REPO_SLUG:-auv-sh/av}}" # owner/repo
AV_VERSION="${AV_VERSION:-latest}" # e.g. v0.1.0 or latest
AV_BIN_NAME="av"
AV_TOKEN="${AV_GITHUB_TOKEN:-${GITHUB_TOKEN:-}}" # optional for private rate limits
# Choose install dir: AV_INSTALL_DIR > ~/.local/bin > /usr/local/bin (if writable)
DEFAULT_LOCAL_BIN="$HOME/.local/bin"
AV_INSTALL_DIR="${AV_INSTALL_DIR:-}"
# ----------------------- Utils -----------------------
say() { printf "%s\n" "$*"; }
err() { printf "ERROR: %s\n" "$*" >&2; exit 1; }
need_cmd() {
command -v "$1" >/dev/null 2>&1 || err "need '$1' (command not found)"
}
downloader() {
url="$1"; out="$2"
if command -v curl >/dev/null 2>&1; then
if [ -n "$AV_TOKEN" ]; then
curl -fsSL -H "Authorization: Bearer $AV_TOKEN" "$url" -o "$out"
else
curl -fsSL "$url" -o "$out"
fi
elif command -v wget >/dev/null 2>&1; then
if [ -n "$AV_TOKEN" ]; then
wget --header "Authorization: Bearer $AV_TOKEN" -q "$url" -O "$out"
else
wget -q "$url" -O "$out"
fi
else
err "need 'curl' or 'wget' to download"
fi
}
detect_os() {
case "$(uname -s)" in
Linux) echo linux ;;
Darwin) echo macos ;;
*) err "unsupported OS: $(uname -s)" ;;
esac
}
detect_arch() {
# normalize common arch names
arch=$(uname -m)
case "$arch" in
x86_64|amd64) echo x86_64 ;;
arm64|aarch64) echo aarch64 ;;
*) err "unsupported CPU arch: $arch" ;;
esac
}
target_triple() {
os="$1"; arch="$2"
case "$os" in
linux)
if [ "$arch" = "x86_64" ]; then
echo "x86_64-unknown-linux-gnu"
else
err "no binary for $arch on Linux"
fi ;;
macos)
if [ "$arch" = "aarch64" ]; then echo "aarch64-apple-darwin"; else err "no binary for $arch on macOS"; fi ;;
*) err "unsupported combo" ;;
esac
}
pick_install_dir() {
if [ -n "$AV_INSTALL_DIR" ]; then echo "$AV_INSTALL_DIR"; return; fi
if [ -d "$DEFAULT_LOCAL_BIN" ] || mkdir -p "$DEFAULT_LOCAL_BIN" 2>/dev/null; then
echo "$DEFAULT_LOCAL_BIN"; return
fi
if [ -w "/usr/local/bin" ]; then echo "/usr/local/bin"; return; fi
# fallback to local bin even if not in PATH
echo "$DEFAULT_LOCAL_BIN"
}
latest_tag() {
# use GitHub latest redirect
# e.g. https://github.com/<slug>/releases/latest -> 302 to .../tag/vX.Y.Z
need_cmd curl
url="https://github.com/$AV_REPO_SLUG/releases/latest"
tag=$(curl -fsSLI "$url" | awk -F '/tag/' '/^location:/I{print $2}' | tr -d '\r\n') || tag=""
if [ -z "$tag" ]; then err "failed to resolve latest tag"; fi
# ensure tag starts with 'v'
case "$tag" in v*) echo "$tag" ;; *) echo "v$tag" ;; esac
}
main() {
os=$(detect_os)
arch=$(detect_arch)
triple=$(target_triple "$os" "$arch")
ver="$AV_VERSION"
if [ "$ver" = "latest" ]; then ver=$(latest_tag); fi
asset="${AV_BIN_NAME}-${ver}-${triple}.tar.gz"
if [ "$AV_VERSION" = "latest" ]; then
base="https://github.com/${AV_REPO_SLUG}/releases/latest/download"
else
base="https://github.com/${AV_REPO_SLUG}/releases/download/${ver}"
fi
url="$base/$asset"
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t av-install)
trap 'rm -rf "$tmpdir"' EXIT INT TERM
say "Downloading $asset ..."
downloader "$url" "$tmpdir/$asset" || err "failed to download asset: $url"
say "Unpacking ..."
tar -C "$tmpdir" -xzf "$tmpdir/$asset" || err "failed to unpack"
bin_src="$tmpdir/$AV_BIN_NAME"
[ -x "$bin_src" ] || err "binary not found in archive: $AV_BIN_NAME"
inst_dir=$(pick_install_dir)
mkdir -p "$inst_dir"
bin_dst="$inst_dir/$AV_BIN_NAME"
# Try to move; fall back to copy if cross-device
if mv "$bin_src" "$bin_dst" 2>/dev/null; then : ; else cp "$bin_src" "$bin_dst"; fi
chmod +x "$bin_dst"
say "Installed to: $bin_dst"
# PATH hint
case ":$PATH:" in
*:"$inst_dir":*) :;;
*) say "NOTE: $inst_dir is not in PATH. Add it, e.g.:"; say " export PATH=\"$inst_dir:\$PATH\"";;
esac
# Smoke test
if "$bin_dst" --version >/dev/null 2>&1; then
say "Run: av --help"
fi
}
main "$@"