-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·69 lines (59 loc) · 2.21 KB
/
install.sh
File metadata and controls
executable file
·69 lines (59 loc) · 2.21 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
#!/usr/bin/env bash
set -euo pipefail
PROJECT="linuxaid-cli"
REPO="Obmondo/$PROJECT"
API_URL="https://api.github.com/repos/$REPO/releases/latest"
BIN_DIR="/usr/local/bin"
BIN_NAME="linuxaid-install"
function cleanup() {
rm -rf "$TMP_DIR"
exit 130
}
# -------------------------------------------------
# 1. Detect architecture
# -------------------------------------------------
ARCH=$(uname -m)
case "$ARCH" in
x86_64) TARGET="amd64" ;;
aarch64) TARGET="arm64" ;;
armv7l) TARGET="armv7" ;;
*)
echo "Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
# -------------------------------------------------
# 2. Find latest release tag on GitHub
# -------------------------------------------------
TAG=$(curl -sSf "$API_URL" | jq -r '.tag_name')
if [[ -z "$TAG" ]]; then
echo "Failed to obtain latest release tag" >&2
exit 1
fi
# -------------------------------------------------
# 3. Build download URL for the appropriate asset
# -------------------------------------------------
ASSET="${PROJECT}_${TAG}_linux_${TARGET}.tar.gz"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET"
SOURCE_CHECKSUM=$(curl -sSf "https://api.github.com/repos/$REPO/releases/latest" | jq -r --arg url "$DOWNLOAD_URL" '.assets[] | select(.browser_download_url == $url) | .digest | split(":")[1]')
# -------------------------------------------------
# 4. Download the package from Github
# -------------------------------------------------
# Trap SIGTERM (15), SIGINT (2 - Ctrl+C), and SIGHUP (1)
trap cleanup SIGTERM SIGINT SIGHUP EXIT
TMP_DIR=$(mktemp -d /tmp/${PROJECT}-XXX)
curl -sL -o "$TMP_DIR/$ASSET" "$DOWNLOAD_URL"
# -------------------------------------------------
# 5. Checksum verification
# -------------------------------------------------
ACTUAL_CHECKSUM=$(sha256sum "$TMP_DIR/$ASSET" | cut -d' ' -f1)
if [[ "$SOURCE_CHECKSUM" != "$ACTUAL_CHECKSUM" ]]; then
echo "Failed to verify the checksum" >&2
exit 1
fi
# -------------------------------------------------
# 6. Extract and execute the linuxaid-install binary
# -------------------------------------------------
tar -xzf "$TMP_DIR/$ASSET" -C "$TMP_DIR"
mv "$TMP_DIR/$BIN_NAME" "$BIN_DIR"
"$BIN_DIR/$BIN_NAME"