forked from crazy-max/docker-qbittorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
107 lines (96 loc) · 4.09 KB
/
entrypoint.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
#!/bin/sh
WAN_IP=${WAN_IP:-$(dig +short myip.opendns.com @resolver1.opendns.com)}
echo "WAN IP address is ${WAN_IP}"
if [ -n "${PGID}" ] && [ "${PGID}" != "$(id -g qbittorrent)" ]; then
echo "Switching to PGID ${PGID}..."
sed -i -e "s/^qbittorrent:\([^:]*\):[0-9]*/qbittorrent:\1:${PGID}/" /etc/group
sed -i -e "s/^qbittorrent:\([^:]*\):\([0-9]*\):[0-9]*/qbittorrent:\1:\2:${PGID}/" /etc/passwd
fi
if [ -n "${PUID}" ] && [ "${PUID}" != "$(id -u qbittorrent)" ]; then
echo "Switching to PUID ${PUID}..."
sed -i -e "s/^qbittorrent:\([^:]*\):[0-9]*:\([0-9]*\)/qbittorrent:\1:${PUID}:\2/" /etc/passwd
fi
WEBUI_PORT=${WEBUI_PORT:-8080}
ALT_WEBUI=${ALT_WEBUI:-false}
if [ "${ALT_WEBUI}" != "true" ]; then
ALT_WEBUI=false
fi
echo "Creating folders..."
mkdir -p /data/config \
/data/data \
/data/downloads \
/data/temp \
/data/torrents \
/data/watch \
/data/webui \
${QBITTORRENT_HOME}/.config \
${QBITTORRENT_HOME}/.local/share \
/var/log/qbittorrent
if [ ! -e "${QBITTORRENT_HOME}/.config/qBittorrent" ]; then
ln -s /data/config "${QBITTORRENT_HOME}/.config/qBittorrent"
fi
if [ ! -e "${QBITTORRENT_HOME}/.local/share/qBittorrent" ]; then
ln -s /data/data "${QBITTORRENT_HOME}/.local/share/qBittorrent"
fi
# https://github.com/qbittorrent/qBittorrent/blob/master/src/base/settingsstorage.cpp
if [ ! -f /data/config/qBittorrent.conf ]; then
echo "Initializing qBittorrent configuration..."
cat > /data/config/qBittorrent.conf <<EOL
[General]
ported_to_new_savepath_system=true
[Application]
FileLogger\Enabled=true
FileLogger\Path=/var/log/qbittorrent
[LegalNotice]
Accepted=true
[Preferences]
Bittorrent\AddTrackers=false
Connection\InetAddress=${WAN_IP}
Connection\InterfaceListenIPv6=false
Connection\PortRangeMin=6881
Connection\UseUPnP=false
Downloads\PreAllocation=true
Downloads\SavePath=/data/downloads
Downloads\StartInPause=false
Downloads\TempPath=/data/temp
Downloads\TempPathEnabled=true
Downloads\FinishedTorrentExportDir=/data/torrents
General\Locale=en
General\UseRandomPort=false
WebUI\Enabled=true
WebUI\HTTPS\Enabled=false
WebUI\Address=0.0.0.0
WebUI\Port=${WEBUI_PORT}
WebUI\LocalHostAuth=false
WebUI\AlternativeUIEnabled=${ALT_WEBUI}
WebUI\RootFolder=/data/webui
EOL
fi
echo "Overriding required parameters..."
sed -i "s!ported_to_new_savepath_system.*!ported_to_new_savepath_system=true!g" /data/config/qBittorrent.conf
sed -i "s!FileLogger\\\Enabled=.*!FileLogger\\\Enabled=true!g" /data/config/qBittorrent.conf
sed -i "s!FileLogger\\\Path=.*!FileLogger\\\Path=/var/log/qbittorrent!g" /data/config/qBittorrent.conf
sed -i "s!Connection\\\InetAddress=.*!Connection\\\InetAddress=${WAN_IP}!g" /data/config/qBittorrent.conf
sed -i "s!Connection\\\InterfaceListenIPv6=.*!Connection\\\InterfaceListenIPv6=false!g" /data/config/qBittorrent.conf
sed -i "s!Connection\\\UseUPnP=.*!Connection\\\UseUPnP=false!g" /data/config/qBittorrent.conf
sed -i "s!Connection\\\InetAddress=.*!Connection\\\InetAddress=${WAN_IP}!g" /data/config/qBittorrent.conf
sed -i "s!Downloads\\\SavePath=.*!Downloads\\\SavePath=/data/downloads!g" /data/config/qBittorrent.conf
sed -i "s!Downloads\\\TempPath=.*!Downloads\\\TempPath=/data/temp!g" /data/config/qBittorrent.conf
sed -i "s!Downloads\\\TempPathEnabled=.*!Downloads\\\TempPathEnabled=true!g" /data/config/qBittorrent.conf
sed -i "s!Downloads\\\FinishedTorrentExportDir=.*!Downloads\\\FinishedTorrentExportDir=/data/torrents!g" /data/config/qBittorrent.conf
sed -i "s!WebUI\\\Enabled=.*!WebUI\\\Enabled=true!g" /data/config/qBittorrent.conf
sed -i "s!WebUI\\\Address=.*!WebUI\\\Address=0\.0\.0\.0!g" /data/config/qBittorrent.conf
sed -i "s!WebUI\\\Port=.*!WebUI\\\Port=${WEBUI_PORT}!g" /data/config/qBittorrent.conf
sed -i "s!WebUI\\\LocalHostAuth=.*!WebUI\\\LocalHostAuth=false!g" /data/config/qBittorrent.conf
sed -i "s!WebUI\\\RootFolder=.*!WebUI\\\RootFolder=/data/webui!g" /data/config/qBittorrent.conf
echo "Fixing perms..."
chown qbittorrent:qbittorrent /data \
/data/config \
/data/data \
/data/downloads \
/data/temp \
/data/torrents \
/data/watch \
/data/webui
chown -R qbittorrent:qbittorrent "${QBITTORRENT_HOME}" /var/log/qbittorrent
exec yasu qbittorrent:qbittorrent "$@"