-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshurikens.sh
245 lines (206 loc) · 8.7 KB
/
shurikens.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
# text colors
red_text=`tput setaf 1`
green_text=`tput setaf 2`
blue_text=`tput setaf 4`
# credentials
mysql_user="root"
mysql_password="root"
# function to get project name, framework name, database name from user input
function get_details_from_user(){
until read -r -p "Enter Projectname : " project_name && test "$project_name" != ""; do
continue
done
until read -r -p "Enter framework (options flask, django, fast api) :" framework_name && test "$framework_name" != ""; do
continue
done
read -p "Would like to specify framework version (Y/N): " confirm
if [[ "$confirm" =~ ^([yY][eE][sS]|[yY])$ ]]
then
read -p "Enter $framework_name version : " framework_version
fi
until read -r -p "Enter database (options mysql, postgresql, mongodb) :" database && test "$database" != ""; do
continue
done
}
environment_variable="env"
env_name="${project_name}${environment_variable}"
project_root_path="${HOME}/${project_name}"
project_settings_path="${project_root_path}/${project_name}"
echo "${project_settings_path}"
# function to create virtualenvironment
function create_virtualenvironment(){
echo "env name is ${env_name}"
echo "${blue_text}creating virtual environment $env_name"
(cd $HOME ; virtualenv -p python3 ${env_name})
}
# function to install django
function install_django(){
if [ ! -z "$frame_work_version" ]
then
echo "${blue_text}======Installing django version $frame_work_version in environment ${env_name}======"
$HOME/${env_name}/bin/pip install django==$frame_work_version
else
echo "${blue_text}======Installing updated django version in environment: ${env_name}======"
$HOME/${env_name}/bin/pip install django
fi
}
# list of supporting packages needed for a typical django project
function install_django_support_packages(){
# mysqlclient
($HOME/${env_name}/bin/pip install mysqlclient)
# Image uploads based operations Pillow
($HOME/${env_name}/bin/pip install Pillow)
}
# function to create django project
function create_django_project(){
echo "${blue_text}======Creating django project ${project_name}======"
(cd $HOME ; django-admin.py startproject ${project_name})
}
# function to create django project setup
function django_project_setup(){
echo "${blue_text}======Setting up django project ${project_name}======"
(cd $HOME/${project_name} ; mkdir templates && mkdir static)
(cd $HOME/${project_name}/static ; mkdir js && mkdir img && mkdir css)
echo "${blue_text}======Changing templates Settings for ${project_name}======"
chmod 755 ./files/django_files/django_settings_template_tweaker.py
(source $HOME/${env_name}/bin/activate && $HOME/${env_name}/bin/python3 ./files/django_files/django_settings_template_tweaker.py)
sleep 5
echo "${blue_text}======Changing database Settings for ${project_name}======"
chmod 755 ./files/django_files/django_settings_database_tweaker.py
(source $HOME/${env_name}/bin/activate && $HOME/${env_name}/bin/python3 ./files/django_files/django_settings_database_tweaker.py)
sleep 5
}
# function to do databasee migrations for django
function django_database_migrate(){
(chmod 755 $HOME/${project_name}/manage.py makemigrations && chmod 755 $HOME/${project_name}/manage.py migrate)
}
# function to install flask
function install_flask(){
if [ ! -z "$frame_work_version" ]
then
echo "${blue_text}======Installing flask version ${frame_work_version} in environment ${env_name}======"
$HOME/${env_name}/bin/pip install flask==$frame_work_version
else
echo "${blue_text}======Installing updated flask version in environment: ${env_name}======"
$HOME/${env_name}/bin/pip install flask
fi
}
# list of supporting packages needed for a typical flask project
function install_flask_support_packages(){
#sql alchemy
echo "${blue_text}======Installing sql alchemy======"
($HOME/${env_name}/bin/pip install Flask-SQLAlchemy)
# flask migrate
echo "${blue_text}======Installing flask migrate======"
($HOME/${env_name}/bin/pip install Flask-Migrate)
case $database in
mysql)
echo "${blue_text}======Installing flask mysql======"
($HOME/${env_name}/bin/pip install flask-mysql)
;;
postgresql)
echo "${blue_text}======Installing flask postgresql======"
($HOME/${env_name}/bin/pip install psycopg2)
;;
mongodb)
echo "${blue_text}======Installing flask pymongo======"
($HOME/${env_name}/bin/pip install Flask-PyMongo)
esac
}
# function to create flask project
function create_flask_project(){
echo "${blue_text}======Creating flask project ${project_name}======"
(cd $HOME ; mkdir ${project_name})
}
# function to create flask project setup
function flask_project_setup(){
echo "${blue_text}======Setting up flask project ${project_name}======"
cp $PWD/files/flask_files/flask_function_routes.py $HOME/${project_name}/api.py
echo "${blue_text}======Setting up models boilerplate file for ${project_name}======"
cp $PWD/files/flask_files/models.py $HOME/${project_name}/models.py
echo "${blue_text}======Setting up configuration for ${project_name}======"
cp $PWD/files/flask_files/configuration.py $HOME/${project_name}/configuration.py
echo "${blue_text}======Setting up errorhandler boilerplate for ${project_name}======"
cp $PWD/files/flask_files/error_handlers.py $HOME/${project_name}/error_handlers.py
}
function install_fastapi(){
if [ ! -z "$frame_work_version" ]
then
echo "${blue_text}======Installing fast api version $frame_work_version in environment ${env_name}======"
($HOME/${env_name}/bin/pip install fastapi==$frame_work_version && $HOME/${env_name}/bin/pip install uvicorn)
else
echo "${blue_text}======Installing updated fastapi version in environment: ${env_name}======"
($HOME/${env_name}/bin/pip install fastapi && $HOME/${env_name}/bin/pip install uvicorn)
fi
}
function fastapi_project_setup(){
echo "${blue_text}======Setting up fastapi project ${project_name}======"
(cd $HOME/${project_name} ; cp .files/fastapi_files/fast_api_routes.py api.py)
echo "${blue_text}======Setting up models boilerblate file for ${project_name}======"
(cd $HOME/${project_name} ; cp ./files/flask_files/models.py models.py)
}
function create_database(){
if ["$database" == mysql]
then
echo "${blue_text}======Creating Mysql database======"
mysql -u${mysql_user} -p${mysql_password} -e "create database ${project_name}"
fi
}
function generic_supporting_packages(){
# locust for load testing
echo "${blue_text}======Installing locust======"
($HOME/${env_name}/bin/pip install locust)
}
function export_bash_variables(){
echo "${blue_text}======Exporting path variables======"
(source $HOME/${env_name}/bin/activate && export $project_name && export $database_name && export $mysql_user && export $mysql_password && export project_root_path="${HOME}/${project_name}" && export project_settings_path="${HOME}/${project_name}/${project_name}")
}
function create_docker_file_and_compose_file(){
echo "${blue_text}======Creating docker file======"
cp $PWD/files/Dockerfile $HOME/${project_name}/Dockerfile
echo "${blue_text}======Creating docker-compose file======"
cp $PWD/files/Dockerfile $HOME/${project_name}/docker-compose.yaml
}
function create_requirements_dot_txt_file(){
(cd $HOME/${project_name} ; pip3 freeze > requirements.txt)
}
function create_helper_bash_scripts(){
cp $PWD/files/flask_files/helper-bash-scripts $HOME/${project_name}/
}
# function to create git repositories
function create_git_repository(){
(cd $HOME/${project_name} ; git init)
}
function main(){
get_details_from_user
create_virtualenvironment
export_bash_variables
case $framework_name in
django)
install_django
create_django_project
django_project_setup
create_database
django_database_migrate
generic_supporting_packages
create_requirements_dot_txt_file
create_git_repository
;;
flask)
install_flask
create_flask_project
flask_project_setup
install_flask_support_packages
generic_supporting_packages
create_requirements_dot_txt_file
create_docker_file
create_git_repository
;;
fastapi)
install_fastapi
generic_supporting_packages
create_git_repository
esac
}
main