-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathseedbox.sh
executable file
·365 lines (322 loc) · 10.5 KB
/
seedbox.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/bin/bash
#####################################
# TEST ROOT USER
if [ "$USER" != "root" ]; then
echo "Ce script doit être lancé par root"
exit 1
fi
# Absolute path to this script.
CURRENT_SCRIPT=$(readlink -f "$0")
# Absolute path this script is in.
SCRIPTPATH=$(dirname "$CURRENT_SCRIPT")
# shellcheck source=/opt/seedbox-compose/includes/functions.sh
source "${SCRIPTPATH}/includes/functions.sh"
# shellcheck source=/opt/seedbox-compose/includes/variables.sh
source "${SCRIPTPATH}/includes/variables.sh"
clear
echo "################################################"
echo "# ATTENTION "
echo "# ce script n'est plus maintenu "
echo "# Merci soit d'installer la v2 "
echo "# soit de faire la migration "
echo " ================================================"
echo " https://github.com/projetssd/ssdv2 "
echo "################################################"
pause
clear
if [[ ! -d "$CONFDIR" ]]; then
echo -e "${CCYAN}
___ ____ ____ ____ ____ _____ _ _
/ __)( ___)( _ \( _ \( _ \( _ )( \/ )
\__ \ )__) )(_) ))(_) )) _ < )(_)( ) (
(___/(____)(____/(____/(____/(_____)(_/\_)
${CEND}"
echo ""
echo -e "${CCYAN}---------------------------------${CEND}"
echo -e "${CCYAN}[ INSTALLATION DES PRÉ-REQUIS ]${CEND}"
echo -e "${CCYAN}---------------------------------${CEND}"
echo ""
echo -e "\n${CGREEN}Appuyer sur ${CEND}${CCYAN}[ENTREE]${CEND}${CGREEN} pour lancer le script${CEND}"
read -r
## Constants
readonly PIP="9.0.3"
readonly ANSIBLE="2.5.14"
## Environmental Variables
export DEBIAN_FRONTEND=noninteractive
## Disable IPv6
if [ -f /etc/sysctl.d/99-sysctl.conf ]; then
grep -q -F 'net.ipv6.conf.all.disable_ipv6 = 1' /etc/sysctl.d/99-sysctl.conf ||
echo 'net.ipv6.conf.all.disable_ipv6 = 1' >>/etc/sysctl.d/99-sysctl.conf
grep -q -F 'net.ipv6.conf.default.disable_ipv6 = 1' /etc/sysctl.d/99-sysctl.conf ||
echo 'net.ipv6.conf.default.disable_ipv6 = 1' >>/etc/sysctl.d/99-sysctl.conf
grep -q -F 'net.ipv6.conf.lo.disable_ipv6 = 1' /etc/sysctl.d/99-sysctl.conf ||
echo 'net.ipv6.conf.lo.disable_ipv6 = 1' >>/etc/sysctl.d/99-sysctl.conf
sysctl -p
fi
## Install Pre-Dependencies
apt-get install -y --reinstall \
software-properties-common \
apt-transport-https \
lsb-release
apt-get update
## Add apt repos
osname=$(lsb_release -si)
if echo "$osname" "Debian" &>/dev/null; then
{
add-apt-repository main
add-apt-repository non-free
add-apt-repository contrib
} >>/dev/null 2>&1
elif echo "$osname" "Ubuntu" &>/dev/null; then
{
add-apt-repository main
add-apt-repository universe
add-apt-repository restricted
add-apt-repository multiverse
} >>/dev/null 2>&1
fi
apt-get update
## Install apt Dependencies
apt-get install -y --reinstall \
nano \
git \
build-essential \
libssl-dev \
libffi-dev \
python3-dev \
python3-pip \
python-dev \
python-pip \
python-apt
## Install pip3 Dependencies
python3 -m pip install --disable-pip-version-check --upgrade --force-reinstall \
pip==${PIP}
python3 -m pip install --disable-pip-version-check --upgrade --force-reinstall \
setuptools
python3 -m pip install --disable-pip-version-check --upgrade --force-reinstall \
pyOpenSSL \
requests \
netaddr
## Install pip2 Dependencies
python -m pip install --disable-pip-version-check --upgrade --force-reinstall \
pip==${PIP}
python -m pip install --disable-pip-version-check --upgrade --force-reinstall \
setuptools
python -m pip install --disable-pip-version-check --upgrade --force-reinstall \
pyOpenSSL \
requests \
netaddr \
jmespath \
ansible==${1-$ANSIBLE}
# Configuration ansible
mkdir -p /etc/ansible/inventories/ 1>/dev/null 2>&1
cat <<EOF >/etc/ansible/inventories/local
[local]
127.0.0.1 ansible_connection=local
EOF
cat <<EOF >/etc/ansible/ansible.cfg
[defaults]
command_warnings = False
callback_whitelist = profile_tasks
deprecation_warnings=False
inventory = /etc/ansible/inventories/local
interpreter_python=/usr/bin/python
EOF
## Copy pip to /usr/bin
cp /usr/local/bin/pip /usr/bin/pip
cp /usr/local/bin/pip3 /usr/bin/pip3
pip uninstall -y cryptography
clear
logo
echo -e "${CCYAN}INSTALLATION SEEDBOX DOCKER${CEND}"
echo -e "${CGREEN}${CEND}"
echo -e "${CGREEN} 1) Installation Seedbox rclone && gdrive${CEND}"
echo -e "${CGREEN} 2) Installation Seedbox Classique ${CEND}"
echo -e "${CGREEN} 3) Restauration Seedbox${CEND}"
echo -e ""
read -p "Votre choix [1-3]: " CHOICE
echo ""
case $CHOICE in
1) ## Installation de la seedbox Plexdrive
check_dir "$PWD"
if [[ ! -d "$CONFDIR" ]]; then
clear
conf_dir
update_system
install_base_packages
install_docker
define_parameters
cloudflare
oauth
install_traefik
install_rclone
install_watchtower
install_fail2ban
choose_media_folder_plexdrive
unionfs_fuse
pause
choose_services
subdomain
install_services
for i in $(docker ps --format "{{.Names}}")
do
if [[ "$i" == "plex" ]]; then
plex_sections
fi
done
projects
filebot
sauve
resume_seedbox
pause
ansible-vault encrypt /opt/seedbox/variables/account.yml >/dev/null 2>&1
script_plexdrive
else
script_plexdrive
fi
;;
2) ## Installation de la seedbox classique
check_dir "$PWD"
if [[ ! -d "$CONFDIR" ]]; then
clear
conf_dir
update_system
install_base_packages
install_docker
define_parameters
cloudflare
oauth
install_traefik
install_watchtower
install_fail2ban
choose_media_folder_classique
choose_services
subdomain
install_services
filebot
resume_seedbox
pause
ansible-vault encrypt /opt/seedbox/variables/account.yml >/dev/null 2>&1
touch "/opt/seedbox/media-$SEEDUSER"
script_classique
else
script_classique
fi
;;
3) ## restauration de la seedbox
check_dir "$PWD"
if [[ ! -d "$CONFDIR" ]]; then
clear
echo ""
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo -e "${CRED} /!\ ATTENTION : PREPARATION DE LA RESTAURATION DU SERVEUR /!\ ${CEND}"
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo ""
conf_dir
update_system
install_base_packages
install_docker
define_parameters
install_rclone
install_fail2ban
sauve
restore
choose_media_folder_plexdrive
rm /etc/systemd/system/mergerfs.service >/dev/null 2>&1
unionfs_fuse
cloudflare
install_traefik
install_watchtower
SERVICESPERUSER="$SERVICESUSER$SEEDUSER"
while read line; do echo $line | cut -d'.' -f1; done <"/home/$SEEDUSER/resume" >"$SERVICESUSER$SEEDUSER"
rm "/home/$SEEDUSER/resume"
install_services
## restauration plex_dupefinder
PLEXDUPE=/home/$SEEDUSER/scripts/plex_dupefinder/plex_dupefinder.py
if [[ -e "$PLEXDUPE" ]]; then
cd "/home/$SEEDUSER/scripts/plex_dupefinder"
python3 -m pip install -r requirements.txt
fi
## restauration cloudplow
CLOUDPLOWSERVICE=/etc/systemd/system/cloudplow.service
if [[ -e "$CLOUDPLOWSERVICE" ]]; then
cd "/home/$SEEDUSER/scripts/cloudplow"
python3 -m pip install -r requirements.txt
ln -s /home/$SEEDUSER/scripts/cloudplow/cloudplow.py /usr/local/bin/cloudplow
systemctl start cloudplow.service
fi
## restauration plex_autoscan
PLEXSCANSERVICE=/etc/systemd/system/plex_autoscan.service
if [[ -e "$PLEXSCANSERVICE" ]]; then
cd "/home/$SEEDUSER/scripts/plex_autoscan"
python -m pip install -r requirements.txt
systemctl start plex_autoscan.service
fi
## restauration des crons
(
crontab -l | grep .
echo "*/1 * * * * /opt/seedbox/docker/$SEEDUSER/.filebot/filebot-process.sh"
) | crontab -
ln -s "/home/$SEEDUSER/scripts/plex_dupefinder/plex_dupefinder.py" /usr/local/bin/plexdupes
rm $SERVICESUSER$SEEDUSER
checking_errors $?
echo ""
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo -e "${CRED} /!\ RESTAURATION DU SERVEUR EFFECTUEE AVEC SUCCES /!\ ${CEND}"
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo ""
pause
ansible-vault encrypt /opt/seedbox/variables/account.yml >/dev/null 2>&1
script_plexdrive
else
script_plexdrive
fi
;;
999) ## Installation seedbox webui
mkdir -p /opt/seedbox/variables
/opt/seedbox-compose/includes/config/scripts/add_user.sh
echo ""
status
update_system
install_base_packages
install_docker
ansible-playbook /opt/seedbox-compose/includes/config/roles/nginx/tasks/main.yml
install_traefik
DOMAIN=$(grep domain /opt/seedbox/variables/account.yml | cut -d ':' -f2 | tr -d ' ')
grep "gui" /opt/seedbox/variables/account.yml > /dev/null 2>&1
if [ $? -eq 0 ]; then
SUBDOMAIN=$(grep gui /opt/seedbox/variables/account.yml | cut -d ':' -f2 | tr -d ' ')
else
SUBDOMAIN="gui"
fi
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo -e "${CRED} /!\ INSTALLATION EFFECTUEE AVEC SUCCES /!\ ${CEND}"
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo ""
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo -e "${CCYAN} Adresse de l'interface WebUI ${CEND}"
echo -e "${CCYAN} https://${SUBDOMAIN}.${DOMAIN} ${CEND}"
echo -e "${CRED}---------------------------------------------------------------${CEND}"
echo ""
ansible-vault encrypt /opt/seedbox/variables/account.yml > /dev/null 2>&1
echo -e "\nAppuyer sur ${CCYAN}[ENTREE]${CEND} pour sortir du script..."
read -r
exit 1
;;
esac
fi
status
if [ ! -d "/opt/seedbox/status" ]
then
mkdir -p /opt/seedbox/status
fi
for i in $(docker ps --format "{{.Names}}" --filter "network=traefik_proxy")
do
echo "2" > /opt/seedbox/status/${i}
done
PLEXDRIVE="/usr/bin/rclone"
if [[ -e "$PLEXDRIVE" ]]; then
script_plexdrive
else
script_classique
fi