-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·78 lines (58 loc) · 2.11 KB
/
run.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
#!/usr/bin/env bash
source static/shell/common.sh
check_for_venv $0
echo "Python3 Virtual Environment active, proceeding..."
PROTOCOL="https"
HOST="127.0.0.1"
PORT=8000
APPLICATION_PATH="webserver.webserver.asgi:application"
OPENER=""
for OPENER_CANDIDATE in "xdg-open" "open"; do
if command -v ${OPENER_CANDIDATE} &> /dev/null; then
OPENER=${OPENER_CANDIDATE}
break
fi
done
function open_browser() {
if [ "${OPENER}" == "" ]; then
echo "'xdg-open' and 'open' could not be found. Please open ${PROTOCOL}://${HOST}:${PORT} in your browser manually."
else
${OPENER} ${PROTOCOL}://${HOST}:${PORT} &
fi
}
cd webserver
if [ ! -d "tls" ]; then
PROTOCOL="http"
echo "tls not found, using HTTP protocol."
fi
cd - &> /dev/null
if ! command -v python3 -m pip show django &> /dev/null; then
echo "django could not be found. Please install it (python3 -m pip install django) before running Web-Agent."
exit
elif ! command -v python3 -m pip show django-extensions &> /dev/null; then
echo "django-extensions could not be found. Please install it (python3 -m pip install django-extensions) before running Web-Agent."
exit
elif ! command -v daphne &> /dev/null; then
echo "daphne could not be found. Please install it (python3 -m pip install daphne) before running Web-Agent."
exit
elif [ ${PROTOCOL} == "https" ]; then
cd webserver/tls
python3 find_key_and_cert.py
cd - &> /dev/null
KEY_PATH="webserver/tls/active/key.pem"
CERT_PATH="webserver/tls/active/cert.pem"
if [ "${1}" == "--launch" ]; then
sleep 2 && open_browser &
fi
if [ ! -f "${KEY_PATH}" ] || [ ! -f "${CERT_PATH}" ]; then
echo "Could not find a valid certificate and key. The content will be served in plain HTTP."
daphne -b ${HOST} -p ${PORT} ${APPLICATION_PATH}
else
daphne -e ssl:${PORT}:privateKey=${KEY_PATH}:certKey=${CERT_PATH} ${APPLICATION_PATH}
fi
elif [ ${PROTOCOL} == "http" ]; then
if [ "${1}" == "--launch" ]; then
sleep 2 && open_browser &
fi
daphne -b ${HOST} -p ${PORT} ${APPLICATION_PATH}
fi