-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·95 lines (81 loc) · 2.53 KB
/
install.sh
File metadata and controls
executable file
·95 lines (81 loc) · 2.53 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# ensures that the script exits immediately if an error occurs
set -euo pipefail
# installer script
# this downloads a github release executable for the current arch and installs it to the /usr/bin/ directory
#
# repo details:
REPO_OWNER="ellipticobj"
REPO_NAME="scrap"
EXEC_NAME="scrap"
INSTALL_PATH="/usr/bin/"
# tells the user what this script does
echo "this script downloads the latest release of ${REPO_OWNER}/${REPO_NAME} and installs it to ${INSTALL_PATH}"
echo "note: you may be prompted to input your password. this is to move the executable to ${INSTALL_PATH}"
echo "do you want to install?"
echo "enter y to continue or any other key to exit"
read -r -n 1 -s CONTINUE
if [ "$CONTINUE" != "y" ]; then
echo "exiting..."
exit 0
fi
# ensures that the current system is linux or macos
if [[ "$(uname)" != "Linux" && "$(uname)" != "Darwin" ]]; then
echo "error: this script only supports linux and macos."
exit 1
fi
# check for dependancies (curl grep and sed)
for cmd in curl grep sed; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "error: $cmd is not installed."
exit 1
fi
done
# use jq if available
if command -v jq >/dev/null 2>&1; then
USE_JQ=true
else
USE_JQ=false
fi
# arch detection
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
ARCH="x86_64"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
# gets latest release
API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest"
if [ "$USE_JQ" = true ]; then
LATEST=$(curl -s "$API_URL" | jq -r '.tag_name')
else
LATEST=$(curl -s "$API_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$LATEST" ]; then
echo "failed to fetch the latest release"
echo "visit https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/latest to manually download the executable."
exit 1
fi
# gets download url
# this assumes your release asset is named like this: EXEC_NAME-ARCH (e.g. scrap-x86_64)
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST}/${EXEC_NAME}-${ARCH}"
echo "downloading executable from $DOWNLOAD_URL"
# downloading
curl -L -o "${EXEC_NAME}" "$DOWNLOAD_URL"
if [ $? -ne 0 ]; then
echo "download failed"
exit 1
fi
# makes the file executable.
chmod +x "$EXEC_NAME"
# moves the executable to /usr/bin.
echo "moving executable to ${INSTALL_PATH}${EXEC_NAME}"
sudo mv "${EXEC_NAME}" "${INSTALL_PATH}${EXEC_NAME}"
echo "installed to ${INSTALL_PATH}${EXEC_NAME}"