Skip to content

Commit a448e52

Browse files
committed
feat: add talm script
Signed-off-by: 7h3-3mp7y-m4n <[email protected]>
1 parent a8ba6b1 commit a448e52

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

‎scripts/install.sh‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
3+
set -e
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 grep sed mktemp; 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+
LATEST_VERSION=$(curl -fsSL "https://api.github.com/repos/cozystack/talm/releases/latest" | \
20+
grep '"tag_name":' | head -1 | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
21+
22+
if [ -z "$LATEST_VERSION" ]; then
23+
error "Failed to fetch the latest Talm version."
24+
exit 1
25+
fi
26+
27+
info "Latest version: $LATEST_VERSION"
28+
29+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
30+
ARCH=$(uname -m)
31+
32+
case "$ARCH" in
33+
x86_64 | amd64) ARCH="amd64" ;;
34+
arm64 | aarch64) ARCH="arm64" ;;
35+
i386 | i686) ARCH="i386" ;;
36+
*)
37+
error "Unsupported architecture: $ARCH"
38+
exit 1
39+
;;
40+
esac
41+
42+
FILE="talm-$OS-$ARCH"
43+
DOWNLOAD_URL="https://github.com/cozystack/talm/releases/download/$LATEST_VERSION/$FILE"
44+
45+
info "Downloading $FILE from $DOWNLOAD_URL..."
46+
47+
TMPDIR=$(mktemp -d)
48+
cleanup() { rm -rf "$TMPDIR"; }
49+
trap cleanup EXIT
50+
51+
curl -fL "$DOWNLOAD_URL" -o "$TMPDIR/talm"
52+
chmod +x "$TMPDIR/talm"
53+
54+
if [ "$(id -u)" = 0 ]; then
55+
INSTALL_DIR="/usr/local/bin"
56+
elif [ -w "/usr/local/bin" ]; then
57+
INSTALL_DIR="/usr/local/bin"
58+
else
59+
INSTALL_DIR="$HOME/.local/bin"
60+
if [ ! -d "$INSTALL_DIR" ]; then
61+
info "Creating directory $INSTALL_DIR"
62+
mkdir -p "$INSTALL_DIR"
63+
fi
64+
case ":$PATH:" in
65+
*":$INSTALL_DIR:"*) ;;
66+
*)
67+
warn "Warning: $INSTALL_DIR is not in your PATH."
68+
;;
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)