-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·72 lines (60 loc) · 2.43 KB
/
install.sh
File metadata and controls
executable file
·72 lines (60 loc) · 2.43 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
#!/bin/sh
set -e
REPO="deadcode-walker/forge"
BINARY_NAME="forge-cli"
INSTALL_DIR="/usr/local/bin"
# ── Detect platform ─────────────────────────────────────────────
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux) ;;
*) echo "error: unsupported OS: $OS (linux only)"; exit 1 ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
*) echo "error: unsupported architecture: $ARCH"; exit 1 ;;
esac
# ── Resolve version ─────────────────────────────────────────────
if [ -n "$1" ]; then
VERSION="$1"
else
VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' | cut -d'"' -f4)
fi
if [ -z "$VERSION" ]; then
echo "error: could not determine latest version"
exit 1
fi
# ── Check if already up to date ─────────────────────────────────
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
CURRENT=$("$BINARY_NAME" --version 2>/dev/null | awk '{print $2}')
CLEAN_VERSION=$(echo "$VERSION" | sed 's/^v//')
if [ "$CURRENT" = "$CLEAN_VERSION" ]; then
echo "forge-cli $CURRENT is already installed and up to date."
exit 0
fi
echo "Updating forge-cli $CURRENT -> $VERSION ..."
else
echo "Installing forge-cli $VERSION ..."
fi
# ── Download and extract ────────────────────────────────────────
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
ASSET="forge-linux-${ARCH}.tar.gz"
URL="https://github.com/$REPO/releases/download/$VERSION/$ASSET"
echo "Downloading $URL"
curl -fsSL "$URL" -o "$TMP/$ASSET"
tar xzf "$TMP/$ASSET" -C "$TMP"
# ── Install ─────────────────────────────────────────────────────
if [ -w "$INSTALL_DIR" ]; then
mv "$TMP/forge" "$INSTALL_DIR/$BINARY_NAME"
else
sudo mv "$TMP/forge" "$INSTALL_DIR/$BINARY_NAME"
fi
chmod +x "$INSTALL_DIR/$BINARY_NAME"
echo ""
echo " forge-cli $VERSION installed to $INSTALL_DIR/$BINARY_NAME"
echo ""
echo " Usage: forge-cli --help"
echo " Update: curl -fsSL https://raw.githubusercontent.com/$REPO/main/install.sh | sh"
echo ""