-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseerr.sh
More file actions
420 lines (378 loc) · 13.3 KB
/
Copy pathseerr.sh
File metadata and controls
420 lines (378 loc) · 13.3 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#!/bin/bash
# thx flyingsausages and swizzin team
# based on the overseerr install script
# --- Privilege detection -----------------------------------------------------
if [[ $EUID -eq 0 ]]; then
if [[ -z "${SUDO_USER:-}" ]] || [[ "$SUDO_USER" == "root" ]]; then
echo "Run this script with sudo from your normal user account (not directly as root)."
exit 1
fi
SUDO_MODE=true
target_user="$SUDO_USER"
else
SUDO_MODE=false
target_user="$(whoami)"
fi
target_home="$(getent passwd "$target_user" | cut -d: -f6)"
target_uid="$(id -u "$target_user")"
if ! $SUDO_MODE; then
echo ""
echo "Not running with sudo."
echo "Without sudo this installer cannot:"
echo " - configure nginx so seerr is reachable at https://<host>/seerr"
echo " - add seerr to the swizzin dashboard"
echo ""
read -r -p "Type 'continue' to install seerr without those steps, or anything else to exit: " sudo_choice
if [[ "$sudo_choice" != "continue" ]]; then
echo "Aborting."
exit 0
fi
fi
export user="$target_user"
mkdir -p "$target_home/.logs/"
touch "$target_home/.logs/seerr.log"
if $SUDO_MODE; then
chown -R "$target_user:$target_user" "$target_home/.logs"
fi
export log="$target_home/.logs/seerr.log"
# --- Helpers to run things as the target user -------------------------------
run_as_user() {
if $SUDO_MODE; then
sudo -u "$target_user" -H bash -lc "$1"
else
bash -lc "$1"
fi
}
systemctl_user() {
if $SUDO_MODE; then
sudo -u "$target_user" \
XDG_RUNTIME_DIR="/run/user/$target_uid" \
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$target_uid/bus" \
systemctl --user "$@"
else
systemctl --user "$@"
fi
}
# Ensure systemd --user services survive logout.
_check_linger() {
if loginctl show-user "$target_user" 2>/dev/null | grep -q 'Linger=yes'; then
return 0
fi
echo "Linger is not enabled for $target_user — enabling now..."
loginctl enable-linger "$target_user"
echo "Linger enabled for $target_user."
}
# --- Install steps -----------------------------------------------------------
function _deps() {
if [[ ! -d "$target_home/.nvm" ]]; then
echo "Installing node"
run_as_user 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/refs/heads/master/install.sh | bash' >> "$log" 2>&1
echo "nvm installed."
else
echo "nvm is already installed."
fi
run_as_user '
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install --lts
' >> "$log" 2>&1 || {
echo "node failed to install"
exit 1
}
echo "Node LTS installed."
echo "Installing pnpm"
run_as_user '
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
npm install -g pnpm
' >> "$log" 2>&1 || {
echo "pnpm failed to install"
exit 1
}
echo "pnpm installed."
}
function _seerr_install() {
echo "Downloading and extracting source code"
dlurl="$(curl -sS https://api.github.com/repos/seerr-team/seerr/releases/latest | jq .tarball_url -r)"
run_as_user "wget '$dlurl' -q -O '$target_home/seerr.tar.gz'" >> "$log" 2>&1 || {
echo "Download failed"
exit 1
}
run_as_user "mkdir -p '$target_home/seerr' && tar --strip-components=1 -C '$target_home/seerr' -xzvf '$target_home/seerr.tar.gz' && rm '$target_home/seerr.tar.gz'" >> "$log" 2>&1
echo "Code extracted"
# Bypass Node version requirement, build with latest LTS.
run_as_user "sed -i 's|engine-strict=true|engine-strict=false|g' '$target_home/seerr/.npmrc'"
echo "Installing dependencies via pnpm (this might take a while)"
run_as_user "
export NVM_DIR=\"\$HOME/.nvm\"
[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"
pnpm install --prefix '$target_home/seerr'
" >> "$log" 2>&1 || {
echo "Failed to install dependencies"
exit 1
}
echo "Dependencies installed"
echo "Building seerr (this might take a while)"
# Limit CPU
run_as_user "sed -i 's|256000,|256000,\n cpus: 6,|g' '$target_home/seerr/next.config.js'"
run_as_user "
export NVM_DIR=\"\$HOME/.nvm\"
[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"
pnpm --prefix '$target_home/seerr' build
" >> "$log" 2>&1 || {
echo "Failed to build seerr"
exit 1
}
echo "Succesfully built"
}
function _port() {
LOW_BOUND=$1
UPPER_BOUND=$2
comm -23 <(seq "${LOW_BOUND}" "${UPPER_BOUND}" | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1
}
function _service() {
_check_linger
run_as_user "mkdir -p '$target_home/.config/systemd/user' '$target_home/.install' '$target_home/.config/seerr'"
node_path="$(run_as_user 'export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; which node' | tail -n1)"
tmp_unit="$(mktemp)"
cat > "$tmp_unit" << EOF
[Unit]
Description=seerr Service
Wants=network-online.target
After=network-online.target
[Service]
EnvironmentFile=%h/seerr/env.conf
Environment=NODE_ENV=production
Type=exec
Restart=on-failure
WorkingDirectory=%h/seerr
ExecStart=$node_path dist/index.js
[Install]
WantedBy=default.target
EOF
install -m 0644 -o "$target_user" -g "$target_user" "$tmp_unit" "$target_home/.config/systemd/user/seerr.service"
rm -f "$tmp_unit"
SEERR_PORT=$(_port 1000 18000)
tmp_env="$(mktemp)"
cat > "$tmp_env" << EOF
# specify on which port to listen
PORT=$SEERR_PORT
EOF
install -m 0644 -o "$target_user" -g "$target_user" "$tmp_env" "$target_home/seerr/env.conf"
rm -f "$tmp_env"
systemctl_user daemon-reload
systemctl_user enable --now -q seerr
run_as_user "touch '$target_home/.install/.seerr.lock'"
if $SUDO_MODE; then
echo "seerr listening on 127.0.0.1:$SEERR_PORT (nginx will expose it at /seerr)"
else
echo "seerr is up and running on http://$(hostname -f):$SEERR_PORT"
fi
}
# --- Nginx + swizzin dashboard (root only) ----------------------------------
function _nginx() {
if [[ -z "${SEERR_PORT:-}" ]]; then
echo "SEERR_PORT not set, skipping nginx config."
return 1
fi
htpasswd_file="/etc/htpasswd.d/htpasswd.${target_user}"
auth_block=""
if [[ -f "$htpasswd_file" ]]; then
auth_block=" auth_basic \"What's the password?\";
auth_basic_user_file ${htpasswd_file};"
fi
local hostname
hostname="$(hostname -f)"
read -r -p " Hostname for seerr redirect [$hostname]: " hostname_input
[[ -n "$hostname_input" ]] && hostname="$hostname_input"
mkdir -p /etc/nginx/apps
cat > /etc/nginx/apps/seerr.conf << EOF
location /seerr {
return 301 http://${hostname}:${SEERR_PORT}/;
}
EOF
if nginx -t >> "$log" 2>&1; then
systemctl reload nginx
echo "nginx configured. seerr reachable at https://$(hostname -f)/seerr"
else
echo "nginx config test failed. Check $log and /etc/nginx/apps/seerr.conf."
return 1
fi
}
function _dashboard() {
icon_dir="/opt/swizzin/static/img/apps"
icon_url="https://raw.githubusercontent.com/Flawkee/swizzin.apps/main/seerr.png"
if curl -fsSL -o "$icon_dir/seerr.png" "$icon_url" 2>>"$log"; then
echo "Icon installed to $icon_dir/seerr.png"
else
echo "Could not download seerr icon from $icon_url (continuing without custom icon)."
fi
profiles="/opt/swizzin/core/custom/profiles.py"
mkdir -p "$(dirname "$profiles")"
[[ -f "$profiles" ]] || touch "$profiles"
if ! grep -q "^class seerr_meta:" "$profiles"; then
cat >> "$profiles" << 'EOF'
class seerr_meta:
name = "seerr"
pretty_name = "Seerr"
baseurl = "/seerr"
systemd = "seerr"
img = "seerr"
runas = "user"
EOF
echo "Appended seerr_meta to $profiles"
else
echo "seerr_meta already present in $profiles"
fi
mkdir -p /install
touch /install/.seerr.lock
systemctl restart panel
echo "swizzin dashboard updated."
}
function _remove() {
systemctl_user disable --now seerr 2>/dev/null || true
sleep 2
run_as_user "rm -rf '$target_home/seerr' '$target_home/.config/seerr' '$target_home/.config/systemd/user/seerr.service' '$target_home/.install/.seerr.lock'"
if $SUDO_MODE; then
rm -f /etc/nginx/apps/seerr.conf
if nginx -t >> "$log" 2>&1; then
systemctl reload nginx
fi
rm -f /install/.seerr.lock
if [[ -f /opt/swizzin/core/custom/profiles.py ]]; then
python3 - << 'PY'
import re
p = "/opt/swizzin/core/custom/profiles.py"
with open(p) as f:
t = f.read()
t = re.sub(r"\n*class seerr_meta:.*?(?=\nclass |\Z)", "", t, flags=re.S)
with open(p, "w") as f:
f.write(t.rstrip() + "\n")
PY
fi
rm -f /opt/swizzin/static/img/apps/seerr.png
systemctl restart panel 2>/dev/null || true
fi
}
# --- Entry point -------------------------------------------------------------
echo 'This is unsupported software. You will not get help with this, please answer `yes` if you understand and wish to proceed'
if [[ -z ${eula} ]]; then
read -r eula
fi
if ! [[ $eula =~ yes ]]; then
echo "You did not accept the above. Exiting..."
exit 1
else
echo "Proceeding with installation"
fi
function _show() {
lock="$target_home/.install/.seerr.lock"
if [[ ! -f "$lock" ]]; then
echo "seerr is not installed. Run 'install' first."
return
fi
# Read port from env.conf
port=""
env_conf="$target_home/seerr/env.conf"
if [[ -f "$env_conf" ]]; then
port="$(grep -E '^PORT=' "$env_conf" | cut -d= -f2)"
fi
# Service status
svc_status="$(systemctl_user is-active seerr 2>/dev/null || echo "unknown")"
# Nginx
nginx_conf="/etc/nginx/apps/seerr.conf"
if [[ -f "$nginx_conf" ]]; then
nginx_status="configured ($nginx_conf)"
url="http://$(hostname -f):${port:-?} (nginx /seerr redirects here)"
else
nginx_status="not configured"
url="http://$(hostname -f):${port:-?}"
fi
# Swizzin panel
panel_lock="/install/.seerr.lock"
profile_entry=""
if [[ -f "$panel_lock" ]] && grep -q "^class seerr_meta:" /opt/swizzin/core/custom/profiles.py 2>/dev/null; then
panel_status="configured"
else
panel_status="not configured"
fi
echo ""
echo "=============================="
echo " seerr installation summary"
echo "=============================="
echo " Service name : seerr"
echo " Service status: $svc_status"
echo " Port : ${port:-unknown}"
echo " URL : $url"
echo " nginx : $nginx_status"
echo " swizzin panel : $panel_status"
echo ""
echo " Useful commands:"
echo " systemctl --user status seerr"
echo " systemctl --user restart seerr"
echo " journalctl --user -u seerr -f"
echo " tail -f $target_home/.logs/seerr.log"
echo "=============================="
echo ""
}
echo "Welcome to the seerr installer..."
echo ""
echo "What do you like to do?"
echo ""
echo "show = Show current installation status and configuration"
echo "install = Install seerr"
echo "uninstall = Completely removes seerr"
echo "exit = Exits Installer"
while true; do
read -r -p "Enter it here: " choice
case $choice in
"show")
_show
;;
"install")
clear
_deps
_seerr_install
_service
if $SUDO_MODE; then
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " nginx + swizzin dashboard setup — please read before continuing"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " The following will be configured:"
echo ""
echo " 1. /etc/nginx/apps/seerr.conf"
echo " - Redirects https://<host>/seerr → http://$(hostname -f):$SEERR_PORT/"
echo " - Simple redirect: no path rewriting, seerr runs directly on its port."
echo ""
echo " 2. /opt/swizzin/core/custom/profiles.py"
echo " - Appends seerr_meta so seerr appears in the swizzin panel sidebar."
echo ""
echo " 3. /install/.seerr.lock + panel restart"
echo ""
read -r -p " Proceed with nginx + dashboard setup? [yes/skip]: " nginx_confirm
if [[ "$nginx_confirm" == "yes" ]]; then
_nginx
_dashboard
else
echo " Skipped. seerr is running on http://$(hostname -f):$SEERR_PORT"
echo " You can re-run the installer and choose 'install' again to set it up later."
fi
echo ""
fi
break
;;
"uninstall")
_remove
break
;;
"exit")
break
;;
*)
echo "Unknown Option."
;;
esac
done
exit