-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_genocrowd.sh
executable file
·94 lines (78 loc) · 2.21 KB
/
run_genocrowd.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
#! /bin/bash
# Paths
dir_genocrowd=$(dirname "$0")
dir_venv="$dir_genocrowd/venv"
dir_node_modules="$dir_genocrowd/node_modules"
activate="$dir_venv/bin/activate"
error=0
function usage() {
echo "Usage: $0 (-d { dev | prod })"
echo " -d deployment mode (default: production)"
}
while getopts "hd:" option; do
case $option in
h)
usage
exit 0
;;
d)
depmode=$OPTARG
;;
esac
done
case $depmode in
prod|production|"")
flask_depmod="production"
flask_command="gunicorn -b 0.0.0.0:5000 app"
;;
dev|development)
flask_depmod="development"
flask_command="flask run --host=0.0.0.0"
npm run dev &
;;
*)
echo "-d $depmode: wrong deployment mode"
usage
exit 1
esac
# Exports
export FLASK_ENV=$flask_depmod
export FLASK_APP="app"
echo "Removing python cache ..."
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
if [[ -f $activate ]]; then
echo "Sourcing Python virtual environment ..."
source ${dir_venv}/bin/activate
else
echo "No virtual environment found. Run install.sh first."
error=1
fi
if [[ ! -d $dir_node_modules ]]; then
echo "No node_modules directory found. Run install.sh first."
error=1
fi
if [[ ! -f $dir_genocrowd/genocrowd/static/js/genocrowd.js ]]; then
echo "Javascript not built. Run build.sh first."
error=1
fi
if [[ $error > 0 ]]; then
exit 1
fi
# Create config file
config_template_path="$dir_genocrowd/config/genocrowd.ini.template"
config_path="$dir_genocrowd/config/genocrowd.ini"
if [[ ! -f $config_path ]]; then
cp $config_template_path $config_path
fi
# Convert env to ini entry
printenv | egrep "GENOCROWD_" | while read setting
do
section=$(echo $setting | egrep -o "^GENOCROWD[^=]+" | sed 's/^.\{5\}//g' | cut -d "_" -f 1)
key=$(echo $setting | egrep -o "^GENOCROWD[^=]+" | sed 's/^.\{5\}//g' | sed "s/$section\_//g")
value=$(echo $setting | egrep -o "=.*$" | sed 's/^=//g')
# crudini --set ${config_path} "${section}" "${key}" "${value}"
python3 config_updater.py -p $config_path -s "${section}" -k "${key}" -v "${value}"
$cmd
done
echo "Starting genocrowd ..."
$flask_command