forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.bash
109 lines (91 loc) · 3.62 KB
/
upgrade.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
#!/bin/bash
# upgrade.bash helps you upgrading DefectDojo in your current environment
#
#
printf "\n\n==============================================================================\n"
printf "DefectDojo Upgrade Script.\n\n"
printf "RECOMMENDATION:\n"
printf "Before upgrading please stop your DefectDojo and Celery prcoesses.\n"
printf "==============================================================================\n\n"
# Initialize variables and functions
source entrypoint_scripts/common/dojo-shared-resources.sh
# This function invocation ensures we're running the script at the right place
verify_cwd
function prompt_env() {
read -p "Is there a virtual environment for DefectDojo? (Default is yes): (y/n): " ENVSETUP
ENVSETUP=${ENVSETUP:-y}
if [ "$ENVSETUP" == "y" ] \
|| [ "$ENVSETUP" == "n" ] ; then
printf "\n"
else
printf "Please enter y or n\n\n"
prompt_env
fi
}
prompt_env
function prompt_env_name() {
read -p "What is the name of the virtual environment? (Default is venv): " ENVNAME
ENVNAME=${ENVNAME:-'venv'}
if [ -z "$ENVNAME" ] ; then
prompt_env_name
fi
}
if [ "$ENVSETUP" == "y" ] ; then
prompt_env_name
source $ENVNAME/bin/activate
fi
printf "\n==============================================================================\n"
printf "Backing up database using django-dbbackup.\n"
printf "For more information please visit:\n"
printf "https://github.com/django-dbbackup/django-dbbackup\n"
printf "==============================================================================\n\n"
#Check to see if django dbbackup is installed
BACKUP="$(pip list | grep -F django-dbbackup)"
if [ -z "$BACKUP" ] ; then
printf "Installing django-dbbackup...."
pip install django-dbbackup
fi
function prompt_db_loc() {
read -p "Please provide a directory path to backup the DefectDojo database: " DBPATH
if [ -z "$DBPATH" ] ; then
prompt_db_loc
elif [ ! -d "$DBPATH" ]; then
printf "Path provided does not exist.\n"
prompt_db_loc
fi
printf "\n"
}
#Prompt for the location to backup the database file to
prompt_db_loc
#Generate the filename
CURR_DATE=$(date "+%Y.%m.%d-%H.%M.%S")
DB_BACKUP_NAME="django-db-$CURR_DATE.dump.gz"
length=${#DBPATH}
last_char=${DBPATH:length-1:1}
[[ $last_char != "/" ]] && DBPATH="$DBPATH/";
#Backup the database compressed
python manage.py dbbackup --output-path $DBPATH$DB_BACKUP_NAME --compress
printf "\n==============================================================================\n"
printf "Pulling the latest version from master.\n"
printf "==============================================================================\n\n"
git checkout master
git pull
printf "==============================================================================\n"
printf "Upgrading the pip installs.\n"
printf "==============================================================================\n\n"
pip install -r requirements.txt --upgrade
printf "==============================================================================\n"
printf "Upgrading static components.\n"
printf "==============================================================================\n\n"
cd components
yarn
cd ..
./manage.py collectstatic --noinput
printf "==============================================================================\n"
printf "Upgrading the database.\n"
printf "==============================================================================\n\n"
./manage.py makemigrations
./manage.py migrate
printf "==============================================================================\n"
printf "Upgrade complete!\n"
printf "==============================================================================\n\n"