This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_script.sh
executable file
·189 lines (167 loc) · 5.56 KB
/
run_script.sh
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
echo -e "#####################################"
echo -e "# Running only run_script will only #"
echo -e "# install dependencies and runserver#"
echo -e "# --------------------------------- #"
echo -e "# If this is the first time running #"
echo -e "# ./run_script.sh first #"
echo -e "# If you want to import a database: #"
echo -e "# ./run_script.sh unicamp #"
echo -e "# To run with a clean migration: #"
echo -e "# ./run_script.sh clean #"
echo -e "# To run with a clean db : #"
echo -e "# ./run_script.sh reset #"
echo -e "# To create a new config.json #"
echo -e "# ./run_script.sh config #"
echo -e "#####################################\n\n\n"
# we check requirements
if type pip3 &> /dev/null; then
# download virtual env if its not installed
if ! pip3 list | grep virtualenv
then
echo -e "\nInstalling virtual env"
sudo pip3 install virtualenv
fi
else
echo -e "\n\n#################################"
echo -e "Please, download and install pip3"
echo -e "#################################\n\n"
fi
# generates the virtual envirement in env and activate it
if [ -d "env" ]; then
# Control will enter here if $DIRECTORY exists.
source env/bin/activate
else
virtualenv env
source env/bin/activate
fi
if [[ ! -z "$VIRTUAL_ENV" ]]; then
echo "Activated virtualenv"
fi
# install dependencies
pip3 install -r dependencies.txt
if [[ "$@" == "first" ]]; then
echo -e '\nNow, will configure mail and security\n'
echo ' Until here |'
echo '"Randonly" type on the keyboard about 35 digits V'
read secret_key
echo 'EMAIL_HOST (for gmail use smtp.gmail.com): '
read email_host
echo 'EMAIL_PORT (for gmail use 587): '
read email_port
echo 'Use TLS? [Y/n]: '
read email_tls
echo 'EMAIL_USERNAME (for gmail is the email): '
read email_username
echo 'PASSWORD: '
read password
echo 'Saving configuration on config.json'
if [[ $email_tls == 'n' ]];then
email_tls='False'
else
email_tls='True'
fi
echo "{
\"SECRET_KEY\": "\"$secret_key\"",
\"EMAIL_HOST\": "\"$email_host\"",
\"EMAIL_PORT\": "\"$email_port\"",
\"EMAIL_USE_TLS\": "\"$email_tls\"",
\"EMAIL_HOST_USER\": "\"$email_username\"",
\"EMAIL_HOST_PASSWORD\": "\"$password\""
}" > config.json
echo -e 'This is the first time\n will make migrations and create user'
python3 manage.py makemigrations
python3 manage.py migrate
echo -e "Would you like to import the dev database? [N/y]:"
read import_db
if [[ $import_db == 'y' ]];then
python3 manage.py loaddata docs/dev.json
fi
echo -e 'Now, you ll create a username and password for django'
python3 manage.py createsuperuser
elif [[ "$@" == "unicamp" ]]; then
echo 'load data'
read -n1 -r -p " You're gonna reset all the db - CTRL+C to quit " key
rm -rf gda/migrations/*
rm -rf dacParser/migrations/*
rm -rf stalkeador/migrations/*
rm -rf db.sqlite3
python3 manage.py makemigrations dacParser
python3 manage.py makemigrations gda
python3 manage.py makemigrations stalkeador
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py loaddata docs/dev.json
python3 manage.py createsuperuser
elif [[ "$@" == "clean" ]]; then
echo 'clean'
read -n1 -r -p " You're gonna clean the migrations - CTRL+C to quit " key
rm -rf gda/migrations/*
rm -rf dacParser/migrations/*
rm -rf stalkeador/migrations/*
python3 manage.py makemigrations dacParser
python3 manage.py makemigrations gda
python3 manage.py makemigrations stalkeador
python3 manage.py makemigrations
python3 manage.py migrate
elif [[ "$@" == "reset" ]]; then
echo 'reset'
read -n1 -r -p " You're gonna reset all the db - CTRL+C to quit " key
rm -rf gda/migrations/*
rm -rf dacParser/migrations/*
rm -rf stalkeador/migrations/*
rm -rf db.sqlite3
python3 manage.py makemigrations dacParser
python3 manage.py makemigrations gda
python3 manage.py makemigrations stalkeador
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
elif [[ "$@" == "config" ]]; then
echo -e '\nNow, will configure mail and security\n'
echo ' Until here |'
echo '"Randonly" type on the keyboard about 35 digits V'
read secret_key
echo 'EMAIL_HOST (for gmail use smtp.gmail.com): '
read email_host
echo 'EMAIL_PORT (for gmail use 587): '
read email_port
echo 'Use TLS? [Y/n]: '
read email_tls
echo 'EMAIL_USERNAME (for gmail is the email): '
read email_username
echo 'PASSWORD: '
read password
echo 'Saving configuration on config.json'
if [[ $email_tls == 'n' ]];then
email_tls='False'
else
email_tls='True'
fi
echo "{
\"SECRET_KEY\": "\"$secret_key\"",
\"EMAIL_HOST\": "\"$email_host\"",
\"EMAIL_PORT\": "\"$email_port\"",
\"EMAIL_USE_TLS\": "\"$email_tls\"",
\"EMAIL_HOST_USER\": "\"$email_username\"",
\"EMAIL_HOST_PASSWORD\": "\"$password\""
}" > config.json
elif [[ "$@" == "travis" ]]; then
echo "{
\"SECRET_KEY\": \"abracadabratravis\",
\"EMAIL_HOST\": \"smtp.gmail.com\",
\"EMAIL_PORT\": \"587\",
\"EMAIL_USE_TLS\": \"True\",
\"EMAIL_HOST_USER\": \"oaoa@gmail.com\",
\"EMAIL_HOST_PASSWORD\": \"ahshasdad\"
}" > config.json
python3 manage.py makemigrations dacParser
python3 manage.py makemigrations gda
python3 manage.py makemigrations stalkeador
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py loaddata docs/dev.json
fi
python3 manage.py runserver
.
echo "########## Script terminado ########"