-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
127 lines (91 loc) · 2.67 KB
/
install.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
#!/usr/bin/bash
SOURCE="/usr/src/muse-for-music"
PACKAGE=muse_for_music
NAME=muse-for-music
PYTHON=/usr/bin/python3
PIP="$PYTHON -m pip"
PIP_VENV="python -m pip"
PIPENV="python -m pipenv"
VENV="virtualenv --python=$PYTHON"
VENV_DIR=/usr/lib/
VENV_FOLDER=muse-for-music
CONFIG_FILE=/etc/${PACKAGE}.conf
LOG_PATH=/var/log/$NAME
HTTP_ROOT=/var/www
WSGI_FILE=${NAME}.wsgi
APACHE_CONFIG=/etc/apache2
#Asset deploy url
#DEPLOY_URL=./assets/
if [ ! -d $VENV_DIR ]; then
mkdir $VENV_DIR
fi
pushd $VENV_DIR
if [ ! -d $VENV_FOLDER ]; then
$VENV $VENV_FOLDER
fi
pushd $VENV_FOLDER
chmod a+x bin/activate*
# Activate venv, everything after is happening in venv!
source bin/activate
# Ensure that pipenv is installed
$PIP_VENV install --upgrade pipenv
popd
popd
pushd $SOURCE
MODE=production
FLASK_APP=$PACKAGE
$PIPENV run build --production --clean-build --unsafe-permissions
$PIPENV run upgrade-db
popd
pushd $HTTP_ROOT
if [ ! -f $WSGI_FILE ]; then
echo "import sys" >> $WSGI_FILE
echo "from os import environ" >> $WSGI_FILE
echo "" >> $WSGI_FILE
echo "activate_this = '$VENV_DIR$VENV_FOLDER/bin/activate_this.py'" >> $WSGI_FILE
echo "with open(activate_this) as file_:" >> $WSGI_FILE
echo " exec(file_.read(), dict(__file__=activate_this))" >> $WSGI_FILE
echo "" >> $WSGI_FILE
echo "sys.path.insert(0, '$SOURCE')" >> $WSGI_FILE
echo "environ['MODE'] = 'production'" >> $WSGI_FILE
echo -n "environ['JWT_SECRET_KEY'] = '" >> $WSGI_FILE
hexdump -n 32 -e '4/4 "%08X" 1 ""' /dev/urandom >> $WSGI_FILE
echo "'" >> $WSGI_FILE
echo "" >> $WSGI_FILE
echo "from $PACKAGE import app as application" >> $WSGI_FILE
echo "" >> $WSGI_FILE
fi
popd
if [ ! -f $CONFIG_FILE ]; then
echo "SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/apache.db'" >> $CONFIG_FILE
echo "LOG_PATH = '$LOG_PATH'" >> $CONFIG_FILE
fi
if [ ! -d $LOG_PATH ]; then
mkdir $LOG_PATH
chmod a+r+w $LOG_PATH
fi
pushd $APACHE_CONFIG
if [ ! -d sites-available ]; then
mkdir sites-available
fi
pushd sites-available
if [ ! -f ${NAME}.conf ]; then
echo "<VirtualHost *>" >> ${NAME}.conf
echo " ServerName example.com" >> ${NAME}.conf
echo " WSGIDaemonProcess $NAME processes=2 threads=15" >> ${NAME}.conf
echo " WSGIProcessGroup $NAME" >> ${NAME}.conf
echo " WSGIScriptAlias / $HTTP_ROOT/$WSGI_FILE" >> ${NAME}.conf
echo " WSGIPassAuthorization on" >> ${NAME}.conf
echo "</VirtualHost>" >> ${NAME}.conf
fi
popd
if [ ! -d sites-enabled ]; then
mkdir sites-enabled
fi
if [ ! -f sites-enabled/${NAME}.conf ]; then
ln -s sites-available/${NAME}.conf sites-enabled/${NAME}.conf
fi
popd
pushd $HTTP_ROOT
touch $WSGI_FILE
popd