-
Notifications
You must be signed in to change notification settings - Fork 16
/
startup
185 lines (151 loc) · 5.73 KB
/
startup
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
#!/usr/bin/env sh
CSI="\033["
CEND="${CSI}0m"
CRED="${CSI}1;31m"
CGREEN="${CSI}1;32m"
CYELLOW="${CSI}1;33m"
CBLUE="${CSI}1;34m"
f_log() {
LOG_TYPE="${1}"
LOG_MESSAGE="${2}"
case "${LOG_TYPE}" in
"INF")
echo -en "${CBLUE}[$(date +%Y/%m/%d-%H:%M:%S)] ${LOG_MESSAGE}${CEND}"
;;
"SUC")
echo -e "${CGREEN}${LOG_MESSAGE}${CEND}"
;;
"WRN")
echo -e "${CYELLOW}[$(date +%Y/%m/%d-%H:%M:%S)] ${LOG_MESSAGE}${CEND}"
;;
"ERR")
echo -e "${CRED}[$(date +%Y/%m/%d-%H:%M:%S)] ${LOG_MESSAGE}${CEND}"
;;
esac
}
f_log INF "Create torrent user... "
if [ -z "$(grep :${GID}: /etc/group)" ]; then
addgroup -g "${GID}" torrent
fi
if [ -z "$(grep :${UID}: /etc/passwd)" ]; then
group="$(grep :${GID}: /etc/group | cut -f 1 -d :)"
adduser -h /home/torrent -s /bin/sh -G "${group}" -D -u "${UID}" torrent
f_log SUC "done" # success of Create torrent user
elif [ -e /config/rtorrent/.rtorrent.rc ]; then
f_log SUC "done" # success of Create torrent user
else
echo ""
f_log ERR "Unable to create torrent user, you cannot use UID ${UID}"
exit 1
fi
f_log INF "Create volume folders... "
mkdir -p /data/.watch /data/.session /data/downloads
mkdir -p /config/rtorrent /config/rutorrent /config/custom_themes /config/custom_plugins
f_log SUC "done" # success of Create volume folders
f_log INF "Generate configuration... "
# Externalize rutorrent configuration
if [ -d /config/rutorrent/conf ]; then
rm -rf /rutorrent/app/conf
ln -s /config/rutorrent/conf /rutorrent/app/conf
else
mv /rutorrent/app/conf /config/rutorrent
ln -s /config/rutorrent/conf /rutorrent/app/conf
fi
# Externalize rutorrent share
if [ -d /config/rutorrent/share ]; then
rm -rf /rutorrent/app/share
ln -s /config/rutorrent/share /rutorrent/app/share
else
mv /rutorrent/app/share /config/rutorrent
ln -s /config/rutorrent/share /rutorrent/app/share
fi
# Add custom plugins
[ "$(ls /config/custom_plugins)" ] && for plugin in $(ls /config/custom_plugins); do
if [ ! -d "/rutorrent/app/plugins/${plugin}" ]; then
ln -s "/config/custom_plugins/${plugin}" "/rutorrent/app/plugins/${plugin}"
fi
done
# Add custom themes
[ "$(ls /config/custom_themes)" ] && for theme in $(ls /config/custom_themes); do
if [ ! -d "/rutorrent/app/plugins/theme/themes/${theme}" ]; then
ln -s "/config/custom_themes/${theme}" "/rutorrent/app/plugins/theme/themes/${theme}"
fi
done
sed -e "s|<DHT_RTORRENT>|${DHT_RTORRENT}|g" -e "s|<PORT_RTORRENT>|${PORT_RTORRENT}|g" -i /home/torrent/.rtorrent.rc
# Externalize rtorrent configuration
if [ -e /config/rtorrent/.rtorrent.rc ]; then
ln -sf /config/rtorrent/.rtorrent.rc /home/torrent/.rtorrent.rc
else
mv /home/torrent/.rtorrent.rc /config/rtorrent/.rtorrent.rc
ln -s /config/rtorrent/.rtorrent.rc /home/torrent/.rtorrent.rc
fi
f_log SUC "done" # success of Generate configuration
f_log INF "HTTP authentication configuration... "
# Add http authentication
if [ "${HTTP_AUTH}" = true ]; then
mkdir -p /config/nginx/passwd
sed -e "s|<auth>|auth_basic \"rutorrent\";\n auth_basic_user_file \"/config/nginx/passwd/rutorrent_passwd\";|g" -i /etc/nginx/nginx.conf
else
sed "/<auth>/d" -i /etc/nginx/nginx.conf
fi
f_log SUC "done" # success of HTTP authentication configuration
# Filebot configuration
if [ -e /filebot/filebot.sh ]; then
f_log INF "Configuration of filebot... "
mkdir -p /data/media /config/filebot
# Externalize filebot data folder
if [ -d /config/filebot/data ]; then
rm -rf /filebot/data
ln -s /config/filebot/data /filebot/data
else
mkdir -p /config/filebot/data
rm -rf /filebot/data
ln -s /config/filebot/data /filebot/data
fi
# Add license file
if [ ! -e "${FILEBOT_LICENSE}" ]; then
f_log ERR "License filebot file does not exist"
exit 1
elif [ ! -e /filebot/data/.license ]; then
/filebot/filebot.sh --license "${FILEBOT_LICENSE}"
fi
# Externalize args_amc.txt file
if [ -e /config/filebot/args_amc.txt ]; then
ln -sf /config/filebot/args_amc.txt /filebot/args_amc.txt
else
mv /filebot/args_amc.txt /config/filebot/args_amc.txt
ln -s /config/filebot/args_amc.txt /filebot/args_amc.txt
fi
# Custom postdl script
if [ -e /config/filebot/postdl ]; then
ln -sf /config/filebot/postdl /usr/local/bin/postdl
fi
if [ -z "$(grep ^method.set_key.*event.download.finished,filebot /home/torrent/.rtorrent.rc)" ]; then
echo 'method.set_key = event.download.finished,filebot,"execute2=/usr/local/bin/postdl,$d.base_path=,$d.name="' >> /home/torrent/.rtorrent.rc
fi
if [ -z "$(grep ^method.set_key.*event.download.erased,filebot_cleaner /home/torrent/.rtorrent.rc)" ]; then
echo 'method.set_key = event.download.erased,filebot_cleaner,"execute2=/usr/local/bin/postrm"' >> /home/torrent/.rtorrent.rc
fi
find /filebot ! -user "${UID}" -exec chown -h "${UID}:${GID}" {} \;
chmod +x /usr/local/bin/postdl /usr/local/bin/postrm
f_log SUC "done" # success of Configuration of filebot
fi
f_log INF "Update old configurations... "
/usr/local/bin/update-config
f_log SUC "done" # success of Update old configurations
f_log INF "Apply system permissions... "
for folder in /config /rutorrent /home/torrent /var/lib/nginx /var/log /etc/nginx /etc/php7 /tmp /etc/s6.d /run; do
find "${folder}" ! -user "${UID}" -exec chown -h "${UID}:${GID}" {} \;
done
find /etc/s6.d -type f -exec chmod +x {} \;
f_log SUC "done" # success of Apply system permissions
# set perm
chown "${UID}:${GID}" /data/.watch /data/.session /data/downloads
if [ "${CHECK_PERM_DATA}" = true ]; then
f_log INF "Apply data permissions... "
find /data ! -user "${UID}" -exec chown -h "${UID}:${GID}" {} \;
chown root:root /data # fix chroot sftp
f_log SUC "done" # success of Apply data permissions
fi
rm -f /data/.session/rtorrent.lock
exec su-exec "${UID}":"${GID}" "$@"