Skip to content

Commit 117e598

Browse files
feat: add talm script (#60)
* feat: add talm script Signed-off-by: 7h3-3mp7y-m4n <[email protected]> * minor fix for http_status Signed-off-by: 7h3-3mp7y-m4n <[email protected]> --------- Signed-off-by: 7h3-3mp7y-m4n <[email protected]>
1 parent 1fe1719 commit 117e598

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

scripts/install.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
trap 'error "An unexpected error occurred."; exit 1' ERR
4+
5+
info() { printf "\033[1;34m[INFO]\033[0m %s\n" "$*"; }
6+
success() { printf "\033[1;32m[SUCCESS]\033[0m %s\n" "$*"; }
7+
warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*" >&2; }
8+
error() { printf "\033[1;31m[ERROR]\033[0m %s\n" "$*" >&2; }
9+
10+
for cmd in curl uname mktemp jq; do
11+
if ! command -v "$cmd" >/dev/null 2>&1; then
12+
error "Required command '$cmd' not found. Please install it and retry."
13+
exit 1
14+
fi
15+
done
16+
17+
info "Fetching latest Talm release version..."
18+
19+
API_URL="https://api.github.com/repos/cozystack/talm/releases/latest"
20+
TMPDIR=$(mktemp -d)
21+
cleanup() { rm -rf "$TMPDIR"; }
22+
trap cleanup EXIT
23+
24+
HTTP_STATUS=$(curl -sSL -w '%{http_code}' -H 'Accept: application/vnd.github.v3+json' -o "$TMPDIR/response.json" "$API_URL")
25+
26+
if [ "$HTTP_STATUS" -ne 200 ]; then
27+
error "GitHub API returned HTTP status $HTTP_STATUS."
28+
exit 1
29+
fi
30+
31+
LATEST_VERSION=$(jq -r '.tag_name' < "$TMPDIR/response.json")
32+
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
33+
error "Could not parse 'tag_name' from GitHub release response."
34+
exit 1
35+
fi
36+
37+
info "Latest version: $LATEST_VERSION"
38+
39+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
40+
ARCH=$(uname -m)
41+
42+
case "$ARCH" in
43+
x86_64 | amd64) ARCH="amd64" ;;
44+
arm64 | aarch64) ARCH="arm64" ;;
45+
i386 | i686) ARCH="i386" ;;
46+
*)
47+
error "Unsupported architecture: $ARCH"
48+
exit 1
49+
;;
50+
esac
51+
52+
FILE="talm-$OS-$ARCH"
53+
DOWNLOAD_URL="https://github.com/cozystack/talm/releases/download/$LATEST_VERSION/$FILE"
54+
55+
info "Downloading $FILE from $DOWNLOAD_URL..."
56+
curl -fL "$DOWNLOAD_URL" -o "$TMPDIR/talm"
57+
chmod +x "$TMPDIR/talm"
58+
59+
if [ "$(id -u)" = 0 ]; then
60+
INSTALL_DIR="/usr/local/bin"
61+
elif [ -w "/usr/local/bin" ]; then
62+
INSTALL_DIR="/usr/local/bin"
63+
else
64+
INSTALL_DIR="$HOME/.local/bin"
65+
mkdir -p "$INSTALL_DIR"
66+
case ":$PATH:" in
67+
*":$INSTALL_DIR:"*) ;;
68+
*) warn "$INSTALL_DIR is not in your PATH." ;;
69+
esac
70+
fi
71+
72+
INSTALL_PATH="$INSTALL_DIR/talm"
73+
mv "$TMPDIR/talm" "$INSTALL_PATH"
74+
75+
success "Talm installed successfully at $INSTALL_PATH"
76+
info "You can now run: talm --help"

0 commit comments

Comments
 (0)