-
-
Notifications
You must be signed in to change notification settings - Fork 306
/
autobrr.sh
executable file
·127 lines (106 loc) · 2.94 KB
/
autobrr.sh
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
#!/bin/bash
# autobrr installer
# ludviglundgren 2021 for Swizzin
#shellcheck source=sources/functions/utils
. /etc/swizzin/sources/functions/utils
#shellcheck source=sources/functions/autobrr
. /etc/swizzin/sources/functions/autobrr
_systemd() {
type=simple
if [[ $(systemctl --version | awk 'NR==1 {print $2}') -ge 240 ]]; then
type=exec
fi
echo_progress_start "Installing Systemd service"
cat > /etc/systemd/system/autobrr@.service << EOF
[Unit]
Description=autobrr service for %i
After=syslog.target network.target
[Service]
Type=$type
User=%i
Group=%i
ExecStart=/usr/bin/autobrr --config=/home/%i/.config/autobrr/
[Install]
WantedBy=multi-user.target
EOF
echo_progress_done "Service installed"
}
_nginx() {
if [[ -f /install/.nginx.lock ]]; then
echo_progress_start "Configuring nginx for autobrr"
bash /etc/swizzin/scripts/nginx/autobrr.sh
systemctl reload nginx >> $log 2>&1
echo_progress_done "Nginx configured for autobrr"
fi
}
# This method will perform all logic related to user accounts. For each user when installed, and for only one user when via box adduser
_add_users() {
for user in "${users[@]}"; do
echo_progress_start "Enabling autobrr for $user"
# get random available port
port=$(port 10000 12000)
# generate a sessionSecret
sessionSecret="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c16)"
mkdir -p "/home/$user/.config/autobrr/"
chown "$user": "/home/$user/.config"
chown -R "$user": "/home/$user/.config/autobrr"
cat > "/home/$user/.config/autobrr/config.toml" << CFG
# config.toml
# Hostname / IP
#
# Default: "localhost"
#
host = "0.0.0.0"
# Port
#
# Default: 8989
#
port = ${port}
# Base url
# Set custom baseUrl eg /autobrr/ to serve in subdirectory.
# Not needed for subdomain, or by accessing with the :port directly.
#
# Optional
#
baseUrl = "/autobrr/"
# autobrr logs file
# If not defined, logs to stdout
#
# Optional
#
logPath = "/home/${user}/.config/autobrr/logs/autobrr.log"
# Log level
#
# Default: "DEBUG"
#
# Options: "ERROR", "DEBUG", "INFO", "WARN"
#
logLevel = "DEBUG"
# Session secret
#
sessionSecret = "${sessionSecret}"
CFG
_get_user_password "$user" | /usr/bin/autobrrctl --config "/home/$user/.config/autobrr" create-user "$user" || {
echo_error "Failed to execute autobrrctl command"
exit 1
}
chown -R "$user": "/home/$user/.config/autobrr"
systemctl enable -q --now autobrr@"${user}" 2>&1 | tee -a $log
echo_progress_done "Started autobrr for $user"
done
}
##############################
# If `box adduser` is running, only do _add_users and then exit. Otherwise, run the whole installer
if [ -n "$1" ]; then
users=("$1")
_add_users
_nginx
exit 0
fi
autobrr_download_latest
_systemd
readarray -t users < <(_get_user_list)
_add_users
_nginx
touch "/install/.autobrr.lock"
echo_success "autobrr installed"