-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·113 lines (98 loc) · 3.87 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·113 lines (98 loc) · 3.87 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
#!/usr/bin/env sh
# tok installer — downloads the latest GitHub release binary for the host.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/antegral/tok/main/install.sh | sh
#
# Env overrides:
# INSTALL_DIR destination directory (default: $HOME/.local/bin)
# VERSION release tag to install (default: latest)
#
# Examples:
# curl -fsSL .../install.sh | INSTALL_DIR=/usr/local/bin sudo sh
# curl -fsSL .../install.sh | VERSION=v1.0.0 sh
set -eu
REPO="antegral/tok"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
VERSION="${VERSION:-latest}"
err() { echo "error: $*" >&2; exit 1; }
info() { echo ">> $*"; }
# --- detect host triplet ---------------------------------------------------
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux)
case "$arch" in
x86_64|amd64) triplet="linux-amd64" ;;
aarch64|arm64) triplet="linux-arm64" ;;
*) err "unsupported linux arch: $arch" ;;
esac ;;
darwin)
case "$arch" in
x86_64) triplet="darwin-amd64" ;;
arm64) triplet="darwin-arm64" ;;
*) err "unsupported darwin arch: $arch" ;;
esac ;;
*) err "unsupported OS: $os (only linux/darwin amd64/arm64 are released)" ;;
esac
info "host: $triplet"
# --- pick downloader -------------------------------------------------------
if command -v curl >/dev/null 2>&1; then
fetch() { curl -fsSL "$1" -o "$2"; }
fetch_stdout() { curl -fsSL "$1"; }
elif command -v wget >/dev/null 2>&1; then
fetch() { wget -qO "$2" "$1"; }
fetch_stdout() { wget -qO- "$1"; }
else
err "neither curl nor wget is available"
fi
# --- pick sha256 utility ---------------------------------------------------
if command -v sha256sum >/dev/null 2>&1; then
sha_check() { sha256sum -c "$1" --ignore-missing >/dev/null; }
elif command -v shasum >/dev/null 2>&1; then
sha_check() { shasum -a 256 -c "$1" --ignore-missing >/dev/null; }
else
err "no sha256 utility (install coreutils on linux; ships on macOS)"
fi
# --- resolve version -------------------------------------------------------
if [ "$VERSION" = "latest" ]; then
info "resolving latest release..."
VERSION=$(fetch_stdout "https://api.github.com/repos/${REPO}/releases/latest" \
| sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p' \
| head -n1)
[ -n "$VERSION" ] || err "could not determine latest version"
fi
info "version: $VERSION"
# --- download --------------------------------------------------------------
asset="tok-${VERSION}-${triplet}.tar.gz"
asset_url="https://github.com/${REPO}/releases/download/${VERSION}/${asset}"
checksum_url="https://github.com/${REPO}/releases/download/${VERSION}/checksums.txt"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
info "downloading $asset"
fetch "$asset_url" "$tmp/$asset" || err "download failed: $asset_url"
fetch "$checksum_url" "$tmp/checksums.txt" || err "checksum download failed: $checksum_url"
info "verifying SHA-256"
( cd "$tmp" && sha_check checksums.txt ) || err "SHA-256 mismatch"
# --- extract ---------------------------------------------------------------
info "extracting"
tar -xzf "$tmp/$asset" -C "$tmp"
[ -f "$tmp/tok" ] || err "binary 'tok' not found in archive"
# --- install ---------------------------------------------------------------
mkdir -p "$INSTALL_DIR"
mv "$tmp/tok" "$INSTALL_DIR/tok"
chmod +x "$INSTALL_DIR/tok"
info "installed: $INSTALL_DIR/tok"
# --- PATH check ------------------------------------------------------------
case ":${PATH:-}:" in
*":$INSTALL_DIR:"*) ;;
*)
echo ""
echo "warning: $INSTALL_DIR is not in PATH"
echo " add to your shell rc:"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
;;
esac
# --- done ------------------------------------------------------------------
echo ""
info "done. try: tok openai/gpt-4o <file>"