-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
355 lines (314 loc) · 11.5 KB
/
install.sh
File metadata and controls
355 lines (314 loc) · 11.5 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/env bash
set -euo pipefail
INSTALL_DIR="/opt/uxtu4linux"
VENV_DIR="$INSTALL_DIR/venv"
VENV_PYTHON="$VENV_DIR/bin/python3"
SRC_DIR="$INSTALL_DIR/src"
BIN_WRAPPER="/usr/local/bin/uxtu4linux"
SERVICE_NAME="uxtu4linux.service"
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME"
RELEASE_URL="https://github.com/HorizonUnix/UXTU4Linux/releases/latest/download/UXTU4Linux.zip"
TMP_DIR="$(mktemp -d)"
_R='\033[0m'; _B='\033[1m'; _D='\033[2m'; _G='\033[32m'; _Y='\033[33m'; _E='\033[31m'
info() { echo -e " ${_D}· $*${_R}"; }
ok() { echo -e " ${_G}✓${_R} $*"; }
warn() { echo -e " ${_Y}!${_R} $*"; }
die() { echo -e "\n ${_E}✗${_R} $*\n"; exit 1; }
hr() { echo -e " ${_D}$(printf '─%.0s' {1..58})${_R}"; }
trap '[[ -n "$TMP_DIR" && ( "$TMP_DIR" == /tmp/* || "$TMP_DIR" == /var/tmp/* ) ]] && rm -rf -- "$TMP_DIR"' EXIT
[[ $EUID -eq 0 ]] && die "Do not run as root — run as your normal user: bash install.sh"
CURRENT_USER="$(whoami)"
CURRENT_GROUP="$(id -gn)"
resolve_release_tag() {
local tag=""
if command -v curl &>/dev/null; then
tag="$(curl -fsSL -o /dev/null -w '%{url_effective}' \
"https://github.com/HorizonUnix/UXTU4Linux/releases/latest" 2>/dev/null \
| sed 's|.*/tag/||')" || true
elif command -v wget &>/dev/null; then
tag="$(wget -q --server-response --spider \
"https://github.com/HorizonUnix/UXTU4Linux/releases/latest" 2>&1 \
| awk '/Location:/{print $2}' | tail -1 | sed 's|.*/tag/||')" || true
fi
echo "${tag:-latest}"
}
detect_pm() {
if command -v apt-get &>/dev/null; then echo "apt"
elif command -v dnf &>/dev/null; then echo "dnf"
elif command -v yum &>/dev/null; then echo "yum"
elif command -v pacman &>/dev/null; then echo "pacman"
elif command -v zypper &>/dev/null; then echo "zypper"
else die "Unsupported distro — see manual installation: https://github.com/HorizonUnix/UXTU4Linux/wiki/Linux-Installation"
fi
}
check_systemd() {
if ! command -v systemctl &>/dev/null; then
echo ""
warn "systemd is not available on this system."
info "This installer requires systemd to manage the background daemon."
info "For non-systemd systems, see the manual installation guide:"
info "https://github.com/HorizonUnix/UXTU4Linux/wiki/Linux-Installation"
echo ""
die "Unsupported init system."
fi
ok "systemd detected."
}
ensure_python310() {
local py=""
for candidate in python3.14 python3.13 python3.12 python3.11 python3.10 python3; do
if command -v "$candidate" &>/dev/null; then
if "$candidate" -c "import sys; sys.exit(0 if sys.version_info >= (3,10) else 1)" 2>/dev/null; then
py="$candidate"
break
fi
fi
done
if [[ -n "$py" ]]; then
ok "Python: $($py --version)"
return
fi
warn "Python 3.10+ not found — installing..."
case "$1" in
apt)
if grep -qi "ubuntu" /etc/os-release 2>/dev/null; then
sudo apt-get install -y -qq software-properties-common &>/dev/null
sudo add-apt-repository -y ppa:deadsnakes/ppa &>/dev/null
sudo apt-get update -qq &>/dev/null
fi
local best=""
for v in 3.14 3.13 3.12 3.11 3.10; do
if sudo apt-get install -y -qq --dry-run "python${v}" "python${v}-venv" &>/dev/null; then
best="$v"; break
fi
done
[[ -n "$best" ]] || die "No Python 3.10+ package found in apt repos."
sudo apt-get install -y -qq "python${best}" "python${best}-venv" &>/dev/null \
|| die "Failed to install python${best}."
;;
dnf)
sudo dnf install -y -q python3 python3-pip &>/dev/null \
|| die "Failed to install Python via dnf."
;;
yum)
sudo yum install -y -q python3 python3-pip &>/dev/null \
|| die "Failed to install Python via yum."
;;
pacman)
sudo pacman -Sy --noconfirm --quiet python &>/dev/null \
|| die "Failed to install Python via pacman."
;;
zypper)
sudo zypper install -y --quiet python3 python3-pip &>/dev/null \
|| die "Failed to install Python via zypper."
;;
esac
for candidate in python3.14 python3.13 python3.12 python3.11 python3.10 python3; do
if command -v "$candidate" &>/dev/null; then
if "$candidate" -c "import sys; sys.exit(0 if sys.version_info >= (3,10) else 1)" 2>/dev/null; then
ok "Python: $($candidate --version)"
return
fi
fi
done
die "Could not install Python 3.10+. Install it manually and re-run."
}
install_deps() {
info "Installing system dependencies..."
case "$1" in
apt)
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update -qq &>/dev/null
sudo apt-get install -y -qq --no-install-recommends \
python3 python3-venv python3-pip \
dmidecode wget unzip curl &>/dev/null
;;
dnf)
sudo dnf install -y -q \
python3 python3-pip \
dmidecode wget unzip curl &>/dev/null
;;
yum)
sudo yum install -y -q \
python3 python3-pip \
dmidecode wget unzip curl &>/dev/null
;;
pacman)
sudo pacman -Sy --noconfirm --quiet \
python python-pip \
dmidecode wget unzip curl &>/dev/null
;;
zypper)
sudo zypper install -y --quiet \
python3 python3-pip \
dmidecode wget unzip curl &>/dev/null
;;
esac
ok "Dependencies installed."
}
download_release() {
info "Downloading release..."
local err="$TMP_DIR/dl.err"
if command -v wget &>/dev/null; then
local -a wget_progress_flag=()
if ! wget --version 2>&1 | grep -q "GNU Wget2"; then
wget_progress_flag+=(--show-progress)
fi
wget -q "${wget_progress_flag[@]}" -O "$TMP_DIR/release.zip" "$RELEASE_URL" 2>"$err" \
|| { cat "$err" >&2; die "Download failed."; }
elif command -v curl &>/dev/null; then
curl -fsSL -o "$TMP_DIR/release.zip" "$RELEASE_URL" 2>"$err" \
|| { cat "$err" >&2; die "Download failed."; }
else
die "Neither wget nor curl found."
fi
ok "Download complete."
}
install_files() {
info "Extracting files..."
unzip -q "$TMP_DIR/release.zip" -d "$TMP_DIR/extracted" || die "Failed to extract archive."
local src
src="$(find "$TMP_DIR/extracted" -maxdepth 1 -mindepth 1 -type d | head -1)"
[[ -d "$src" ]] || die "Could not find source directory in archive."
sudo mkdir -p "$INSTALL_DIR"
sudo chown "$CURRENT_USER:$CURRENT_GROUP" "$INSTALL_DIR"
sudo rm -rf "$SRC_DIR"
cp -r "$src" "$SRC_DIR"
ok "Installed to $SRC_DIR"
}
patch_entry_point() {
info "Configuring entry point..."
[[ -f "$SRC_DIR/UXTU4Linux.py" ]] || die "UXTU4Linux.py not found in $SRC_DIR"
sed -i "1s|.*|#!${VENV_PYTHON}|" "$SRC_DIR/UXTU4Linux.py" || die "Failed to patch shebang."
python3 - "$SRC_DIR/UXTU4Linux.py" "${VENV_PYTHON}" <<'PYEOF' || die "Guard injection failed."
import sys
path, venv = sys.argv[1], sys.argv[2]
guard = (
"import sys as _sys, os as _os\n"
f"_venv = '{venv}'\n"
"if _os.path.isfile(_venv) and _os.path.realpath(_sys.executable) != _os.path.realpath(_venv):\n"
" _os.execv(_venv, [_venv] + _sys.argv)\n"
)
with open(path, "r") as f:
lines = f.readlines()
lines.insert(1, guard)
with open(path, "w") as f:
f.writelines(lines)
PYEOF
ok "Entry point configured."
}
find_python_executable() {
command -v python3.14 || command -v python3.13 || command -v python3.12 || \
command -v python3.11 || command -v python3.10 || command -v python3 || true
}
setup_venv() {
info "Setting up Python environment..."
local py
py="$(find_python_executable)"
[[ -n "$py" ]] || die "python3 not found."
if [[ -d "$VENV_DIR" ]] && ! "$VENV_PYTHON" -c "" &>/dev/null; then
warn "Broken venv — recreating..."
rm -rf "$VENV_DIR"
fi
if [[ ! -d "$VENV_DIR" ]]; then
"$py" -m venv --without-pip "$VENV_DIR" &>/dev/null \
|| "$py" -m venv "$VENV_DIR" &>/dev/null \
|| die "Failed to create virtual environment."
"$VENV_PYTHON" -m ensurepip --upgrade --default-pip &>/dev/null || true
fi
"$VENV_PYTHON" -m pip install --quiet --no-cache-dir --upgrade pip &>/dev/null || true
if [[ -f "$SRC_DIR/requirements.txt" ]]; then
"$VENV_PYTHON" -m pip install --quiet --no-cache-dir -r "$SRC_DIR/requirements.txt" &>/dev/null \
|| die "Failed to install Python requirements."
else
"$VENV_PYTHON" -m pip install --quiet --no-cache-dir pyzmq &>/dev/null \
|| die "Failed to install pyzmq."
fi
ok "Python environment ready."
}
set_permissions() {
info "Setting permissions..."
chmod +x "$SRC_DIR/UXTU4Linux.py"
local ryzenadj="$SRC_DIR/Assets/Linux/ryzenadj"
[[ -f "$ryzenadj" ]] && chmod +x "$ryzenadj"
ok "Permissions set."
}
install_wrapper() {
info "Installing launcher..."
sudo tee "$BIN_WRAPPER" > /dev/null <<EOF
#!/usr/bin/env bash
exec "$VENV_PYTHON" "$SRC_DIR/UXTU4Linux.py" "\$@"
EOF
sudo chmod +x "$BIN_WRAPPER"
[[ -x "$BIN_WRAPPER" ]] || die "Failed to install launcher at $BIN_WRAPPER"
ok "Launcher installed: $BIN_WRAPPER"
}
daemon_is_installed() {
[[ -f "$SERVICE_FILE" ]]
}
restart_daemon() {
info "Restarting daemon..."
sudo systemctl daemon-reload
sudo systemctl restart "$SERVICE_NAME" \
&& ok "Daemon restarted." \
|| warn "Could not restart daemon — run: sudo systemctl status $SERVICE_NAME"
}
print_banner() {
local tag="$1"
clear
echo ""
echo -e "${_B}+----------------------------------------------------------+"
echo -e "| _ ___ _______ _ _ _ _ _ _ |"
echo -e "| | | | \ \/ /_ _| | | | || | | | (_)_ __ _ ___ __ |"
echo -e "| | | | |\ / | | | | | | || |_| | | | '_ \| | | \ \/ / |"
echo -e "| | |_| |/ \ | | | |_| |__ _| |___| | | | | |_| |> < |"
echo -e "| \___//_/\_\ |_| \___/ |_| |_____|_|_| |_|\__,_/_/\_\ |"
echo -e "+----------------------------------------------------------+${_R}"
echo ""
echo -e " ${_D}Installer · ${tag}${_R}"
hr
echo -e " ${_D}Install : $INSTALL_DIR${_R}"
echo -e " ${_D}Source : $SRC_DIR${_R}"
echo -e " ${_D}Launcher : $BIN_WRAPPER${_R}"
hr
echo ""
}
run_setup() {
echo ""
hr
ok "Installation complete."
hr
echo ""
if daemon_is_installed; then
restart_daemon
echo ""
fi
echo -e " ${_G}Done!${_R} Run the app with:"
echo ""
echo -e " ${_B}uxtu4linux${_R}"
echo ""
}
main() {
local tag
tag="$(resolve_release_tag)"
print_banner "$tag"
local pm
pm="$(detect_pm)"
info "Package manager: $pm"
check_systemd
if daemon_is_installed; then
echo ""
warn "Existing installation found — updating files and restarting daemon."
fi
hr
echo ""
ensure_python310 "$pm"
install_deps "$pm"
download_release
install_files
patch_entry_point
setup_venv
set_permissions
install_wrapper
run_setup
}
main "$@"