blob: 66ce6de911894daf12b2ce247f2fd0e7d5660d65 (
plain)
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
|
_torrcli_detect_user() {
if [[ -n "${SUDO_USER:-}" && "${SUDO_USER}" != "root" ]]; then
printf '%s\n' "${SUDO_USER}"
return 0
fi
local login_name
login_name=$(logname 2>/dev/null || true)
if [[ -n "${login_name}" && "${login_name}" != "root" ]]; then
printf '%s\n' "${login_name}"
return 0
fi
local first_uid_user
first_uid_user=$(getent passwd 1000 2>/dev/null | cut -d: -f1)
if [[ -n "${first_uid_user}" ]]; then
printf '%s\n' "${first_uid_user}"
return 0
fi
return 1
}
post_install() {
local torrcli_user
if ! torrcli_user=$(_torrcli_detect_user); then
torrcli_user=root
echo "Warning: could not detect a non-root login user; configuring torrcli.service to run as root."
fi
sed -i "s|__USER__|${torrcli_user}|" /usr/lib/systemd/system/torrcli.service
echo "Enabling and starting torrcli service..."
systemctl daemon-reload
systemctl enable --now torrcli.service
}
post_upgrade() {
local torrcli_user
if ! torrcli_user=$(_torrcli_detect_user); then
torrcli_user=root
echo "Warning: could not detect a non-root login user; configuring torrcli.service to run as root."
fi
sed -i "s|__USER__|${torrcli_user}|" /usr/lib/systemd/system/torrcli.service
echo "Reloading daemon and restarting torrcli service..."
systemctl daemon-reload
systemctl restart torrcli.service
}
pre_remove() {
echo "Stopping torrcli service..."
systemctl stop torrcli.service
systemctl disable torrcli.service
systemctl daemon-reload
}
|