forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.bash
executable file
·152 lines (131 loc) · 5.02 KB
/
setup.bash
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
#!/bin/bash
# Get MySQL details
function get_db_details() {
read -p "MySQL user (should already exist): " SQLUSER
stty -echo
read -p "Password for user: " SQLPWD; echo
stty echo
read -p "Database name (should NOT exist): " DBNAME
echo
if mysql -fs -u$SQLUSER -p$SQLPWD $DBNAME >/dev/null 2>&1 </dev/null; then
echo "Database $DBNAME already exists!"
echo
read -p "Drop database $DBNAME? [Y/n] " DELETE
if [[ ! $DELETE =~ ^[nN]$ ]]; then
mysqladmin -f --user=$SQLUSER --password=$SQLPWD drop $DBNAME
mysqladmin --user=$SQLUSER --password=$SQLPWD create $DBNAME
else
echo "Error! Must supply an empty database to proceed."
echo
get_db_details
fi
else
if mysqladmin --user=$SQLUSER --password=$SQLPWD create $DBNAME; then
echo "Created database $DBNAME."
else
echo "Error! Failed to create database $DBNAME. Check your credentials."
echo
get_db_details
fi
fi
}
echo "Welcome to DefectDojo! This is a quick script to get you up and running."
echo
echo "NEED SUDO PRIVILEGES FOR NEXT STEPS!"
echo
echo "Attempting to install required packages..."
echo
# Set up packages via Yum / APT
YUM_CMD=$(which yum)
APT_GET_CMD=$(which apt-get)
if [[ ! -z $YUM_CMD ]]; then
sudo curl -sL https://rpm.nodesource.com/setup | sudo bash -
sudo yum install gcc libmysqlclient-dev python-devel mysql-server mysql-devel MySQL-python python-setuptools python-pip nodejs wkhtmltopdf npm -y
sudo yum groupinstall 'Development Tools'
elif [[ ! -z $APT_GET_CMD ]]; then
sudo apt-get install gcc libssl-dev python-dev libmysqlclient-dev python-pip mysql-server nodejs-legacy wkhtmltopdf npm -y
else
echo "ERROR! OS not supported. Try the Vagrant option."
exit 1;
fi
# bower install
sudo npm install -g bower
echo
get_db_details
unset HISTFILE
SECRET=`cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 128`
cp dojo/settings.dist.py dojo/settings.py
# Save MySQL details in settings file
sed -i "s/MYSQLUSER/$SQLUSER/g" dojo/settings.py
sed -i "s/MYSQLPWD/$SQLPWD/g" dojo/settings.py
sed -i "s/MYSQLDB/$DBNAME/g" dojo/settings.py
sed -i "s#DOJODIR#$PWD/dojo#g" dojo/settings.py
sed -i "s/DOJOSECRET/$SECRET/g" dojo/settings.py
sed -i "s#BOWERDIR#$PWD/components#g" dojo/settings.py
sed -i "s#DOJO_MEDIA_ROOT#$PWD/media/#g" dojo/settings.py
sed -i "s#DOJO_STATIC_ROOT#$PWD/static/#g" dojo/settings.py
# Detect Python version
PYV=`python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";`
if [[ "$PYV"<"2.7" ]]; then
echo "ERROR: DefectDojo requires Python 2.7+"
exit 1;
else
echo "Leaving Django 1.8.4 requirement"
fi
# Detect if we're in a a virtualenv
if python -c 'import sys; print sys.real_prefix' 2>/dev/null; then
pip install .
python manage.py makemigrations dojo
python manage.py makemigrations
python manage.py migrate
python manage.py syncdb
python manage.py loaddata product_type
python manage.py loaddata test_type
python manage.py loaddata development_environment
python manage.py installwatson
python manage.py buildwatson
else
sudo pip install .
sudo python manage.py makemigrations dojo
sudo python manage.py makemigrations
sudo python manage.py migrate
sudo python manage.py syncdb
sudo python manage.py loaddata product_type
sudo python manage.py loaddata test_type
sudo python manage.py loaddata development_environment
sudo python manage.py installwatson
sudo python manage.py buildwatson
fi
if [[ "$USER" == "root" ]]; then
cd components && bower install --allow-root && cd ..
else
cd components && bower install && cd ..
fi
# Detect if we're in a a virtualenv
if python -c 'import sys; print sys.real_prefix' 2>/dev/null; then
python manage.py collectstatic --noinput
else
sudo python manage.py collectstatic --noinput
fi
echo "=============================================================================="
echo
echo "SUCCESS! Now edit your settings.py file in the 'dojo' directory to complete the installation."
echo
echo "We suggest you consider changing the following defaults:"
echo
echo " DEBUG = True # you should set this to False when you are ready for production."
echo " Uncomment the following lines if you enabled SSL/TLS on your server:"
echo " SESSION_COOKIE_SECURE = True"
echo " CSRF_COOKIE_SECURE = True"
echo " SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')"
echo " SECURE_SSL_REDIRECT = True"
echo " SECURE_BROWSER_XSS_FILTER = True"
echo " django.middleware.security.SecurityMiddleware"
echo
echo "When you're ready to start the DefectDojo server, type in this directory:"
echo
echo " python manage.py runserver"
echo
echo "Note: If git cannot connect using the git:// protocol when downloading bower artifacts, you can run the command "
echo "below to switch over to https://"
echo " git config --global url."https://".insteadOf git://"