@@ -26,13 +26,28 @@ function prompt_db_type() {
26
26
27
27
# Get MySQL details
28
28
function get_db_details() {
29
- read -p " MySQL host: " SQLHOST
30
- read -p " MySQL port: " SQLPORT
31
- read -p " MySQL user (should already exist): " SQLUSER
32
- stty -echo
33
- read -p " Password for user: " SQLPWD; echo
34
- stty echo
35
- read -p " Database name (should NOT exist): " DBNAME
29
+ # Allow script to be called non-interactively using:
30
+ # export AUTO_DOCKER=yes && /opt/django-DefectDojo/setup.bash
31
+ if [ " $AUTO_DOCKER " != " yes" ]; then
32
+ # Run interactively
33
+ read -p " MySQL host: " SQLHOST
34
+ read -p " MySQL port: " SQLPORT
35
+ read -p " MySQL user (should already exist): " SQLUSER
36
+ stty -echo
37
+ read -p " Password for user: " SQLPWD; echo
38
+ stty echo
39
+ read -p " Database name (should NOT exist): " DBNAME
40
+ else
41
+ # Set the root password for mysql - install has it blank
42
+ mysql -uroot -e " SET PASSWORD = PASSWORD('Cu3zehoh7eegoogohdoh1the');"
43
+ # Default values for a automated Docker install
44
+ echo " Setting default values for MySQL install"
45
+ SQLHOST=" localhost"
46
+ SQLPORT=" 3306"
47
+ SQLUSER=" root"
48
+ SQLPWD=" Cu3zehoh7eegoogohdoh1the"
49
+ DBNAME=" dojodb"
50
+ fi
36
51
37
52
if mysql -fs -h " $SQLHOST " -P " $SQLPORT " -u" $SQLUSER " -p" $SQLPWD " " $DBNAME " > /dev/null 2>&1 < /dev/null; then
38
53
echo " Database $DBNAME already exists!"
@@ -97,7 +112,14 @@ function get_postgres_db_details() {
97
112
98
113
echo " Welcome to DefectDojo! This is a quick script to get you up and running."
99
114
echo
100
- prompt_db_type
115
+ # Allow script to be called non-interactively using:
116
+ # export AUTO_DOCKER=yes && /opt/django-DefectDojo/setup.bash
117
+ if [ " $AUTO_DOCKER " != " yes" ]; then
118
+ prompt_db_type
119
+ else
120
+ # Default to MySQL install
121
+ DBTYPE=$MYSQL
122
+ fi
101
123
echo
102
124
echo " NEED SUDO PRIVILEGES FOR NEXT STEPS!"
103
125
echo
@@ -126,13 +148,13 @@ if [[ ! -z "$YUM_CMD" ]]; then
126
148
elif [[ ! -z " $APT_GET_CMD " ]]; then
127
149
if [ " $DBTYPE " == $MYSQL ]; then
128
150
echo " Installing MySQL client"
129
- sudo apt-get install libmysqlclient-dev mysql-server
151
+ sudo apt-get -y install libmysqlclient-dev mysql-server
130
152
elif [ " $DBTYPE " == $POSTGRES ]; then
131
153
echo " Installing Postgres client"
132
- sudo apt-get install libpq-dev postgresql postgresql-contrib libmysqlclient-dev
154
+ sudo apt-get -y install libpq-dev postgresql postgresql-contrib libmysqlclient-dev
133
155
fi
134
156
135
- sudo apt-get install libjpeg-dev gcc libssl-dev python-dev python-pip nodejs-legacy wkhtmltopdf npm
157
+ sudo apt-get install -y libjpeg-dev gcc libssl-dev python-dev python-pip nodejs-legacy wkhtmltopdf npm
136
158
elif [[ ! -z " $BREW_CMD " ]]; then
137
159
brew install gcc openssl python node npm Caskroom/cask/wkhtmltopdf
138
160
if [ " $DBTYPE " == $MYSQL ]; then
167
189
168
190
SECRET=` cat /dev/urandom | LC_CTYPE=C tr -dc " a-zA-Z0-9" | head -c 128`
169
191
170
- cp dojo/settings.dist.py dojo/settings.py
192
+ # Allow script to be called non-interactively using:
193
+ # export AUTO_DOCKER=yes && /opt/django-DefectDojo/setup.bash
194
+ if [ " $AUTO_DOCKER " != " yes" ]; then
195
+ cp dojo/settings.dist.py dojo/settings.py
196
+ else
197
+ # locate to the install directory first
198
+ cd /opt/django-DefectDojo/
199
+ cp dojo/settings.dist.py dojo/settings.py
200
+ fi
171
201
172
202
# Save MySQL details in settings file
173
203
if [[ ! -z $BREW_CMD ]]; then
@@ -235,9 +265,17 @@ else
235
265
python manage.py makemigrations dojo
236
266
python manage.py makemigrations
237
267
python manage.py migrate
238
- echo -e " ${GREEN}${BOLD} Create Dojo superuser:"
239
- tput sgr0
240
- python manage.py createsuperuser
268
+ # Allow script to be called non-interactively using:
269
+ # export AUTO_DOCKER=yes && /opt/django-DefectDojo/setup.bash
270
+ if [ " $AUTO_DOCKER " != " yes" ]; then
271
+ echo -e " ${GREEN}${BOLD} Create Dojo superuser:"
272
+ tput sgr0
273
+ python manage.py createsuperuser
274
+ else
275
+ # non-interactively setup the superuser
276
+ python manage.py createsuperuser --noinput --username=admin --email=
' [email protected] '
277
+ /opt/django-DefectDojo/docker/setup-superuser.expect
278
+ fi
241
279
python manage.py loaddata product_type
242
280
python manage.py loaddata test_type
243
281
python manage.py loaddata development_environment
246
284
python manage.py buildwatson
247
285
fi
248
286
249
- if [[ " $USER " == " root" ]]; then
250
- cd components && bower install --allow-root && cd ..
287
+ if [ $( id -u) = 0 ]; then
288
+ adduser --disabled-password --gecos " DefectDojo" dojo
289
+ sudo - dojo -c ' cd /opt/django-DefectDojo/components && bower install'
251
290
else
252
291
cd components && bower install && cd ..
253
292
fi
256
295
if python -c ' import sys; print sys.real_prefix' 2> /dev/null; then
257
296
python manage.py collectstatic --noinput
258
297
else
259
- python manage.py collectstatic --noinput
298
+ python manage.py collectstatic --noinput
260
299
fi
261
300
262
301
0 commit comments