-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·110 lines (86 loc) · 2.67 KB
/
start.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
#!/bin/bash
shopt -s expand_aliases
install_flag='false'
production_flag='false'
# Check to see if python has been set by an environment variable
if [ -n "${python}" ]; then
alias p=${python}
else
# If python is not an environment variable, try to find it in the path
python3_cmd=$(which python3)
python_cmd=$(which python)
if [ -n "$python3_cmd" ]; then
alias p='python3'
elif [ -z "$python3_cmd" ] && [ -n "$python_cmd" ]; then
alias p='python'
else
echo "No python found. Exiting."
exit 1
fi
fi
node_cmd=$(which node)
npm_cmd=$(which npm)
BACKEND_PORT=5000
BACKEND_HOST="0.0.0.0"
FRONTEND_PORT=4200
if [ -z "$node_cmd" ]; then
echo "Node not found. Cannot continue"
exit 1
fi
if [ -z "$npm_cmd" ]; then
echo "Npm not found. Cannot continue"
exit 1
fi
python_version=`p -c "import sys;print('{v[0]}'.format(v=list(sys.version_info[:1])))";`
if [ "$python_version" -lt 3 ]; then
echo "This software requires at least python version 3 to run. Please upgrade as soon as possible"
exit 1
fi
print_usage() {
echo "Arguments: "
echo "-i install all dependencies for front end and backend. Useful if they have not already been installed"
echo "-p Start the REST server but only build the front end for production deployment. Useful if you are deploying to a server and don't need the interactive front end."
echo "-h Get help"
}
cleanup() {
printf "\nKilling python server...\n"
curl http://$BACKEND_HOST:$BACKEND_PORT/stopServer
printf "\nKilling angular instance...\n"
}
while getopts 'ihp' flag; do
case "${flag}" in
i) install_flag='true' ;;
p) production_flag='true' ;;
h) print_usage
exit 1;;
*) print_usage
exit 1 ;;
esac
done
echo "============== Starting InfiniTag =================="
trap cleanup EXIT
if [ "$install_flag" = "true" ]; then
echo "Installing dependencies..."
p -m pip install -r requirements.txt
cd frontend || exit
npm ci
cd ../
echo "Dependencies installed. Continuing..."
fi
echo "Starting REST Server...."
p -u app.py --debug=False --host=$BACKEND_HOST --port=$BACKEND_PORT &
echo "Rest Server running at"
printf "http://$BACKEND_HOST:$BACKEND_PORT\n"
if [ "$production_flag" = "true" ]; then
echo "Building Frontend for production deployment..."
cd frontend || exit
node node_modules/@angular/cli/bin/ng build --prod
cd ../
printf "Front end built and server is running...\n"
read -p 'Press enter to kill the server.'
else
echo "Serving Frontend at: "
echo "http://localhost:$FRONTEND_PORT"
cd frontend || exit
node node_modules/@angular/cli/bin/ng serve --port=$FRONTEND_PORT -o
fi