-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·99 lines (81 loc) · 2.58 KB
/
install.sh
File metadata and controls
executable file
·99 lines (81 loc) · 2.58 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
#!/bin/sh
set -eu
REPO="MrMichou/tone"
INSTALL_DIR="${TONE_INSTALL_DIR:-$HOME/.local/bin}"
main() {
detect_platform
get_version "$@"
download_and_install
}
detect_platform() {
OS=$(uname -s)
case "$OS" in
Linux) OS_TARGET="unknown-linux-gnu" ;;
Darwin) OS_TARGET="apple-darwin" ;;
*) error "Unsupported OS: $OS" ;;
esac
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH_TARGET="x86_64" ;;
aarch64|arm64) ARCH_TARGET="aarch64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
TARGET="${ARCH_TARGET}-${OS_TARGET}"
echo "Detected platform: ${TARGET}"
}
get_version() {
if [ $# -ge 1 ]; then
VERSION="$1"
else
echo "Fetching latest version..."
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$VERSION" ]; then
error "Failed to determine latest version. Try specifying a version: ./install.sh v0.1.0"
fi
echo "Version: ${VERSION}"
}
download_and_install() {
URL="https://github.com/${REPO}/releases/download/${VERSION}/tone-${TARGET}.tar.gz"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${VERSION}/checksums.txt"
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
echo "Downloading tone ${VERSION} for ${TARGET}..."
curl -fsSL "$URL" -o "$TMPDIR/tone.tar.gz"
curl -fsSL "$CHECKSUM_URL" -o "$TMPDIR/checksums.txt"
verify_checksum
extract_and_install
}
verify_checksum() {
EXPECTED=$(grep "tone-${TARGET}.tar.gz" "$TMPDIR/checksums.txt" | cut -d' ' -f1)
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "$TMPDIR/tone.tar.gz" | cut -d' ' -f1)
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "$TMPDIR/tone.tar.gz" | cut -d' ' -f1)
else
echo "Warning: cannot verify checksum (no sha256sum or shasum found)"
return
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
error "Checksum mismatch! Expected: ${EXPECTED}, Got: ${ACTUAL}"
fi
echo "Checksum verified."
}
extract_and_install() {
tar -xzf "$TMPDIR/tone.tar.gz" -C "$TMPDIR"
mkdir -p "$INSTALL_DIR"
mv "$TMPDIR/tone" "$INSTALL_DIR/tone"
chmod +x "$INSTALL_DIR/tone"
echo "tone ${VERSION} installed to ${INSTALL_DIR}/tone"
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*) echo "Note: Add ${INSTALL_DIR} to your PATH to use tone" ;;
esac
}
error() {
echo "Error: $1" >&2
exit 1
}
main "$@"