forked from GovReady/govready-q
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-govready-q.sh
executable file
·163 lines (136 loc) · 3.83 KB
/
install-govready-q.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# this script can be used to quickly set up a new GovReady-Q instance
# for local testing, from a freshly-cloned repository.
# Usage:
# $ ./install-govready-q.sh
# $ ./install-govready-q.sh --non-interactive
# note that this script DOES NOT install libraries from a package manager,
# and does not edit /etc/hosts. those will have to be done manually
# Defaults
##########
# run the script be non-interactively?
# default is yes, run interactively
NONINTERACTIVE=
# some of these commands generate a big wall of text, so we may want visual space
# between them
SPACER="..."
# Parse command-line arguments
##############################
while [ $# -gt 0 ]; do
case "$1" in
--non-interactive)
NONINTERACTIVE=1
shift 1;;
-v)
VERBOSE=1
shift 1;;
--)
shift
break
;;
*)
echo "Unrecognized command line option: $1";
exit 1;
esac
done
# make sure we're not running in an environment with the wrong Python
# command names (Docker, for instance, has python3.6 as the command)
function check_has_command() {
which $1 >/dev/null 2>&1
return $?
}
if check_has_command python3 && check_has_command pip3
then
: # we're good
else
echo "ERROR: The commands 'python3' and 'pip3' are not available.";
exit 1;
fi
# indicate mode
if [ $NONINTERACTIVE ];
then
echo "Installing GovReady-Q in non-interactive mode..."
else
echo "Installing GovReady-Q in interactive mode (default)..."
fi
# install basic requirements either in venv or as the local user
if test -f env/bin/activate
then
source env/bin/activate;
pip3 install -r requirements.txt;
elif [ -v $VIRTUALENV_ENV ]
then
pip3 install -r requirements.txt;
else
pip3 install --user -r requirements.txt;
fi
echo $SPACER
# retrieve static assets
./fetch-vendor-resources.sh
# collect files into static directory
if [ $NONINTERACTIVE ];
then
python3 manage.py collectstatic --no-input
else
python3 manage.py collectstatic
fi
# create the local/environment.json file, if it is missing (it generally will be)
if [ ! -e local/environment.json ];
then
echo "creating DEV environment.json file"
# this is an easy way for us to get a random secret key
SECRET_KEY_LINE="$(python3 manage.py | grep '"secret-key":')"
# need to use a <<- heredoc if we want to have tabs be ignored
cat <<- ENDJSON > local/environment.json
{
"debug": true,
"host": "localhost:8000",
"https": false,
"organization-parent-domain": "localhost",
$SECRET_KEY_LINE
}
ENDJSON
else
echo "environment.json file already exists, proceeding"
fi
# run various DB setup scripts (schema, core data, etc.)
python3 manage.py migrate
python3 manage.py load_modules
echo $SPACER
echo $SPACER
echo $SPACER
if [ $NONINTERACTIVE ];
then
python3 manage.py first_run --non-interactive
else
python3 manage.py first_run
fi
echo $SPACER
# Use jq and cut to extract hostname from govready-url param in local/environment.json
# environment_json=$(<local/environment.json)
govready_url=`cat local/environment.json | jq .\"govready-url\"`
# echo "govready_url is $govready_url"
govready_host_and_port=$(echo $govready_url | cut -f2 -d\" | cut -f3 -d/)
echo "govready_host_and_port is $govready_host_and_port"
if [ $NONINTERACTIVE ];
then
echo ""
echo "*********************************"
echo "* Starting GovReady-Q Server... *"
echo "*********************************"
echo ""
python3 manage.py runserver "$govready_host_and_port"
else
# prompt the user if they want to run the webserver now
# this currently runs synchronously, in the foreground, so it needs to be the last
# functional line of the script
while true;
do
read -p "Do you want to run the GovReady-Q now, in the foreground? [y/n] " answer
case $answer in
[Yy]* ) python3 manage.py runserver "$govready_host_and_port"; break;;
[Nn]* ) break;;
* ) echo "Please answer 'yes' or 'no'";;
esac
done
fi