-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·159 lines (134 loc) · 4.48 KB
/
install.sh
File metadata and controls
executable file
·159 lines (134 loc) · 4.48 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# ensure script exits on errors
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:
# https://github.com/REPO_OWNER/REPO_NAME should be the repository you want to download the executable from
# EXECUTABLE_NAME_HERE should be the name of the executable that the user will install
# credits: https://github.com/ellipticobj
# to user: USE WITH CAUTION! THIS SCRIPT CAN BE MODIFIED TO BE DANGEROUS. ALWAYS CHECK THE SCRIPT BEFORE RUNNING IT.
# ------------------------------------
# init variables
# ------------------------------------
REPO_OWNER="ellipticobj"
REPO_NAME="cuter"
EXEC_NAME="cuter"
MIN_SIZE=100000
# ------------------------------------
# helpers
# ------------------------------------
build() {
INSTALL_PATH="/usr/bin/"
pip3 install -U PyInstaller
echo "purging ./dist/"
rm -rf dist/
curl -fsSL "https://raw.githubusercontent.com/ellipticobj/cuter/refs/heads/v2/client.py" > client.py
# single pyinstaller command with all necessary parameters
python3 -m PyInstaller \
--onefile \
--name "$EXEC_NAME-$(uname -m)" \
--clean \
--upx-dir=/usr/bin \
--exclude-module tkinter \
--exclude-module unittest \
--exclude-module pytest \
--optimize 2 \
client.py
echo -e "\nexecutable size: \n$(du -sh "dist/$EXEC_NAME-$(uname -m)")"
# determine install path based on architecture
if [[ "$(uname -m)" == "arm64" ]]; then
INSTALL_PATH='/usr/local/bin/'
else
INSTALL_PATH='/usr/bin/'
fi
echo -e "\nmove to ${INSTALL_PATH} (ENTER) or exit (anything else)?"
read -r CONTINUE < /dev/tty
if [ -n "${CONTINUE}" ]; then
echo "build at dist/$EXEC_NAME-$(uname -m)"
exit 0
fi
sudo mv "./dist/$EXEC_NAME-$(uname -m)" "$INSTALL_PATH$EXEC_NAME"
echo "installed to ${INSTALL_PATH}${EXEC_NAME} yippie"
echo "run ${EXEC_NAME} to get started"
}
# ensures that the script exits immediately if an error occurs
set -euo pipefail
# ------------------------------------
# environment checks
# ------------------------------------
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux|darwin) ;;
*) echo "error: unsupported os"; exit 1 ;;
esac
# set install path based on OS
if [[ "$OS" == "darwin" ]]; then
INSTALL_PATH="/usr/local/bin/"
else
INSTALL_PATH="/usr/bin/"
fi
# check for dependencies (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" ;;
arm64) ARCH="arm64" ;;
aarch64) ARCH="aarch64" ;;
*) echo "error: unsupported arch: $ARCH"; exit 1 ;;
esac
# ------------------------------------
# user confirmation
# ------------------------------------
# tells the user what this script does
echo "this script gets the executable from ./dist/ 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 -n "enter y to continue or any other key to exit "
read CONTINUE
if [ "$CONTINUE" != "y" ]; then
echo "exiting..."
exit 0
fi
# ------------------------------------
# installation
# ------------------------------------
# get latest release tag
API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest"
if command -v jq >/dev/null 2>&1; then
LATEST=$(curl -s "$API_URL" | jq -r '.tag_name')
else
LATEST=$(curl -s "$API_URL" | grep -oP '"tag_name": "\K[^"]+')
fi
[ -n "$LATEST" ] || { echo "failed to fetch release"; exit 1; }
# download executable
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${LATEST}/${EXEC_NAME}-${ARCH}"
echo "downloading: $DOWNLOAD_URL"
curl -L -o "$EXEC_NAME" "$DOWNLOAD_URL" || { echo "download failed"; exit 1; }
# validate file size
file_size=$(wc -c < "$EXEC_NAME")
if (( file_size < MIN_SIZE )); then
echo "error: no build available for your device"
rm -f "$EXEC_NAME"
echo "attempting to build locally"
build
exit 1
fi
# install
chmod +x "$EXEC_NAME"
sudo mv "$EXEC_NAME" "${INSTALL_PATH}${EXEC_NAME}"
echo "installed to ${INSTALL_PATH}${EXEC_NAME} yippie"
echo "run ${EXEC_NAME} to get started"