-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1mk.sh
More file actions
executable file
·434 lines (288 loc) · 10.4 KB
/
1mk.sh
File metadata and controls
executable file
·434 lines (288 loc) · 10.4 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
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
#!/usr/bin/env bash
# Requirements:
# - ruby 2.6 3 [2.7.1 got error mysql2 gem failed to build native extension 0.5.3 ]
# - rails 5.2.4.4
# - apt -y install zip
# - rsync
# - sudo apt-get -y install libmysqlclient-dev
function abort()
{
# set -e will exit on first error. so set -vxe..
# http://stackoverflow.com/questions/2870992/automatic-exit-from-bash-shell-script-on-error
echo >&2 '
***************
*** ABORTED ***
***************
'
date
echo "An error occurred. Exiting..." >&2
exit 1
}
# comment out the next two lines to disable the abort on error. [ trap and set -e]..
# commented out it will not stop - just continue after and error and go to completion.
# You will have to find the error way back somewhere in the terminal. You may want that to happen. You have a choice.
trap 'abort' 0
set -e
# Add your script below.... If an error occurs, the abort() function will be called.
#----------------------------------------------------------
# ===> Your script goes here.........................
### settings .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# http://how-to.wikia.com/wiki/How_to_read_command_line_arguments_in_a_bash_script
# $0 is scripts name.
# http://stackoverflow.com/questions/6121091/get-file-directory-path-from-filepath
# http://stackoverflow.com/questions/1464253/global-environment-variables-in-a-shell-script
# http://stackoverflow.com/questions/29270289/bash-read-from-file-and-store-to-variables
if [ -z "$1" ] ; then
set +vx
echo ;
echo 'Invalid parameters.'
echo ' Usage: eg: bashrail/1mk.sh project_name'
echo ' bashrail contains the app creator scripts.'
echo ' project_name is the name you want to give the generated rails app.'
echo ;
exit 7
else
#
# Set variables
#
# set app name as first pramater on commandline
export appn=$1
# get the command that invoked this..
inscript=$0
# extract the path from that command..
bpath=$(dirname "${inscript}")
# Location of creator files beside the new folder of the application..
export sfil=$bpath # ex: bashrail
# Location modified for use after cd into the new app folder..
export sfil2='../'$sfil # ex: ../bashrail
fi
export mpwd=$PWD
export mhome=$HOME
#
# Save commandline parameters so they can be used to run one subscript later.
#
mkdir -p /tmp
echo $appn $sfil $sfil2 $mpwd $0 $mhome>/tmp/"_brvar1202_${USER}".txt
chmod 777 /tmp/"_brvar1202_${USER}".txt
# create the tmp ruby runner file...
touch "/tmp/_temprubyrunner_${USER}.rb"
chmod 777 "/tmp/_temprubyrunner_${USER}.rb"
echo
echo
echo Press ctrl-c now if you want to stop and edit settings in /tmp/_brvar1202_${USER}.txt
echo
date
timeout1=20 ; read -t "${timeout1}" -p "Press ENTER or wait $timeout1 seconds..." || true ; echo ;
### setup.... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
date ; set +vx ; set -vx ; # echo off, then echo on
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# for mac osx install gnu-sed, brew install gnu-sed
# alias gsed to sed..
# http://apple.stackexchange.com/questions/236177/using-alias-in-bash-script-in-osx
if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo OSX
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
echo cygwin
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
echo msys
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
echo win
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo freebsd
fi
# for OSX....
if [[ "$OSTYPE" == "darwin"* ]]; then
echo Mac OSX
alias sed=gsed
shopt -s expand_aliases
fi
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# thor error in version 0.19.2
# See error listed in gemfile1.sh
# gem uninstall thor -v 0.19.2
# gem install thor -v 0.19.1
### start.... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pwd
source $sfil/new1.sh
# everything after this is done from within the project folder $appn
source $sfil2/gemfile1.sh
# source $sfil2/tableprefix1.sh # optional
source $sfil2/timezone1.sh # optional
source $sfil2/home1.sh #
source $sfil2/bootstrap1.sh
source $sfil2/applayout1.sh # requires home1.sh
source $sfil2/paginate1.sh # optional, but you may need to edit to overcome some errors since it may include some code that depends on other features.
# use only devisetokenauth1.sh or devisejwt.sh NOT both..
source $sfil2/devise1.sh # optional, but will modify home page, so.. some edits to overcome missing items may be necessary
source $sfil2/devisejwt.sh # optional. requires devise1.sh
# or
# source $sfil2/devisetokenauth1.sh # optional
source $sfil2/cancan1.sh # optional, but .. may require some further edits.
source $sfil2/admin1.sh # optional
#source ../bashrail/admin-ra-materialtheme.sh
# or
source $sfil2/admin-ra-materialtheme.sh
source $sfil2/ldap1.sh
source $sfil2/papertrail1.sh
source $sfil2/figaro.env.sh
# See below for select2.sh and jqueryautocomplete.sh
### scaffold... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rails g scaffold CountryOfOrigin name ctype fdate:datetime active_status:integer sort_order:integer -f
rails g scaffold Pfeature name fdate:datetime active_status:integer sort_order:integer -f
rails g scaffold Product name pcolor country_of_origin:references pdate:datetime active_status:integer sort_order:integer -f
rails g scaffold ProductFeature name product:references pfeature:references active_status:integer sort_order:integer -f
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# How to add a column..
# http://stackoverflow.com/questions/22815009/add-a-reference-column-migration-in-rails-4
# rails g migration AddUserToUploads user:references
# rails g migration AddCountryOfOriginToProducts country_of_origin:references
# See howtoaddacolumn.txt in docs/
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sleep 1
git add -A # Add all files and commit them
git commit -m "scaffold"
### select2 for product pfeature.... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source $sfil2/select2.sh # optional
# commit is in select2.sh
source $sfil2/jqueryautocomplete.sh
source $sfil2/jqueryautocomplete_pcolor.sh
sleep 1
git add -A # Add all files and commit them
git commit -m "jquery-autocomplete-bigtunacan"
source $sfil2/activestorage.sh
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Copy migration files over..
path1='db/migrate'
mkdir -p $path1/
# rm -r $path1/
# rsync.. -a - rltpgoD preserve almost all. -u update don't copy older source files.
rsync -av --ignore-times $sfil2/$path1/ $path1/
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### db seed .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# if you want to seed specific pre-planned data...
# echo 'Product.create({name: "furniture"}) '>> db/seeds.rb
# rake db:reset
# rake db:drop
rake db:migrate
rake db:seed
sleep 1
git add -A # Add all files and commit them
git commit -m "seed"
### populate .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# populator gem seems to be too old to work now. Switch to seeder.rake task. See below.
# cat << HEREDOC > lib/tasks/populate.rake
# namespace :db do
# desc "fill database"
# task :populate => :environment do
# require 'populator'
# require 'faker'
# Product.populate 11 do |a12|
# a12.name = Faker::Commerce.product_name
# end
# CountryOfOrigin.populate 99 do |a12|
# a12.name = Faker::Address.country
# end
# Pfeature.populate 9 do |a12|
# a12.name = Faker::Commerce.color
# end
# end
# end
# HEREDOC
# rake db:populate
cat << HEREDOC > lib/tasks/seader.rake
# lib/tasks/seeder.rake
# https://stackoverflow.com/questions/19872271/adding-a-custom-seed-file
# usage: rake db:seeder
# seeds all files in db/seeds/*
desc "Run all files in db/seeds directory"
namespace :db do
task seeder: :environment do
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename|
puts "seeding - #{filename}. (see lib/tasks/seeder.rake)"
load(filename)
end
end
end
HEREDOC
mkdir -p db/seeds
cat << HEREDOC > db/seeds/seed3.rb
10.times do
CountryOfOrigin.create(
name: Faker::Address.country
)
end
10.times do
Pfeature.create(
name: Faker::Commerce.color
)
end
7.times do
Product.create(
name: Faker::Commerce.product_name,
country_of_origin_id: Faker::Number.within(range: 1..5)
)
end
HEREDOC
rake db:seeder
sleep 1
git add -A # Add all files and commit them
git commit -m "populate"
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Copy files over..
path1='empty'
pathtmp='/tmp/bashrail'
rm -rf $pathtmp; mkdir -p $pathtmp/
pathtarget='docs/generatedby' ;mkdir -p $pathtarget/
rsync -av --ignore-times $sfil2/ $pathtmp/
# rsync.. -a - rltpgoD preserve almost all. -u update don't copy older source files.
rm -rf $pathtmp/.git
zip -r /tmp/bashrail_copy.zip $pathtmp/*
# cp /tmp/bashrail_copy.zip $pathtarget
cp -av $sfil2/version* $pathtarget
cp -av $sfil2/root/.gitignore .
cp -av $sfil2/docker .
cp -av $sfil2/docker-com*.* .
cp -av $sfil2/Makefil* .
# cleanup
rm -rf $pathtmp
rm /tmp/bashrail_copy.zip
cat << HEREDOC > README.md
## $appn
This project was generated by bashrail. See the files in docs/generatedby for more info.
Also see https://github.com/dgleba/bashrail/tree/master/docsbr
If you clone this repo, You may need to:
```
cp config/database-example.yml config/database.yml
cp config/application-example.yml config/application.yml
cp config/secrets-example.yml config/secrets.yml
```
Check db/../..seeds*.rb for username and password.
HEREDOC
cp config/database.yml config/database-example.yml
cp config/application.yml config/application-example.yml
cp config/secrets.yml config/secrets-example.yml
sleep 1
git add -A # Add all files and commit them
git commit -m "add sqlite db and docs. Bashrail Finished."
### finish up.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set +vx
pwd
# echo '----------------------------------------> !!! Reached end of file !!!'
echo run rails s
echo then visit localhost:3000/
echo then visit localhost:3000/products
set +vx
#
# Done!....................
trap : 0
date
echo >&2 '
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!! DONE !!!**
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'