-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
117 lines (103 loc) · 3.22 KB
/
setup.sh
File metadata and controls
117 lines (103 loc) · 3.22 KB
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
#!/bin/bash
function report_result() {
# Gets the return value '$?'' of the last command and reports success or not
last_cmd=$?
if [[ $last_cmd -eq 0 ]]; then
echo -e "Success."
else
echo -e "\nSomething went wrong! Bailing..."
exit 1
fi
}
OS=$(uname -a | cut -c1-5)
# venv
## create venv
echo -e "\n*** Checking to see if virtual environment exists"
if [[ ! -d "./venv" ]]; then
echo -e "\n*** Creating new virtual environment using python-venv"
if [[ $OS =~ "Linux" ]]; then
echo "Making adjustments due to bad choice of operating system"
python3 -m venv venv --prompt SQL-Injection-Example
else
python -m venv venv --prompt SQL-Injection-Example
fi
report_result
else
echo -e "\n Virtual environment already exists in this directory."
fi
## activate venv (python virtual environment)
echo -e "\n*** Activating the python virtual environment for this script..."
if [[ $OS =~ "Linux" ]]; then
source venv/bin/activate
else
source venv/Scripts/activate
fi
report_result
echo -e "Using: $(which python)"
# upgrade pip
echo -e "\n*** Updating pip to latest version...\n"
python -m pip install --upgrade pip
report_result
# pip install
echo -e "\n*** Installing latest Python requirements...\n"
python -m pip install -r requirements.txt
report_result
# create .env file
# echo -e "\n*** Creating .env file"
# cat > .env << EOF
# SECRET_KEY = 'Enter django secret key here'
# EOF
# report_result
##################################### setup post-merge hook #####################################
echo -e "\n*** Installing post-merge hooks at .git/hooks/post-merge"
cat > .git/hooks/post-merge << EOF
#!/bin/bash
# This script will run on a successful merge
function report_result() {
# Gets the return value '$?' of the last command and reports success or not
if [[ $? -eq 0 ]]; then
echo -e "Success."
else
echo -e "\nSomething went wrong! Bailing..."
exit 1
fi
}
echo -e "\n*** Running post-merge hook\n"
# venv
echo -e "\n*** Activating the python virtual environment for this script..."
OS=$(uname -a | cut -c1-5)
if [[ $OS =~ "Linux" ]]; then
echo "Making adjustments due to bad choice of operating system"
source venv/bin/activate
else
source venv/Scripts/activate
fi
report_result
echo -e "Using: $(which python)"
# upgrade pip
echo -e "\n*** Updating pip to latest version...\n"
python -m pip install --upgrade pip
report_result
# pip install
echo -e "\n*** Installing latest Python requirements...\n"
python -m pip install -r requirements.txt
report_result
# pre-commit install
echo -e "\n*** Installing any new pre-commit hooks\n"
python -m pre_commit install
report_result
EOF
report_result
# set post-merge hook as executable
echo -e "\n*** Setting post-merge hook as executable\n"
report_result
chmod +x .git/hooks/post-merge
##################################### end of post merge hook setup #####################################
# creating update.sh, which will simply run the post-merge hook
echo -e "\n*** Creating update.sh file. This can be used for running the post merge hook manually."
cat > update.sh << EOF
source .git/hooks/post-merge
EOF
report_result
chmod +x update.sh
echo -e "\nSetup Completed Successfully."