-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·57 lines (43 loc) · 1.32 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·57 lines (43 loc) · 1.32 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
#!/usr/bin/env bash
set -e
BINARY_NAME="cs"
INSTALL_DIR="/usr/local/bin"
echo "==> Downloading $BINARY_NAME..."
ARCH=$(uname -m)
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux) PLATFORM="linux" ;;
darwin) PLATFORM="darwin" ;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64) TARGET="x86_64-${PLATFORM}" ;;
aarch64|arm64) TARGET="aarch64-${PLATFORM}" ;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
ASSET_NAME="cs-${TARGET}"
VERSION="${VERSION:-$(curl -s https://api.github.com/repos/dougmaitelli/cs/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')}"
if [ -z "$VERSION" ]; then
echo "Could not determine latest version."
exit 1
fi
DOWNLOAD_URL="https://github.com/dougmaitelli/cs/releases/download/${VERSION}/${ASSET_NAME}"
TMPFILE=$(mktemp)
echo "==> Fetching $DOWNLOAD_URL ..."
curl -fsSL "$DOWNLOAD_URL" -o "$TMPFILE"
echo "==> Installing $BINARY_NAME to $INSTALL_DIR..."
if [ "$(id -u)" -ne 0 ]; then
echo "==> Re-running with sudo to install to $INSTALL_DIR..."
sudo mv "$TMPFILE" "$INSTALL_DIR/$BINARY_NAME"
else
mv "$TMPFILE" "$INSTALL_DIR/$BINARY_NAME"
fi
chmod +x "$INSTALL_DIR/$BINARY_NAME"
echo "==> $BINARY_NAME installed successfully (version $VERSION)!"
echo "==> Run '$BINARY_NAME --help' to get started."