forked from ISIFoundation/influenzanet-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·270 lines (234 loc) · 10.8 KB
/
bootstrap.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
#
# Bootstraps everything installing Django and all required eggs, configuring
# the database and making sure a consistent development environment is
# installed.
# Here we customize src/epiweb/settings.py by setting the user preferred
# database, language and country. Note that the database and the user used
# to connect should already exist.
DB_ENGINE=""
DB_NAME=""
DB_HOST=""
DB_PORT=""
DB_USERNAME=""
DB_PASSWORD=""
DJANGO_ENGINE="unconfigured"
TIMEZONE=""
LANGUAGE=""
COUNTRY=""
echo ""
echo -n "Checking for pre-requisites: python ... "
exe_python="$(which python)"
if [ -n "$exe_python" ] ; then
echo "$exe_python"
else
echo "no found; place make sure Python 2.7 is installed"
echo ""
exit 1
fi
echo ""
echo -n "Checking for pre-requisites: easy_install ... "
exe_easy_install="$(which easy_install)"
if [ -n "$exe_easy_install" ] ; then
echo "$exe_easy_install"
else
echo "no found; place make sure setuptools are installed"
echo ""
exit 1
fi
echo ""
echo -n "Checking for pre-requisites: pip ... "
exe_pip="$(which pip)"
if [ -n "$exe_pip" ] ; then
echo "$exe_pip"
else
echo "no found; place make sure pip is installed (sudo easy_install pip)"
echo ""
exit 1
fi
echo ""
echo -n "Checking for pre-requisites: virtualenv ... "
exe_virtualenv="$(which virtualenv)"
if [ -n "$exe_virtualenv" ] ; then
echo "$exe_virtualenv"
else
echo "no found; place make sure virtualenv is installed (sudo pip install --upgrade virtualenv)"
echo ""
exit 1
fi
echo -n "Checking for pre-requisites: psql ... "
exe_psql="$(which psql)"
if [ -n "$exe_psql" ] ; then
echo "$exe_psql"
else
echo "not found; automatic PostgreSQL configuration disabled"
fi
# Can we keep access to mapnik module and still use --no-site-packages?
# virtualenv --no-site-packages .
virtualenv .
source ./bin/activate
pip install -r requirements.txt
if [ -n "$exe_psql" ] ; then
pip install psycopg2
fi
echo ""
while [ -z "$LANGUAGE" ] ; do
echo -n "Please, choose your country and language (be, it, nl, uk, pt, se, da, es): "
read line && [ -n "$line" ] && LANGUAGE="$line";
COUNTRY="$LANGUAGE"
done
while [ -z "$TIMEZONE" ] ; do
test -f /etc/timezone && TIMEZONE="$(cat /etc/timezone)"
echo -n "Please, enter your time zone (default is $TIMEZONE): "
read line && [ -n "$line" ] && TIMEZONE="$line";
done
DB_ENGINE="postgresql"
if [ "$DB_ENGINE" = "postgresql" ] ; then
echo ""
echo -n "Database host (just hit enter if on localhost/same host): "
read line && [ -n "$line" ] && DB_HOST="$line";
echo -n "Database port (just hit enter if using default port): "
read line && [ -n "$line" ] && DB_PORT="$line";
while [ -z "$DB_NAME" ] ; do
echo -n "Database name (database will be created if necessary; default is epiwork): "
read line && DB_NAME="${line:-epiwork}";
done
while [ -z "$DB_USERNAME" ] ; do
echo -n "Database username (user will be created if necessary; default is epiwork): "
read line && DB_USERNAME="${line:-epiwork}";
done
while [ -z "$DB_PASSWORD" ] ; do
echo -n "Database password: "
read line && [ -n "$line" ] && DB_PASSWORD="$line";
done
DJANGO_ENGINE="postgresql_psycopg2"
if [ -n "$exe_psql" ] ; then
echo ""
echo "Note: the following data will NOT be saved, but it is necessary to create"
echo "the database '$DB_NAME' and the user '$DB_USERNAME' that will be used to"
echo "connect to database for normal operation."
echo ""
echo -n "Please, insert PostgrSQL administrator's username (default is postgres): "
read line
root_username="${line:-postgres}"
fi
fi
echo ""
echo "Configuration parameters:"
echo ""
echo " country and language: $LANGUAGE"
echo " time zone: $TIMEZONE"
echo " database engine: $DB_ENGINE ($DJANGO_ENGINE)"
echo " database name: $DB_NAME"
echo " database host: ${DB_HOST:-localhost}"
echo " database port: ${DB_PORT:-(default)}"
echo " database username: $DB_USERNAME"
echo " database password: $DB_PASSWORD"
echo ""
echo "We are about to generate a new Django configuration and to create a new"
echo "database. This will destroy your previous configuration and make you lose"
echo "all you data. Make sure all parameters are correct before proceeding."
echo ""
echo -n "Please, type YES if you want to preceed or ABORT to exit now: "
line=""
while [ -z "$line" ] ; do
read line
if [ "$line" = "ABORT" ] ; then exit 0 ; fi
if [ "$line" != "YES" ] ; then line="" ; fi
done
echo ""
if [ "$DB_ENGINE" = "postgresql" -a -n "$exe_psql" ] ; then
echo "Creating database $DB_NAME ... "
args="--username=$root_username template1"
if [ -n "$DB_PORT" ] ; then
args="--port=$DB_PORT $args"
fi
if [ -n "$DB_HOST" ] ; then
args="--host=$DB_HOST $args"
fi
psql -q $args <<EOF
DROP DATABASE IF EXISTS $DB_NAME ;
DROP USER IF EXISTS $DB_USERNAME ;
CREATE USER $DB_USERNAME WITH ENCRYPTED PASSWORD '$DB_PASSWORD' ;
CREATE DATABASE $DB_NAME WITH OWNER = $DB_USERNAME ;
EOF
echo "PostgreSQL setup complete"
fi
echo ""
echo -n "Generating settings.py ... "
cat local_settings.py.in \
| sed -e "s/@DB_ENGINE@/django.db.backends.$DJANGO_ENGINE/g" \
| sed -e "s/@DB_NAME@/$DB_NAME/g" \
| sed -e "s/@DB_HOST@/$DB_HOST/g" \
| sed -e "s/@DB_PORT@/$DB_PORT/g" \
| sed -e "s/@DB_USERNAME@/$DB_USERNAME/g" \
| sed -e "s/@DB_PASSWORD@/$DB_PASSWORD/g" \
| sed -e "s/@LANGUAGE@/$LANGUAGE/g" \
| sed -e "s/@COUNTRY@/$COUNTRY/g" \
| sed -e "s%@TIMEZONE@%$TIMEZONE%g" \
> local_settings.py
echo "done"
echo ""
echo "Initializing Django database and loading default surveys:"
echo ""
python manage.py syncdb
# On PostgreSQL ovverride the order of migrated tables creating first
# referenced tables (journal migration fails if CMS isn't available.)
python manage.py migrate cms
python manage.py migrate
python manage.py rule_type_register --title 'Show Question' --jsclass 'wok.pollster.rules.ShowQuestion'
python manage.py rule_type_register --title 'Hide Question' --jsclass 'wok.pollster.rules.HideQuestion'
python manage.py rule_type_register --title 'Show Options' --jsclass 'wok.pollster.rules.ShowOptions'
python manage.py rule_type_register --title 'Hide Options' --jsclass 'wok.pollster.rules.HideOptions'
python manage.py rule_type_register --title 'Check Options' --jsclass 'wok.pollster.rules.CheckOptions'
python manage.py rule_type_register --title 'Uncheck Options' --jsclass 'wok.pollster.rules.UncheckOptions'
python manage.py rule_type_register --title 'Exclusive' --jsclass 'wok.pollster.rules.Exclusive'
python manage.py rule_type_register --title 'Future Fill' --jsclass 'wok.pollster.rules.FutureFill'
python manage.py rule_type_register --title 'Future Show Question' --jsclass 'wok.pollster.rules.FutureShowQuestion'
python manage.py rule_type_register --title 'Future Hide Question' --jsclass 'wok.pollster.rules.FutureHideQuestion'
python manage.py rule_type_register --title 'Future Show Options' --jsclass 'wok.pollster.rules.FutureShowOptions'
python manage.py rule_type_register --title 'Future Hide Options' --jsclass 'wok.pollster.rules.FutureHideOptions'
python manage.py rule_type_register --title 'Fill' --jsclass 'wok.pollster.rules.Fill'
python manage.py question_data_type_register --title 'Text' --dbtype 'django.db.models.TextField(null=True, blank=True)' --cssclass 'text-type' --jsclass 'wok.pollster.datatypes.Text'
python manage.py question_data_type_register --title 'Numeric' --dbtype 'django.db.models.PositiveIntegerField(null=True, blank=True)' --cssclass 'numeric-type' --jsclass 'wok.pollster.datatypes.Numeric'
python manage.py question_data_type_register --title 'Date' --dbtype 'django.db.models.DateField(null=True, blank=True)' --cssclass 'date-type' --jsclass 'wok.pollster.datatypes.Date'
python manage.py question_data_type_register --title 'YearMonth' --dbtype 'db.models.YearMonthField(null=True, blank=True)' --cssclass 'monthyear-type' --jsclass 'wok.pollster.datatypes.YearMonth'
python manage.py question_data_type_register --title 'Timestamp' --dbtype 'django.db.models.DateTimeField(null=True, blank=True)' --cssclass 'timestamp-type' --jsclass 'wok.pollster.datatypes.Timestamp'
# PostalCode is added by the pollster migration 0005_postalcodefield.py
# python manage.py question_data_type_register --title 'PostalCode' --dbtype 'django.db.models.PostalCodeField(null=True, blank=True)' --cssclass 'postalcode-type' --jsclass 'wok.pollster.datatypes.PostalCode'
python manage.py virtual_option_type_register --title 'Range' --question-data-type-title 'Text' --jsclass 'wok.pollster.virtualoptions.TextRange'
python manage.py virtual_option_type_register --title 'Range' --question-data-type-title 'Numeric' --jsclass 'wok.pollster.virtualoptions.NumericRange'
python manage.py virtual_option_type_register --title 'Range' --question-data-type-title 'Date' --jsclass 'wok.pollster.virtualoptions.DateRange'
python manage.py virtual_option_type_register --title 'Years ago' --question-data-type-title 'Date' --jsclass 'wok.pollster.virtualoptions.DateYearsAgo'
python manage.py virtual_option_type_register --title 'Years ago' --question-data-type-title 'YearMonth' --jsclass 'wok.pollster.virtualoptions.YearMonthYearsAgo'
python manage.py virtual_option_type_register --title 'Weeks ago' --question-data-type-title 'Timestamp' --jsclass 'wok.pollster.virtualoptions.TimestampWeeksAgo'
python manage.py virtual_option_type_register --title 'Regular expression' --question-data-type-title 'Text' --jsclass 'wok.pollster.virtualoptions.RegularExpression'
python manage.py createcachetable django_cache 2>/dev/null || echo 'Cache table errors ignored'
if [ "$DB_ENGINE" = "postgresql" -a -n "$exe_psql" ] ; then
postgis=$(ls /usr/share/postgresql/*/contrib/postgis-*/postgis.sql)
srefsys=$(ls /usr/share/postgresql/*/contrib/postgis-*/spatial_ref_sys.sql)
if [ -n "$postgis" -a -n "$srefsys" ] ; then
echo "Setting up PostGIS"
args="--username=$root_username $DB_NAME"
if [ -n "$DB_PORT" ] ; then
args="--port=$DB_PORT $args"
fi
if [ -n "$DB_HOST" ] ; then
args="--host=$DB_HOST $args"
fi
psql -q $args <<EOF
\i $postgis
\i $srefsys
CREATE TABLE pollster_zip_codes (id serial, country TEXT, zip_code_key TEXT);
SELECT AddGeometryColumn('pollster_zip_codes', 'geometry', 4326, 'MULTIPOLYGON', 2);
ALTER TABLE pollster_zip_codes OWNER TO $DB_USERNAME;
ALTER TABLE spatial_ref_sys OWNER TO $DB_USERNAME;
ALTER TABLE geometry_columns OWNER TO $DB_USERNAME;
ALTER VIEW geography_columns OWNER TO $DB_USERNAME;
EOF
echo "PostGIS setup complete"
fi
fi
echo ""
echo "** All done. You can start the system by issuing: 'source ./bin/activate && python manage.py runserver'"
echo ""