blob: 6fe3768c220b274f80a3f336a682f510c9cf4132 (
plain)
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
|
#!/bin/bash
DEBUG=false # true
set -e
[ "$DEBUG" == 'true' ] && set -x
if [ -z "$URL" ]; then echo "Error: URL env variable must be set"; exit 1; fi
if [ -z "$RESPONSIBLE_EMAIL" ];
then echo "Error: RESPONSIBLE_EMAIL env variable must be set"; exit 1; fi
echo " * Install dependencies"
APT_OPTIONS=" -y -q "
[ "$DEBUG" == 'true' ] && APT_OPTIONS=""
apt-get install $APT_OPTIONS git nginx uwsgi uwsgi-plugin-python3 postgresql apg sed gettext > /dev/null
apt-get install $APT_OPTIONS python3 python3-pip python3-psycopg2 python3-pygments > /dev/null
apt-get install $APT_OPTIONS -t stretch-backports python3-django > /dev/null
# buster: apt install python3-django
pip3 install scrapy==1.7 tldextract==2.2 django-ajax-selects==1.6.0 > /dev/null
# buster: apt install python3-tldextract django-ajax-selects
# bullseye: apt install python3-scrapy python3-tldextract django-ajax-selects
PASSWORD=`apg -n 1 -a 1 -m 24 -M CLN`
PWD=`pwd`
DB_NAME=commonnet
echo " * Creating conf files"
mkdir -p /var/log/django/
mkdir -p /var/lib/uwsgi/run
chown -R www-data:www-data /var/lib/uwsgi/run
chown -R www-data:www-data /var/log/django/
sed -s "s|#URL#|$URL|g;s|#PASSWORD#|$PASSWORD|g;\
s|RESPONSIBLE_EMAIL = None|RESPONSIBLE_EMAIL = '$RESPONSIBLE_EMAIL'|;" \
commonnet/local_settings.py.sample > conf/local_settings.py
rm -f commonnet/local_settings.py
ln -s "$PWD"/conf/local_settings.py commonnet/
sed -s "s|#URL#|$URL|g;" conf/uwsgi.ini.template > \
conf/uwsgi.ini
rm -f /etc/uwsgi/apps-enabled/commonnet.ini
ln -s "$PWD"/conf/uwsgi.ini /etc/uwsgi/apps-enabled/commonnet.ini
sed -s "s|#URL#|$URL|g;" conf/nginx.conf.template > \
conf/nginx.conf
rm -f /etc/nginx/sites-enabled/commonnet.conf
ln -s "$PWD"/conf/nginx.conf /etc/nginx/sites-enabled/commonnet.conf
echo " * Creating database $DB_NAME"
if ! su postgres -c "psql -l" | grep -qs "$DB_NAME"; then
su postgres -c "createuser --echo --adduser --createdb --encrypted $DB_NAME"
echo "ALTER USER \""$DB_NAME"\" with password '"$PASSWORD"';" > /tmp/inst.sql
su postgres -c "psql -f /tmp/inst.sql"
rm /tmp/inst.sql
su postgres -c "createdb --echo --owner $DB_NAME --encoding UNICODE $DB_NAME"
else
echo "Error: commonnet database already present. Exiting..."
exit 1
fi
make update
echo " * create super user"
python3 manage.py createsuperuser
systemctl restart uwsgi nginx
|