forked from megamsys/nilavu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd
executable file
·469 lines (441 loc) · 13.2 KB
/
d
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#!/bin/bash
# This script is a helper to perform git commit, cleaning up the rails asset directory, clean db
#before a git commit is performed.
#
#
NIL_INSTALL_PATH=
NIL_GIT_COMMIT_MASTER=
NIL_GIT_MASTER=master
NIL_GIT_ORIGIN=origin
#--------------------------------------------------------------------------
#initialize the environment variables.
#NIL_INSTALL_PATH => the rails application installation directory.
#--------------------------------------------------------------------------
initialize(){
if [ -f "$PWD/app" ] ;
then
echo "WARNING ! "
echo " Recommended mode to start the script is by running"
echo " d.sh from the script directory.!!!!"
NIL_INSTALL_PATH=$PWD
else
NIL_INSTALL_PATH=../
fi
cd $NIL_INSTALL_PATH
}
#
#
#
#--------------------------------------------------------------------------
#parse the input parameters.
# Pattern in case statement is explained below.
# a*) The letter a followed by zero or more of any
# *a) The letter a preceded by zero or more of any
#--------------------------------------------------------------------------
parseParameters() {
#integer index=0
if [ $# -lt 1 ]
then
help
exitScript 0
fi
NIL_GIT_COMMIT_MASTER=$2
for item in "$@"
do
case $item in
[hH][eE][lL][pP])
help
;;
[lL][uU][dD])
licenseupd
;;
('/?')
help
;;
[mM][yY])
echo "Howdy $NIL_GIT_MASTER. Enjoy committing local to <master> - Github..."
mystuff
;;
[oO][mM][yY])
echo "Howdy $NIL_GIT_ORIGIN. Enjoy committing local to <origin> - Github..."
origin_stuff
;;
[uU][pP][dD])
echo "Howdy $NIL_GIT_MASTER.enjoy merging <origin> to local..."
uptodate
;;
[fF][iI][nN][iI][sS][hH])
finish
;;
[cC][lL][eE][aA][nN])
echo "Cleaning up tmp and assets..."
clean
exitScript 0
;;
[pP][rR][eE][cC][oO][mM])
echo "Cleaning up tmp and assets, precompiling..."
precom
;;
[dD][bB][cC][lL][eA][aA][nN])
echo "Cleaning up db..."
dbclean
;;
'dbinit')
echo "Initializing db..."
dbinit
;;
[vV][eE][rR][sS][iI][oO][nN])
version
;;
'status')
status
;;
*)
echo "Unknown option : $item - refer help."
help
;;
esac
index=$(($index+1))
done
}
#
#
#--------------------------------------------------------------------------
#prints the help to out file.
#--------------------------------------------------------------------------
help(){
echo "Usage : d.sh [Options]"
echo "help : prints the help message."
echo "status : does a git status."
echo "lud : does a insert of License file into your code."
echo "my : does a add, commit and push of my master."
echo "omy : does a add, commit and push to origin."
echo "upd : does a fetch from origing and merge to my master."
echo "finish : does a push of anothers users master to origin"
echo " (committer only)"
echo "clean : cleans up the temp files."
echo "precom : cleans up the temp files and precompiles asset."
echo "dbinit : initializes your database."
echo "dbclean : cleans up the db. (*valid on an existing setup system)"
exitScript 0
}
#--------------------------------------------------------------------------
# status the installation
# this pretty much dumps the environment variables., java path and arguments
#-------------------------------------------------------------------------
status(){
echo "========================================================="
printf "%-20s=>\t%s\n" git remote
echo "========================================================="
git remote -v
echo "========================================================="
printf "%-20s=>\t%s\n" git status
echo "========================================================="
git status
echo "========================================================="
exitScript 1
}
#
#
#--------------------------------------------------------------------------
#Updates the license text in all the source code.
#--------------------------------------------------------------------------
licenseupd(){
if [ ! -f $LICENSE_FILE_NAME ]
then
echo $LICENSE_FILE_NAME does not exists.
exitScript 0
fi
echo "========================================================="
printf "%-20s=>\t%s\n" Updating [$LICENSE_FILE_NAME]
echo "========================================================="
echo -n "Do you want to insert [$LICENSE_FILE_NAME] text into your code [y/n]? "
read -n 1 licenseupd
echo
if [[ $licenseupd =~ ^[Yy]$ ]]
then
echo "========================================================="
cd $JAVA_SRC_DIR
if [ -d $JAVA_OUT_DIR ]
then
rm -r $JAVA_OUT_DIR
fi
mkdir $JAVA_OUT_DIR
for i in `find -type d | sed 's/\.//' | grep -v "^$"`; do mkdir $JAVA_OUT_DIR$i; done
for i in `find -name "*.java"`; do cat $NIL_INSTALL_PATH/$LICENSE_FILE_NAME $i > $JAVA_OUT_DIR/$i ; done
fi
exitScript 0
}
#--------------------------------------------------------------------------
# git add all the files,commits to the local repos.
# performs a push to the users master in github.
#-------------------------------------------------------------------------
mystuff(){
clean
echo -n "Do you want to add/commit files [y/n]? "
read -n 1 addcommit
echo
if [[ $addcommit =~ ^[Yy]$ ]]
then
echo "========================================================="
git add .
git commit .
fi
echo "========================================================="
echo -n "Do you want to push to your master [y/n]? "
read -n 1 pmstr
echo
if [[ $pmstr =~ ^[Yy]$ ]]
then
echo "========================================================="
git push master
echo "========================================================="
fi
status
exitScript 1
}
#--------------------------------------------------------------------------
# git add all the files,commits to the local repos.
# performs a push to the committers origin in github.
#-------------------------------------------------------------------------
origin_stuff(){
clean
echo -n "Do you want to add/commit files [y/n]? "
read -n 1 addcommit
echo
if [[ $addcommit =~ ^[Yy]$ ]]
then
echo "========================================================="
git add .
git commit .
fi
echo "========================================================="
echo -n "Do you want to push to your origin [y/n]? "
read -n 1 pmstr
echo
if [[ $pmstr =~ ^[Yy]$ ]]
then
echo "========================================================="
git push origin
echo "========================================================="
fi
status
exitScript 1
}
#--------------------------------------------------------------------------
# git add all the files,commits to the local repos.
# performs a push to the users master in github.
#-------------------------------------------------------------------------
uptodate(){
echo -n "Do you want to add/commit files [y/n]? "
read -n 1 addcommit
echo
if [[ $addcommit =~ ^[Yy]$ ]]
then
echo "========================================================="
git add .
git commit .
fi
echo "========================================================="
echo -n "Do you want to rebase from origin [y/n]? "
read -n 1 pmstr
echo
if [[ $pmstr =~ ^[Yy]$ ]]
then
echo "========================================================="
git fetch origin
git merge origin
echo "========================================================="
fi
exitScript 1
}
#--------------------------------------------------------------------------
# git add all the files,commits to the local repos.
# performs a push to the users master in github.
#-------------------------------------------------------------------------
finish(){
if [ -z $NIL_GIT_COMMIT_MASTER ]
then
echo "Missing parameter <master repository name>."
help
exitScript 1
else
echo "Howdy committer.Enjoy merging <$NIL_GIT_COMMIT_MASTER> to origin..."
echo "========================================================="
echo -n "Do you want to add/commit files [y/n]? "
read -n 1 addcommit
echo
if [[ $addcommit =~ ^[Yy]$ ]]
then
echo "========================================================="
git add .
git commit .
fi
echo "========================================================="
echo -n "Do you want to commit $NIL_GIT_COMMIT_MASTER to your origin [y/n]? "
read -n 1 pmstr
echo
if [[ $pmstr =~ ^[Yy]$ ]]
then
echo "========================================================="
git fetch $NIL_GIT_COMMIT_MASTER
git merge $NIL_GIT_COMMIT_MASTER/master
git push -u origin $NIL_GIT_COMMIT_MASTER/master
echo "========================================================="
fi
status
exitScript 0
fi
}
#
#
#
#
#--------------------------------------------------------------------------
#This command will automatically cleanup the assests and the tmp directory.
#--------------------------------------------------------------------------
clean(){
#
#
clear
find . -type f -name "*.*~" -exec rm -f {} \;
rake assets:clean
rake tmp:clear
#only delete public system directory if it exists
if [ -d public/system ]
then
rm -r public/system
fi
}
#
#
#
#
#--------------------------------------------------------------------------
#This command will automatically cleanup the assests and the tmp directory.
#and run a precompile of the assets.
#--------------------------------------------------------------------------
precom(){
#
#
clear
find . -type f -name "*.*~" -exec rm -f {} \;
rake assets:clean
rake tmp:clear
rake assets:precompile
exitScript 0
}
#
#
#
#--------------------------------------------------------------------------
#This command will automatically bring up the required migration versions and bring it up.
#Run it the first time.
#--------------------------------------------------------------------------
dbinit(){
echo "========================================================="
echo -n "!!! Do you want to init(drop & recreate) your db [y/n]? "
read -n 1 initdb
echo
if [[ $initdb =~ ^[Yy]$ ]]
then
echo "========================================================="
# As a super user, to list all of the open connections to the cocdb database
psql -U postgres -c "select * from pg_stat_activity where datname='cocdb'"
# As a superuser, to drop all of the open connections to the cocdb database
psql -U postgres -c "select pg_terminate_backend(procpid) from pg_stat_activity where datname='cocdb'"
# Drop cocdb
psql -U postgres -c "drop database cocdb"
# Create cocdb
psql -U postgres -c "create database cocdb"
#Grant all privileges on cocdb to user megam, postgres
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE cocdb to postgres"
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE cocdb to megam"
#create users
rake db:migrate:up VERSION=20120319153913
#create identities
rake db:migrate:up VERSION=20120319154255
#create organization
rake db:migrate:up VERSION=20120811145124
#alter organization - logo
rake db:migrate:up VERSION=20120811145726
#create cloud_identities
rake db:migrate:up VERSION=20120817045502
#create apps_items
rake db:migrate:up VERSION=20120824094944
#create products
rake db:migrate:up VERSION=20120829143151
#create cloud_runs
rake db:migrate:up VERSION=20130108105504
rake db:seed
fi
exitScript 0
}
#
#
#
#--------------------------------------------------------------------------
#This command will automatically bring down the required migration versions and bring it up.
#also will perform the required cleanup.
#--------------------------------------------------------------------------
dbclean(){
#remove cloud_runs
rake db:migrate:down VERSION=20130108105504
#remove products
rake db:migrate:down VERSION=20120829143151
#remove apps_items
rake db:migrate:down VERSION=20120824094944
#remove cloud_identities
rake db:migrate:down VERSION=20120817045502
#remove logo
rake db:migrate:down VERSION=20120811145726
#drop organizations
rake db:migrate:down VERSION=20120811145124
#drop identities
rake db:migrate:down VERSION=20120319154255
#drop users
rake db:migrate:down VERSION=20120319153913
#create users
rake db:migrate:up VERSION=20120319153913
#create identities
rake db:migrate:up VERSION=20120319154255
#create organization
rake db:migrate:up VERSION=20120811145124
#alter organization - logo
rake db:migrate:up VERSION=20120811145726
#create cloud_identities
rake db:migrate:up VERSION=20120817045502
#create apps_items
rake db:migrate:up VERSION=20120824094944
#create products
rake db:migrate:up VERSION=20120829143151
#create cloud_runs
rake db:migrate:up VERSION=20130108105504
rake db:seed
exitScript 0
}
#
#
#
#--------------------------------------------------------------------------
#print the version.
#--------------------------------------------------------------------------
version(){
echo "Nothing to show as version now."
exitScript 0
}
#
#
#
exitScript(){
exit $@
}
#
#
#
#--------------------------------------------------------------------------
# main entry
#--------------------------------------------------------------------------
initialize
#parse parameters
parseParameters "$@"