-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·66 lines (59 loc) · 1.68 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·66 lines (59 loc) · 1.68 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
#!/usr/bin/env sh
# install.sh — download the latest tpane release binary into ~/.local/bin.
set -eu
REPO="phcurado/tpane"
BIN_DIR="${BIN_DIR:-$HOME/.local/bin}"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$arch" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "unsupported arch: $arch" >&2; exit 1 ;;
esac
case "$os" in
linux|darwin) ;;
*) echo "unsupported os: $os" >&2; exit 1 ;;
esac
if [ "${VERSION:-}" ]; then
tag="$VERSION"
else
tag=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -n1)
fi
if [ -z "$tag" ]; then
echo "could not resolve latest tag" >&2
exit 1
fi
case "$tag" in
v*) ;;
*) tag="v$tag" ;;
esac
asset="tpane_${tag#v}_${os}_${arch}.tar.gz"
url="https://github.com/$REPO/releases/download/$tag/$asset"
echo "downloading $url"
curl -fsSL "$url" -o "$TMP/$asset"
curl -fsSL "https://github.com/$REPO/releases/download/$tag/checksums.txt" -o "$TMP/checksums.txt"
expected=$(grep " $asset\$" "$TMP/checksums.txt" | awk '{print $1}')
if [ -z "$expected" ]; then
echo "checksum not found for $asset" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$TMP/$asset" | awk '{print $1}')
else
actual=$(shasum -a 256 "$TMP/$asset" | awk '{print $1}')
fi
if [ "$actual" != "$expected" ]; then
echo "checksum mismatch for $asset" >&2
exit 1
fi
tar -xzf "$TMP/$asset" -C "$TMP"
mkdir -p "$BIN_DIR"
install -m 0755 "$TMP/tpane" "$BIN_DIR/tpane"
echo "installed: $BIN_DIR/tpane ($tag)"
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*) echo "note: $BIN_DIR is not in PATH" >&2 ;;
esac