Skip to content

Commit d5269e2

Browse files
authored
Merge pull request DefectDojo#377 from mtesauro/master
Updated setup.bash to allow for non-interactive running to make build…
2 parents 6377d9c + 72704f0 commit d5269e2

File tree

2 files changed

+66
-18
lines changed

2 files changed

+66
-18
lines changed

docker/setup-superuser.expect

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/expect
2+
3+
set timeout -1;
4+
spawn /usr/bin/python manage.py changepassword admin;
5+
expect {
6+
"Password:" { exp_send "admin\r" ; exp_continue }
7+
"Password (again):" { exp_send "admin\r" ; exp_continue }
8+
eof
9+
}

setup.bash

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,28 @@ function prompt_db_type() {
2626

2727
# Get MySQL details
2828
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
3651

3752
if mysql -fs -h "$SQLHOST" -P "$SQLPORT" -u"$SQLUSER" -p"$SQLPWD" "$DBNAME" >/dev/null 2>&1 </dev/null; then
3853
echo "Database $DBNAME already exists!"
@@ -97,7 +112,14 @@ function get_postgres_db_details() {
97112

98113
echo "Welcome to DefectDojo! This is a quick script to get you up and running."
99114
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
101123
echo
102124
echo "NEED SUDO PRIVILEGES FOR NEXT STEPS!"
103125
echo
@@ -126,13 +148,13 @@ if [[ ! -z "$YUM_CMD" ]]; then
126148
elif [[ ! -z "$APT_GET_CMD" ]]; then
127149
if [ "$DBTYPE" == $MYSQL ]; then
128150
echo "Installing MySQL client"
129-
sudo apt-get install libmysqlclient-dev mysql-server
151+
sudo apt-get -y install libmysqlclient-dev mysql-server
130152
elif [ "$DBTYPE" == $POSTGRES ]; then
131153
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
133155
fi
134156

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
136158
elif [[ ! -z "$BREW_CMD" ]]; then
137159
brew install gcc openssl python node npm Caskroom/cask/wkhtmltopdf
138160
if [ "$DBTYPE" == $MYSQL ]; then
@@ -167,7 +189,15 @@ fi
167189

168190
SECRET=`cat /dev/urandom | LC_CTYPE=C tr -dc "a-zA-Z0-9" | head -c 128`
169191

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
171201

172202
# Save MySQL details in settings file
173203
if [[ ! -z $BREW_CMD ]]; then
@@ -235,9 +265,17 @@ else
235265
python manage.py makemigrations dojo
236266
python manage.py makemigrations
237267
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
241279
python manage.py loaddata product_type
242280
python manage.py loaddata test_type
243281
python manage.py loaddata development_environment
@@ -246,8 +284,9 @@ else
246284
python manage.py buildwatson
247285
fi
248286

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'
251290
else
252291
cd components && bower install && cd ..
253292
fi
@@ -256,7 +295,7 @@ fi
256295
if python -c 'import sys; print sys.real_prefix' 2>/dev/null; then
257296
python manage.py collectstatic --noinput
258297
else
259-
python manage.py collectstatic --noinput
298+
python manage.py collectstatic --noinput
260299
fi
261300

262301

0 commit comments

Comments
 (0)