-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·119 lines (91 loc) · 2.74 KB
/
install
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
#!/bin/bash
# +--------------------------------------------------------------------------+ #
# | | #
# | --- Install Script --- | #
# | | #
# +--------------------------------------------------------------------------+ #
#
# --- Setup ---
#
NAME=total-tolles-ferleihsystem
PACKAGE=total_tolles_ferleihsystem
PYTHON=/usr/bin/python3
VENV="virtualenv --python=$PYTHON"
PIP_VENV="python -m pip"
NPM_BUILD_SCRIPT=production-build
LIB_PATH=/usr/lib/$NAME
LOG_PATH=/var/log/$NAME
CONFIG_FILE=/etc/$NAME.conf
WSGI_FILE=/var/www/$NAME.wsgi
APACHE_CONFIG_FILE=/etc/apache2/sites-available/$NAME.conf
#
# --- Setup venv and activate it ---
#
# setup venv
if [ ! -d $LIB_PATH ]; then
$VENV $LIB_PATH
fi
# activate venv
source $LIB_PATH/bin/activate
# install the ttf software and it's requirements into the venv
$PIP_VENV install -r requirements.txt
$PIP_VENV install -e .
#
# --- Create all other files and folders ---
#
# create log folder
mkdir -p $LOG_PATH
# create wsgi file
if [ ! -f $WSGI_FILE ]; then
echo "[INFO] Create WSGI file: $WSGI_FILE"
cat > $WSGI_FILE << EOF
import sys
from os import environ
activate_this = '$LIB_PATH/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
sys.path.insert(0, '$PWD')
environ['MODE'] = 'production'
environ['JWT_SECRET_KEY'] = '$(hexdump -n 32 -e '4/4 "%08X" 1 ""' /dev/urandom)'
from $PACKAGE import APP as application
EOF
else
echo "[WARN] Can't create WSGI file: $WSGI_FILE; It already exists!"
fi
# create the ttf config file
if [ ! -f $CONFIG_FILE ]; then
echo "[INFO] Create config file: $CONFIG_FILE"
cat > $CONFIG_FILE << EOF
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/apache.db'
CELERY_BROKER_URL = 'amqp://localhost'
CELERY_RESULT_BACKEND = 'rpc://'
LOG_PATH = '$LOG_PATH'
EOF
else
echo "[WARN] Can't create config file: $CONFIG_FILE; It already exists!"
fi
# create the apache configuration file and activate it
if [ ! -f $APACHE_CONFIG_FILE ]; then
echo "[INFO] Create apache2 config file: $APACHE_CONFIG_FILE"
cat > $APACHE_CONFIG_FILE << EOF
<VirtualHost *:80>
ServerName example.com
WSGIDaemonProcess $NAME processes=2 threads=15
WSGIProcessGroup $NAME
WSGIScriptAlias / $WSGI_FILE
WSGIPassAuthorization on
</VirtualHost>
EOF
a2ensite $NAME
else
echo "[WARN] Can't create apache2 config file: $APACHE_CONFIG_FILE; It already exists!"
fi
#
# --- Cleanup / Reload ---
#
# run db migrations
MODE=production FLASK_APP=$PACKAGE flask db upgrade
# deactivate venv
deactivate
# reload apache
service apache2 reload