docker – Blame information for rev 62

Subversion Repositories:
Rev:
Rev Author Line No. Line
62 office 1 #!/usr/bin/with-contenv sh
2 # shellcheck shell=sh
3  
4 #WAN_IP=${WAN_IP:-10.0.0.1}
5 #WAN_IP_CMD=${WAN_IP_CMD:-"dig +short myip.opendns.com @resolver1.opendns.com"}
6  
7 TZ=${TZ:-UTC}
8 MEMORY_LIMIT=${MEMORY_LIMIT:-256M}
9 UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-16M}
10 CLEAR_ENV=${CLEAR_ENV:-yes}
11 OPCACHE_MEM_SIZE=${OPCACHE_MEM_SIZE:-128}
12 MAX_FILE_UPLOADS=${MAX_FILE_UPLOADS:-50}
13 AUTH_DELAY=${AUTH_DELAY:-0s}
14 REAL_IP_FROM=${REAL_IP_FROM:-0.0.0.0/32}
15 REAL_IP_HEADER=${REAL_IP_HEADER:-X-Forwarded-For}
16 LOG_IP_VAR=${LOG_IP_VAR:-remote_addr}
17 LOG_ACCESS=${LOG_ACCESS:-true}
18 XMLRPC_SIZE_LIMIT=${XMLRPC_SIZE_LIMIT:-1M}
19  
20 XMLRPC_AUTHBASIC_STRING=${XMLRPC_AUTHBASIC_STRING:-rTorrent XMLRPC restricted access}
21 RUTORRENT_AUTHBASIC_STRING=${RUTORRENT_AUTHBASIC_STRING:-ruTorrent restricted access}
22 WEBDAV_AUTHBASIC_STRING=${WEBDAV_AUTHBASIC_STRING:-WebDAV restricted access}
23  
24 RT_LOG_LEVEL=${RT_LOG_LEVEL:-info}
25 RT_LOG_EXECUTE=${RT_LOG_EXECUTE:-false}
26 RT_LOG_XMLRPC=${RT_LOG_XMLRPC:-false}
27 RT_SESSION_SAVE_SECONDS=${RT_SESSION_SAVE_SECONDS:-3600}
28 RT_TRACKER_DELAY_SCRAPE=${RT_TRACKER_DELAY_SCRAPE:-true}
29 RT_SEND_BUFFER_SIZE=${RT_SEND_BUFFER_SIZE:-4M}
30 RT_RECEIVE_BUFFER_SIZE=${RT_RECEIVE_BUFFER_SIZE:-4M}
31 RT_PREALLOCATE_TYPE=${RT_PREALLOCATE_TYPE:-0}
32  
33 RU_REMOVE_CORE_PLUGINS=${RU_REMOVE_CORE_PLUGINS:-false}
34 RU_HTTP_USER_AGENT=${RU_HTTP_USER_AGENT:-Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0}
35 RU_HTTP_TIME_OUT=${RU_HTTP_TIME_OUT:-30}
36 RU_HTTP_USE_GZIP=${RU_HTTP_USE_GZIP:-true}
37 RU_RPC_TIME_OUT=${RU_RPC_TIME_OUT:-5}
38 RU_LOG_RPC_CALLS=${RU_LOG_RPC_CALLS:-false}
39 RU_LOG_RPC_FAULTS=${RU_LOG_RPC_FAULTS:-true}
40 RU_PHP_USE_GZIP=${RU_PHP_USE_GZIP:-false}
41 RU_PHP_GZIP_LEVEL=${RU_PHP_GZIP_LEVEL:-2}
42 RU_SCHEDULE_RAND=${RU_SCHEDULE_RAND:-10}
43 RU_LOG_FILE=${RU_LOG_FILE:-/data/rutorrent/rutorrent.log}
44 RU_DO_DIAGNOSTIC=${RU_DO_DIAGNOSTIC:-true}
45 RU_CACHED_PLUGIN_LOADING=${RU_CACHED_PLUGIN_LOADING:-false}
46 RU_SAVE_UPLOADED_TORRENTS=${RU_SAVE_UPLOADED_TORRENTS:-true}
47 RU_OVERWRITE_UPLOADED_TORRENTS=${RU_OVERWRITE_UPLOADED_TORRENTS:-false}
48 RU_FORBID_USER_SETTINGS=${RU_FORBID_USER_SETTINGS:-false}
49 RU_LOCALE=${RU_LOCALE:-UTF8}
50  
51 RT_DHT_PORT=${RT_DHT_PORT:-6881}
52 RT_INC_PORT=${RT_INC_PORT:-50000}
53 XMLRPC_PORT=${XMLRPC_PORT:-8000}
54 XMLRPC_HEALTH_PORT=$((XMLRPC_PORT + 1))
55 RUTORRENT_PORT=${RUTORRENT_PORT:-8080}
56 RUTORRENT_HEALTH_PORT=$((RUTORRENT_PORT + 1))
57 WEBDAV_PORT=${WEBDAV_PORT:-9000}
58 WEBDAV_HEALTH_PORT=$((WEBDAV_PORT + 1))
59  
60 # WAN IP
61 if [ -z "$WAN_IP" ] && [ -n "$WAN_IP_CMD" ]; then
62 WAN_IP=$(eval "$WAN_IP_CMD")
63 fi
64 if [ -n "$WAN_IP" ]; then
65 echo "Public IP address enforced to ${WAN_IP}"
66 fi
67 printf "%s" "$WAN_IP" > /var/run/s6/container_environment/WAN_IP
68  
69 # Timezone
70 echo "Setting timezone to ${TZ}..."
71 ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
72 echo ${TZ} > /etc/timezone
73  
74 # PHP
75 echo "Setting PHP-FPM configuration..."
76 sed -e "s/@MEMORY_LIMIT@/$MEMORY_LIMIT/g" \
77 -e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \
78 -e "s/@CLEAR_ENV@/$CLEAR_ENV/g" \
79 /tpls/etc/php83/php-fpm.d/www.conf > /etc/php83/php-fpm.d/www.conf
80  
81 echo "Setting PHP INI configuration..."
82 sed -i "s|memory_limit.*|memory_limit = ${MEMORY_LIMIT}|g" /etc/php83/php.ini
83 sed -i "s|;date\.timezone.*|date\.timezone = ${TZ}|g" /etc/php83/php.ini
84 sed -i "s|max_file_uploads.*|max_file_uploads = ${MAX_FILE_UPLOADS}|g" /etc/php83/php.ini
85  
86 # OpCache
87 echo "Setting OpCache configuration..."
88 sed -e "s/@OPCACHE_MEM_SIZE@/$OPCACHE_MEM_SIZE/g" \
89 /tpls/etc/php83/conf.d/opcache.ini > /etc/php83/conf.d/opcache.ini
90  
91 # Nginx
92 echo "Setting Nginx configuration..."
93 sed -e "s#@REAL_IP_FROM@#$REAL_IP_FROM#g" \
94 -e "s#@REAL_IP_HEADER@#$REAL_IP_HEADER#g" \
95 -e "s#@LOG_IP_VAR@#$LOG_IP_VAR#g" \
96 -e "s#@AUTH_DELAY@#$AUTH_DELAY#g" \
97 /tpls/etc/nginx/nginx.conf > /etc/nginx/nginx.conf
98 if [ "${LOG_ACCESS}" != "true" ]; then
99 echo " Disabling Nginx access log..."
100 sed -i "s!access_log /proc/self/fd/1 main!access_log off!g" /etc/nginx/nginx.conf
101 fi
102  
103 # Nginx XMLRPC over SCGI
104 echo "Setting Nginx XMLRPC over SCGI configuration..."
105 sed -e "s!@XMLRPC_AUTHBASIC_STRING@!$XMLRPC_AUTHBASIC_STRING!g" \
106 -e "s!@XMLRPC_PORT@!$XMLRPC_PORT!g" \
107 -e "s!@XMLRPC_HEALTH_PORT@!$XMLRPC_HEALTH_PORT!g" \
108 -e "s!@XMLRPC_SIZE_LIMIT@!$XMLRPC_SIZE_LIMIT!g" \
109 /tpls/etc/nginx/conf.d/rpc.conf > /etc/nginx/conf.d/rpc.conf
110  
111 # Nginx ruTorrent
112 echo "Setting Nginx ruTorrent configuration..."
113 sed -e "s!@UPLOAD_MAX_SIZE@!$UPLOAD_MAX_SIZE!g" \
114 -e "s!@RUTORRENT_AUTHBASIC_STRING@!$RUTORRENT_AUTHBASIC_STRING!g" \
115 -e "s!@RUTORRENT_PORT@!$RUTORRENT_PORT!g" \
116 -e "s!@RUTORRENT_HEALTH_PORT@!$RUTORRENT_HEALTH_PORT!g" \
117 /tpls/etc/nginx/conf.d/rutorrent.conf > /etc/nginx/conf.d/rutorrent.conf
118  
119 # Nginx WebDAV
120 echo "Setting Nginx WebDAV configuration..."
121 sed -e "s!@WEBDAV_AUTHBASIC_STRING@!$WEBDAV_AUTHBASIC_STRING!g" \
122 -e "s!@WEBDAV_PORT@!$WEBDAV_PORT!g" \
123 -e "s!@WEBDAV_HEALTH_PORT@!$WEBDAV_HEALTH_PORT!g" \
124 /tpls/etc/nginx/conf.d/webdav.conf > /etc/nginx/conf.d/webdav.conf
125  
126 # Healthcheck
127 echo "Update healthcheck script..."
128 cat > /usr/local/bin/healthcheck <<EOL
129 #!/bin/sh
130 set -e
131  
132 # rTorrent
133 curl --fail -H "Content-Type: text/xml" -d "<?xml version='1.0'?><methodCall><methodName>system.api_version</methodName></methodCall>" http://127.0.0.1:${XMLRPC_HEALTH_PORT}
134  
135 # ruTorrent / PHP
136 curl --fail http://127.0.0.1:${RUTORRENT_HEALTH_PORT}/ping
137  
138 # WebDAV
139 curl --fail http://127.0.0.1:${WEBDAV_HEALTH_PORT}
140 EOL
141  
142 # Init
143 echo "Initializing files and folders..."
144 mkdir -p /data/geoip \
145 /data/rtorrent/log \
146 /data/rtorrent/.session \
147 /data/rtorrent/watch \
148 /data/rutorrent/conf/users \
149 /data/rutorrent/plugins \
150 /data/rutorrent/plugins-conf \
151 /data/rutorrent/share/users \
152 /data/rutorrent/share/torrents \
153 /data/rutorrent/themes/
154 /downloads
155 # x rtorrent 0.9.8
156 # /downloads/complete \
157 # /downloads/temp
158 touch /passwd/rpc.htpasswd \
159 /passwd/rutorrent.htpasswd \
160 /passwd/webdav.htpasswd \
161 /data/rtorrent/log/rtorrent.log \
162 "${RU_LOG_FILE}"
163 rm -f /data/rtorrent/.session/rtorrent.lock
164  
165 # Check htpasswd files
166 if [ ! -s "/passwd/rpc.htpasswd" ]; then
167 echo "rpc.htpasswd is empty, removing authentication..."
168 sed -i "s!auth_basic .*!#auth_basic!g" /etc/nginx/conf.d/rpc.conf
169 sed -i "s!auth_basic_user_file.*!#auth_basic_user_file!g" /etc/nginx/conf.d/rpc.conf
170 fi
171 if [ ! -s "/passwd/rutorrent.htpasswd" ]; then
172 echo "rutorrent.htpasswd is empty, removing authentication..."
173 sed -i "s!auth_basic .*!#auth_basic!g" /etc/nginx/conf.d/rutorrent.conf
174 sed -i "s!auth_basic_user_file.*!#auth_basic_user_file!g" /etc/nginx/conf.d/rutorrent.conf
175 fi
176 if [ ! -s "/passwd/webdav.htpasswd" ]; then
177 echo "webdav.htpasswd is empty, removing authentication..."
178 sed -i "s!auth_basic .*!#auth_basic!g" /etc/nginx/conf.d/webdav.conf
179 sed -i "s!auth_basic_user_file.*!#auth_basic_user_file!g" /etc/nginx/conf.d/webdav.conf
180 fi
181  
182 # rTorrent local config
183 echo "Checking rTorrent local configuration..."
184 sed -e "s!@RT_LOG_LEVEL@!$RT_LOG_LEVEL!g" \
185 -e "s!@RT_DHT_PORT@!$RT_DHT_PORT!g" \
186 -e "s!@RT_INC_PORT@!$RT_INC_PORT!g" \
187 -e "s!@XMLRPC_SIZE_LIMIT@!$XMLRPC_SIZE_LIMIT!g" \
188 -e "s!@RT_SESSION_SAVE_SECONDS@!$RT_SESSION_SAVE_SECONDS!g" \
189 -e "s!@RT_TRACKER_DELAY_SCRAPE@!$RT_TRACKER_DELAY_SCRAPE!g" \
190 -e "s!@RT_SEND_BUFFER_SIZE@!$RT_SEND_BUFFER_SIZE!g" \
191 -e "s!@RT_RECEIVE_BUFFER_SIZE@!$RT_RECEIVE_BUFFER_SIZE!g" \
192 -e "s!@RT_PREALLOCATE_TYPE@!$RT_PREALLOCATE_TYPE!g" \
193 /tpls/etc/rtorrent/.rtlocal.rc > /etc/rtorrent/.rtlocal.rc
194 if [ "${RT_LOG_EXECUTE}" = "true" ]; then
195 echo " Enabling rTorrent execute log..."
196 sed -i "s!#log\.execute.*!log\.execute = (cat,(cfg.logs),\"execute.log\")!g" /etc/rtorrent/.rtlocal.rc
197 fi
198 if [ "${RT_LOG_XMLRPC}" = "true" ]; then
199 echo " Enabling rTorrent xmlrpc log..."
200 sed -i "s!#log\.xmlrpc.*!log\.xmlrpc = (cat,(cfg.logs),\"xmlrpc.log\")!g" /etc/rtorrent/.rtlocal.rc
201 fi
202  
203 # rTorrent config
204 echo "Checking rTorrent configuration..."
205 if [ ! -f /data/rtorrent/.rtorrent.rc ]; then
206 echo " Creating default configuration..."
207 cp /tpls/.rtorrent.rc /data/rtorrent/.rtorrent.rc
208 fi
209 chown rtorrent:rtorrent /data/rtorrent/.rtorrent.rc
210  
211 # ruTorrent config
212 echo "Bootstrapping ruTorrent configuration..."
213 cat > /var/www/rutorrent/conf/config.php <<EOL
214 <?php
215  
216 // for snoopy client
217 \$httpUserAgent = '${RU_HTTP_USER_AGENT}';
218 \$httpTimeOut = ${RU_HTTP_TIME_OUT};
219 \$httpUseGzip = ${RU_HTTP_USE_GZIP};
220  
221 // for xmlrpc actions
222 \$rpcTimeOut = ${RU_RPC_TIME_OUT};
223 \$rpcLogCalls = ${RU_LOG_RPC_CALLS};
224 \$rpcLogFaults = ${RU_LOG_RPC_FAULTS};
225  
226 // for php
227 \$phpUseGzip = ${RU_PHP_USE_GZIP};
228 \$phpGzipLevel = ${RU_PHP_GZIP_LEVEL};
229  
230 // Rand for schedulers start, +0..X seconds
231 \$schedule_rand = ${RU_SCHEDULE_RAND};
232  
233 // Path to log file (comment or leave blank to disable logging)
234 \$log_file = '${RU_LOG_FILE}';
235 \$do_diagnostic = ${RU_DO_DIAGNOSTIC};
236  
237 // Set to true if rTorrent is hosted on the SAME machine as ruTorrent
238 \$localHostedMode = true;
239  
240 // Set to true to enable rapid cached loading of ruTorrent plugins
241 // Required to clear web browser cache during version upgrades
242 \$cachedPluginLoading = ${RU_CACHED_PLUGIN_LOADING};
243  
244 // Save uploaded torrents to profile/torrents directory or not
245 \$saveUploadedTorrents = ${RU_SAVE_UPLOADED_TORRENTS};
246  
247 // Overwrite existing uploaded torrents in profile/torrents directory or make unique name
248 \$overwriteUploadedTorrents = ${RU_OVERWRITE_UPLOADED_TORRENTS};
249  
250 // Upper available directory. Absolute path with trail slash.
251 \$topDirectory = '/';
252 \$forbidUserSettings = ${RU_FORBID_USER_SETTINGS};
253  
254 // For web->rtorrent link through unix domain socket
255 \$scgi_port = 0;
256 \$scgi_host = "unix:///var/run/rtorrent/scgi.socket";
257 \$XMLRPCMountPoint = "/RPC2"; // DO NOT DELETE THIS LINE!!! DO NOT COMMENT THIS LINE!!!
258 \$throttleMaxSpeed = 4294967294; // DO NOT EDIT THIS LINE!!! DO NOT COMMENT THIS LINE!!!
259  
260 \$pathToExternals = array(
261 "php" => '',
262 "curl" => '',
263 "gzip" => '',
264 "id" => '',
265 "stat" => '',
266 "python" => '$(which python3)',
267 );
268  
269 // List of local interfaces
270 \$localhosts = array(
271 "127.0.0.1",
272 "localhost",
273 );
274  
275 // Path to user profiles
276 \$profilePath = '/data/rutorrent/share';
277 // Mask for files and directory creation in user profiles.
278 \$profileMask = 0770;
279  
280 // Temp directory. Absolute path with trail slash. If null, then autodetect will be used.
281 \$tempDirectory = null;
282  
283 // If true then use X-Sendfile feature if it exist
284 \$canUseXSendFile = false;
285  
286 \$locale = '${RU_LOCALE}';
287  
288 \$enableCSRFCheck = false; // If true then Origin and Referer will be checked
289 \$enabledOrigins = array(); // List of enabled domains for CSRF check (only hostnames, without protocols, port etc.). If empty, then will retrieve domain from HTTP_HOST / HTTP_X_FORWARDED_HOST
290 EOL
291 chown nobody:nogroup "/var/www/rutorrent/conf/config.php"
292  
293 # Symlinking ruTorrent config
294 ln -sf /data/rutorrent/conf/users /var/www/rutorrent/conf/users
295 if [ ! -f /data/rutorrent/conf/access.ini ]; then
296 echo "Symlinking ruTorrent access.ini file..."
297 mv /var/www/rutorrent/conf/access.ini /data/rutorrent/conf/access.ini
298 ln -sf /data/rutorrent/conf/access.ini /var/www/rutorrent/conf/access.ini
299 fi
300 chown rtorrent:rtorrent /data/rutorrent/conf/access.ini
301 if [ ! -f /data/rutorrent/conf/plugins.ini ]; then
302 echo "Symlinking ruTorrent plugins.ini file..."
303 mv /var/www/rutorrent/conf/plugins.ini /data/rutorrent/conf/plugins.ini
304 ln -sf /data/rutorrent/conf/plugins.ini /var/www/rutorrent/conf/plugins.ini
305 fi
306 chown rtorrent:rtorrent /data/rutorrent/conf/plugins.ini
307  
308 # Remove ruTorrent core plugins
309 if [ "$RU_REMOVE_CORE_PLUGINS" != "false" ]; then
310 for i in ${RU_REMOVE_CORE_PLUGINS//,/ }
311 do
312 if [ -z "$i" ]; then continue; fi
313 if [ "$i" == "httprpc" ]; then
314 echo "Warning: skipping core plugin httprpc, required for ruTorrent v4.3+ operation"
315 echo "Please remove httprpc from RU_REMOVE_CORE_PLUGINS environment varriable"
316 continue;
317 fi
318 echo "Removing core plugin $i..."
319 rm -rf "/var/www/rutorrent/plugins/${i}"
320 done
321 fi
322  
323 echo "Setting custom config for create plugin..."
324 if [ -d "/var/www/rutorrent/plugins/create" ]; then
325  
326 cat > /var/www/rutorrent/plugins/create/conf.php <<EOL
327 <?php
328  
329 \$useExternal = 'mktorrent';
330 \$pathToCreatetorrent = '/usr/local/bin/mktorrent';
331 \$recentTrackersMaxCount = 15;
332 \$useInternalHybrid = true;
333 EOL
334 chown nobody:nogroup "/var/www/rutorrent/plugins/create/conf.php"
335 else
336 echo " WARNING: create plugin does not exist"
337 fi
338  
339 echo "Checking ruTorrent custom plugins..."
340 plugins=$(ls -l /data/rutorrent/plugins | grep -E '^d' | awk '{print $9}')
341 for plugin in ${plugins}; do
342 if [ "${plugin}" = "theme" ]; then
343 echo " WARNING: theme plugin cannot be overriden"
344 continue
345 fi
346 echo " Copying custom ${plugin} plugin..."
347 if [ -d "/var/www/rutorrent/plugins/${plugin}" ]; then
348 rm -rf "/var/www/rutorrent/plugins/${plugin}"
349 fi
350 cp -Rf "/data/rutorrent/plugins/${plugin}" "/var/www/rutorrent/plugins/${plugin}"
351 chown -R nobody:nogroup "/var/www/rutorrent/plugins/${plugin}"
352 done
353  
354 echo "Checking ruTorrent plugins configuration..."
355 for pluginConfFile in /data/rutorrent/plugins-conf/*.php; do
356 if [ ! -f "$pluginConfFile" ]; then
357 continue
358 fi
359 pluginConf=$(basename "$pluginConfFile")
360 pluginName=$(echo "$pluginConf" | cut -f 1 -d '.')
361 if [ ! -d "/var/www/rutorrent/plugins/${pluginName}" ]; then
362 echo " WARNING: $pluginName plugin does not exist"
363 continue
364 fi
365 if [ -d "/data/rutorrent/plugins/${pluginName}" ]; then
366 echo " WARNING: $pluginName plugin already exist in /data/rutorrent/plugins/"
367 continue
368 fi
369 echo " Copying ${pluginName} plugin config..."
370 cp -f "${pluginConfFile}" "/var/www/rutorrent/plugins/${pluginName}/conf.php"
371 chown nobody:nogroup "/var/www/rutorrent/plugins/${pluginName}/conf.php"
372 done
373  
374 echo "Checking ruTorrent custom themes..."
375 themes=$(ls -l /data/rutorrent/themes | grep -E '^d' | awk '{print $9}')
376 for theme in ${themes}; do
377 echo " Copying custom ${theme} theme..."
378 if [ -d "/var/www/rutorrent/plugins/theme/themes/${theme}" ]; then
379 rm -rf "/var/www/rutorrent/plugins/theme/themes/${theme}"
380 fi
381 cp -Rf "/data/rutorrent/themes/${theme}" "/var/www/rutorrent/plugins/theme/themes/${theme}"
382 chown -R nobody:nogroup "/var/www/rutorrent/plugins/theme/themes/${theme}"
383 done
384  
385 echo "Setting GeoIP2 databases for geoip2 plugin..."
386 if [ -d "/var/www/rutorrent/plugins/geoip2" ]; then
387 if [ ! "$(ls -A /data/geoip)" ]; then
388 cp -f /var/mmdb/*.mmdb /data/geoip/
389 fi
390 ln -sf /data/geoip/GeoLite2-ASN.mmdb /var/www/rutorrent/plugins/geoip2/database/GeoLite2-ASN.mmdb
391 ln -sf /data/geoip/GeoLite2-City.mmdb /var/www/rutorrent/plugins/geoip2/database/GeoLite2-City.mmdb
392 ln -sf /data/geoip/GeoLite2-Country.mmdb /var/www/rutorrent/plugins/geoip2/database/GeoLite2-Country.mmdb
393 else
394 echo " WARNING: geoip2 plugin does not exist"
395 fi
396  
397 echo "Fixing perms..."
398 chown rtorrent:rtorrent \
399 /data/rutorrent/share/users \
400 /data/rutorrent/share/torrents \
401 /downloads \
402 "${RU_LOG_FILE}"
403 # x rtorrent 0.9.8
404 # /downloads/complete \
405 # /downloads/temp \
406 chown -R rtorrent:rtorrent \
407 /data/geoip \
408 /data/rtorrent/log \
409 /data/rtorrent/.session \
410 /data/rtorrent/watch \
411 /data/rutorrent/conf \
412 /data/rutorrent/plugins \
413 /data/rutorrent/plugins-conf \
414 /data/rutorrent/share \
415 /data/rutorrent/themes \
416 /etc/rtorrent
417 chmod 644 \
418 /data/rtorrent/.rtorrent.rc \
419 /passwd/*.htpasswd \
420 /etc/rtorrent/.rtlocal.rc