Skip to content

Commit 7c44eb8

Browse files
committed
Merge pull request 'chore: add install script to setup linuxaid-install' (#179) from chore/add-install-script-to-setup-linuxaid-install into main
Reviewed-on: https://gitea.obmondo.com/EnableIT/Linuxaid-cli/pulls/179
2 parents 62bd23b + 1a934b2 commit 7c44eb8

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

install.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function cleanup() {
5+
rm -rf "$TMP_DIR"
6+
exit 130
7+
}
8+
9+
# -------------------------------------------------
10+
# 1. Detect architecture
11+
# -------------------------------------------------
12+
ARCH=$(uname -m)
13+
case "$ARCH" in
14+
x86_64) TARGET="amd64" ;;
15+
aarch64) TARGET="arm64" ;;
16+
armv7l) TARGET="armv7" ;;
17+
*)
18+
echo "Unsupported architecture: $ARCH" >&2
19+
exit 1
20+
;;
21+
esac
22+
23+
# -------------------------------------------------
24+
# 2. Find latest release tag on GitHub
25+
# -------------------------------------------------
26+
PROJECT=linuxaid-cli""
27+
REPO="Obmondo/$PROJECT"
28+
API_URL="https://api.github.com/repos/$REPO/releases/latest"
29+
30+
# Grab the tag name (e.g., v1.2.3)
31+
TAG=$(curl -sSf "$API_URL" | jq -r '.tag_name')
32+
if [[ -z "$TAG" ]]; then
33+
echo "Failed to obtain latest release tag" >&2
34+
exit 1
35+
fi
36+
37+
# -------------------------------------------------
38+
# 3. Build download URL for the appropriate asset
39+
# -------------------------------------------------
40+
# Expected asset name pattern: $PROJECT_${TAG}_linux_${TARGET}.tar.gz
41+
ASSET="${PROJECT}_${TAG}_linux_${TARGET}.tar.gz"
42+
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET"
43+
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]')
44+
45+
# -------------------------------------------------
46+
# 4. Download the package from Github
47+
# -------------------------------------------------
48+
BIN_DIR="/usr/local/bin"
49+
BIN_NAME="linuxaid-install"
50+
51+
# Trap SIGTERM (15), SIGINT (2 - Ctrl+C), and SIGHUP (1)
52+
trap cleanup SIGTERM SIGINT SIGHUP EXIT
53+
54+
TMP_DIR=$(mktemp -d /tmp/${PROJECT}-XXX)
55+
curl -sL -o "$TMP_DIR/$ASSET" "$DOWNLOAD_URL"
56+
57+
# -------------------------------------------------
58+
# 5. Checksum verification
59+
# -------------------------------------------------
60+
ACTUAL_CHECKSUM=$(sha256sum "$TMP_DIR/$ASSET" | cut -d' ' -f1)
61+
if [[ "$SOURCE_CHECKSUM" != "$ACTUAL_CHECKSUM" ]]; then
62+
echo "Failed to verify the checksum" >&2
63+
exit 1
64+
fi
65+
66+
# -------------------------------------------------
67+
# 6. Extract and execute the linuxaid-install binary
68+
# -------------------------------------------------
69+
tar -xzf "$TMP_DIR/$ASSET" -C "$TMP_DIR"
70+
mv "$TMP_DIR/$BIN_NAME" "$BIN_DIR"
71+
72+
"$BIN_DIR/$BIN_NAME"

0 commit comments

Comments
 (0)