This repository was archived by the owner on Feb 16, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathprojRocket.sh
More file actions
executable file
·288 lines (207 loc) · 6.79 KB
/
Copy pathprojRocket.sh
File metadata and controls
executable file
·288 lines (207 loc) · 6.79 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd)
DIR="." # the directory that holds this project
PROJ_TYPE=""
PROJ_NAME="UNTITLED"
EXTRAS=""
if [ "$1" == "--help" ];
then
clear
echo
echo "projRocket: A command line project bootstrapper."
echo
echo "Usage: ./projRocket -t <project_type> See: Project Types -n <project_name> Default: UNTITLED -d <project_directory>Default: CWD"
echo
echo -e "Supported Project Types\n"
#--------STATICPLAIN-------------------------------
echo -e " ----------\n Static\n ----------"
echo " Use: -t static"
echo " What happens:"
echo -e " Creates index.html with some basic markup."
echo
#--------STATIC SITE-------------------------------
echo -e " ----------\n Static Site\n ----------"
echo " Use: -t staticsite"
echo " What happens:"
echo -e " Creates a static site based on html5Boilerplate"
echo
#--------Python Module-------------------------------
echo -e " ----------\n Python Module\n ----------"
echo " Use: -t pymodule"
echo " What happens:"
echo -e " Creates a skeleton python module that adheres to \n http://guide.python-distribute.org/creation.html"
echo
#--------Django-------------------------------
echo -e " ----------\n Django Project\n ----------"
echo " Use: -t django"
echo " What happens:"
echo -e " Creates a new virtualenv environment (ENV), pip installs Django, calls startproject with your project name"
echo -e " testdjango/
├── ENV
├── manage.py
└── testdjango
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py"
echo -e "Install extra packages into your ENV with -e followed by a COMMA DELIMITED string. Currently only PyPi packages work. "
echo -e "Example:"
echo -e "-e south,psycopg2"
#--------WORDPRESS-------------------------------
echo -e " ----------\n Wordpress\n ----------"
echo " Use: -t wordpress"
echo " What happens:"
echo -e " Creates a new theme folder based on the html5boilerplate theme \n and grabs Wordpress from github. Your theme is ln -s'd into the wordpress theme directory \n You will also be asked if you want to configure your DB which will set up wp-config.php."
echo
exit 1
fi
while getopts ":t:n:d:e:" opt; do
case $opt in
t)
#echo "-t was triggered, Parameter: $OPTARG" >&2
PROJ_TYPE=$OPTARG
;;
n)
#echo "-t was triggered, Parameter: $OPTARG" >&2
PROJ_NAME=$OPTARG
;;
d)
DIR=$OPTARG
;;
e)
EXTRAS="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
start_static (){
echo "Starting Static Html project, codename: $PROJ_NAME"
if [ ! -d "$DIR/$PROJ_NAME" ];
then
mkdir "$DIR/$PROJ_NAME"
fi
# we are just gonna a file from the templates directory
cp $SCRIPTPATH/templates/html/index.html $DIR/$PROJ_NAME/.
}
start_static_site (){
echo "Starting Static Site project, codename: $PROJ_NAME"
if [ ! -d "$DIR/$PROJ_NAME" ];
then
mkdir "$DIR/$PROJ_NAME"
fi
git clone git://github.com/h5bp/html5-boilerplate.git $DIR/$PROJ_NAME
# ungit html5bp
rm -rf "$DIR/$PROJ_NAME/.git"
# get rid of some files from html5 boilerplate
rm "$DIR/$PROJ_NAME/CHANGELOG.md"
rm "$DIR/$PROJ_NAME/CONTRIBUTING.md"
rm -rf "$DIR/$PROJ_NAME/doc"
}
start_wp_project (){
echo "Starting Wordpress project, codename: $PROJ_NAME"
if [ ! -d "$DIR/$PROJ_NAME" ];
then
mkdir "$DIR/$PROJ_NAME"
fi
# its really up to each project handler to take it from here.
# So what do we need:
# Wordpress installation lets get it from Github
git clone git://github.com/WordPress/WordPress.git "$DIR/$PROJ_NAME/wordpress"
# a bootstrapped Theme directory, we'll ln -s it in wordpress content. I like using HTML5 Boilerplate so lets use this thing
git clone git://github.com/asmedrano/html5-boilerplate-for-wordpress.git "$DIR/$PROJ_NAME/$PROJ_NAME-theme"
# get rid of all the .git files so this is really just a bunch of files. TODO: is there an actual way to do this?
rm -rf "$DIR/$PROJ_NAME/$PROJ_NAME-theme/.git"
# now we need to ln -s the theme into wordpress content, cause we dont want to check in the wordpress install into github.
ln -s "$DIR/$PROJ_NAME/$PROJ_NAME-theme" "$DIR/$PROJ_NAME/wordpress/wp-content/themes/$PROJ_NAME-theme"
echo "Do you want to configure a database? I'm assuming one already exists in mysql...(y/n)"
read DB_Y_N
if [ $DB_Y_N == "y" ];
then
echo "Enter DB Name:"
read DB_NAME
echo "Enter DB User:"
read DB_USER
echo "Enter DB Password"
read DB_PASS
echo "You entered Db name: $DB_NAME, Db user: $DB_USER, Pass: $DB_PASS"
# we are gonna use SED to edit config.sample that exists in wordpress/wp-config-sample.php
cp $DIR/$PROJ_NAME/wordpress/wp-config-sample.php $DIR/$PROJ_NAME/wordpress/wp-config.php
sed -i -e 's/username_here/'${DB_USER}'/g' $DIR/$PROJ_NAME/wordpress/wp-config.php
sed -i -e 's/database_name_here/'${DB_NAME}'/g' $DIR/$PROJ_NAME/wordpress/wp-config.php
sed -i -e 's/password_here/'${DB_PASS}'/g' $DIR/$PROJ_NAME/wordpress/wp-config.php
fi
echo "ALL DONE!"
}
start_pymodule (){
echo "Starting Python Module, codename: $PROJ_NAME"
if [ ! -d "$DIR/$PROJ_NAME" ];
then
mkdir "$DIR/$PROJ_NAME"
fi
cp -r $SCRIPTPATH/templates/python/pymodule/* $DIR/$PROJ_NAME/.
MODULE_NAME=` echo $PROJ_NAME | awk '{print tolower($0)}'`
# rename module template
mv $DIR/$PROJ_NAME/your_module $DIR/$PROJ_NAME/$MODULE_NAME
}
start_django (){
echo "Starting Django Project, codename: $PROJ_NAME"
if [ ! -d "$DIR/$PROJ_NAME" ];
then
mkdir "$DIR/$PROJ_NAME"
fi
# everyone uses virtualenv!
virtualenv $DIR/$PROJ_NAME/ENV
source $DIR/$PROJ_NAME/ENV/bin/activate && pip install django
# start project
DJANGO_PROJ_NAME=` echo $PROJ_NAME | awk '{print tolower($0)}'` # lower caseproject name
source $DIR/$PROJ_NAME/ENV/bin/activate && django-admin.py startproject $DJANGO_PROJ_NAME $DIR/$PROJ_NAME
#this supports the EXTRAS -e arg, it will pip install everything you pass to it.
OIFS=$IFS
IFS=','
extra_installs=$EXTRAS
for x in $extra_installs
do
source $DIR/$PROJ_NAME/ENV/bin/activate && pip install $x
done
IFS=$OIFS
echo "Done!"
}
#--------------------------- Options are parsed, do the buisness
# check if project type is specified
if [ "$PROJ_TYPE" == '' ];
then
echo "Project Type is required, use -t <project_name>...Exiting"
exit
fi
# always create the dir if it doesnt exist
if [ ! -d $DIR ];
then
mkdir $DIR
fi
if [ "$PROJ_TYPE" == "wordpress" ];
then
start_wp_project
fi
if [ "$PROJ_TYPE" == "static" ];
then
start_static
fi
if [ "$PROJ_TYPE" == "staticsite" ];
then
start_static_site
fi
if [ "$PROJ_TYPE" == "pymodule" ];
then
start_pymodule
fi
if [ "$PROJ_TYPE" == "django" ];
then
start_django
fi