-
Notifications
You must be signed in to change notification settings - Fork 2
/
preparation.sh
87 lines (74 loc) · 2.83 KB
/
preparation.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
#! /bin/bash
CUR_PATH=$(pwd)
REPLACEABLE_STATIC_ROOT="$(echo "$CUR_PATH" | sed 's/\//\\\//g')\/static"
REPLACEABLE_ROOT_PATH="$(echo "$CUR_PATH" | sed 's/\//\\\//g')"
# please enter the correct ip address
REPLACEABLE_IP_ADDR="" # please enter the ip address or host url
# please enter the certificate file name for ssl setting
REPLACEABLE_CERTIFICATE=""
REPLACEABLE_CERTIFICATE_KEY=""
# please correct the nginx path if you install nginx in other place.
NGINX_PATH=/etc/nginx/
useEncryption="false"
while getopts ":e" opt
do
case $opt in
e)
useEncryption="true"
;;
?)
echo "unknown parameter"
exit 1;;
esac
done
replace_parameter(){
files=$(ls "$1")
for file in $files
do
if test -d "$1/$file"
then
if [ "$file" != "node_modules" ]
then
replace_parameter "$1/$file"
fi
else
sed -i "s/\[REPLACEABLE_IP_ADDR\]/$REPLACEABLE_IP_ADDR/" "$1/$file"
if [ "$useEncryption" == "true" ]
then
sed -i "s/\[REPLACEABLE_PROTOCOL\]/https/" "$1/$file"
sed -i "s/\[REPLACEABLE_PORT_NUM\]/443/" "$1/$file"
else
sed -i "s/\[REPLACEABLE_PROTOCOL\]/http/" "$1/$file"
sed -i "s/\[REPLACEABLE_PORT_NUM\]/80/" "$1/$file"
fi
sed -i "s/\[REPLACEABLE_ROOT_PATH\]/$REPLACEABLE_ROOT_PATH/" "$1/$file"
sed -i "s/\[REPLACEABLE_STATIC_ROOT\]/$REPLACEABLE_STATIC_ROOT/" "$1/$file"
sed -i "s/\[REPLACEABLE_CERTIFICATE\]/$REPLACEABLE_CERTIFICATE/" "$1/$file"
sed -i "s/\[REPLACEABLE_CERTIFICATE_KEY\]/$REPLACEABLE_CERTIFICATE_KEY/" "$1/$file"
fi
done
}
replace_parameter "$CUR_PATH"
# install dependencies and build the package for react
cd "$CUR_PATH/reactapp" || exit
npm install
npm run build
cd "$CUR_PATH" || exit
# install dependencies for django
pip install -r requirements.txt
# collect static files to target directory
echo yes | python manage.py collectstatic
# create shortcut for nginx config file
if [ "$useEncryption" == "true" ]
then
sudo rm "$NGINX_PATH/sites-available/AWARE-Light-Configurator_nginx"
sudo rm "$NGINX_PATH/sites-enabled/AWARE-Light-Configurator_nginx"
sudo ln -s "$CUR_PATH/util/nginx_config_https" "$NGINX_PATH/sites-available/AWARE-Light-Configurator_nginx"
sudo ln -s "$CUR_PATH/util/nginx_config_https" "$NGINX_PATH/sites-enabled/AWARE-Light-Configurator_nginx"
else
sudo rm "$NGINX_PATH/sites-available/AWARE-Light-Configurator_nginx"
sudo rm "$NGINX_PATH/sites-enabled/AWARE-Light-Configurator_nginx"
sudo ln -s "$CUR_PATH/util/nginx_config_http" "$NGINX_PATH/sites-available/AWARE-Light-Configurator_nginx"
sudo ln -s "$CUR_PATH/util/nginx_config_http" "$NGINX_PATH/sites-enabled/AWARE-Light-Configurator_nginx"
fi
sudo systemctl restart nginx