/
setup_nyaa.sh
executable file
·51 lines (44 loc) · 2.08 KB
/
setup_nyaa.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
#!/bin/bash
#
# Configuration modifier for the nyaa.si docker image.
#
# Variables:
#
# MYSQL_HOST: Defines the host/server for the database instance. Fallback to SQLite if not defined.
# MYSQL_DATABASE: Defines the database name used
# MYSQL_USER: Defines the user having access to the said database.
# MYSQL_PASS: Defines the MYSQL_USER password to be used.
# SITE_FLAVOR: Defines the variant of the website. (nyaa or sukebei)
# Note: MYSQL_USER and MYSQL_PASS can be left blank if desired but they depend on MYSQL_HOST being defined.
#
# Other Note: Ensure that the database container is accessible first before modifying any of these.
if [ ! -f .database_created ] ; then
# Copy the config
cp config.example.py config.py
# Set the database information as defined by the user
if [ -n "$MYSQL_HOST" ] ; then
if [[ -n "$MYSQL_USER" && -n "$MYSQL_PASS" ]] ; then
sed -i "/mysql:\/\/test:test123@localhost\/nyaav2?charset=utf8mb4/ s/test:test123@localhost/$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST/g" config.py
elif [ -n "$MYSQL_USER" ] ; then
sed -i "/mysql:\/\/test:test123@localhost\/nyaav2?charset=utf8mb4/ s/test:test123@localhost/$MYSQL_USER:test123@$MYSQL_HOST/g" config.py
elif [ -n "$MYSQL_PASS" ] ; then
sed -i "/mysql:\/\/test:test123@localhost\/nyaav2?charset=utf8mb4/ s/test:test123@localhost/test:$MYSQL_PASS@$MYSQL_HOST/g" config.py
else
sed -i "/mysql:\/\/test:test123@localhost\/nyaav2?charset=utf8mb4/ s/test:test123@localhost/test:test123@$MYSQL_HOST/g" config.py
fi
if [ -n "$MYSQL_DATABASE" ] ; then
sed -i "/?charset=utf8mb4/ s/nyaav2/$MYSQL_DATABASE/g" config.py
fi
else
# Fallback to sqlite even though it is not really recommended...
sed -i '/USE_MYSQL/ s/True/False/g' config.py
fi
# Only modify the flavor if the user set sukebei
if [ "$SITE_FLAVOR" = "sukebei" ] ; then
sed -i "/SITE_FLAVOR/ s/'nyaa'/'sukebei'/1" config.py
fi
touch .database_created
python db_create.py
python db_migrate.py stamp head
fi
python run.py