-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·74 lines (60 loc) · 1.74 KB
/
install.sh
File metadata and controls
executable file
·74 lines (60 loc) · 1.74 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
73
74
#!/bin/bash
set -e
REPO="citizenpkg/cli"
BINARY_NAME="cli"
INSTALL_DIR="/usr/local/bin"
OS=$(uname -s)
ARCH=$(uname -m)
case "$OS" in
Linux)
TARGET_OS="unknown-linux-gnu"
;;
Darwin)
TARGET_OS="apple-darwin"
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64)
TARGET_ARCH="x86_64"
;;
arm64 | aarch64)
TARGET_ARCH="aarch64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
ASSET_NAME="${BINARY_NAME}-${TARGET_ARCH}-${TARGET_OS}.tar.gz"
LATEST_RELEASE_URL="https://api.github.com/repos/${REPO}/releases/latest"
echo "Fetching latest release information..."
DOWNLOAD_URL=$(curl -sSL "$LATEST_RELEASE_URL" | grep "browser_download_url.*${ASSET_NAME}" | cut -d '"' -f 4)
if [ -z "$DOWNLOAD_URL" ]; then
echo "Could not find a download URL for the latest release for your system ($OS/$ARCH)."
echo "Please check the releases page: https://github.com/${REPO}/releases"
exit 1
fi
TMP_DIR=$(mktemp -d)
echo "Downloading $DOWNLOAD_URL to $TMP_DIR..."
curl -sSL "$DOWNLOAD_URL" -o "$TMP_DIR/$ASSET_NAME"
echo "Unpacking archive..."
tar -xzf "$TMP_DIR/$ASSET_NAME" -C "$TMP_DIR"
BINARY_PATH="$TMP_DIR/$BINARY_NAME"
if [ ! -f "$BINARY_PATH" ]; then
echo >&2 "Binary not found after unpacking. Aborting."
exit 1
fi
echo "Installing binary to $INSTALL_DIR..."
if [ -w "$INSTALL_DIR" ]; then
mv "$BINARY_PATH" "$INSTALL_DIR/"
else
echo "Write permission to $INSTALL_DIR is required. You may be prompted for your password."
sudo mv "$BINARY_PATH" "$INSTALL_DIR/"
fi
echo "Cleaning up..."
rm -rf "$TMP_DIR"
echo "Installation successful! You can now use the '$BINARY_NAME' command."