-
Notifications
You must be signed in to change notification settings - Fork 0
/
papertrail1.sh
executable file
·189 lines (134 loc) · 4.1 KB
/
papertrail1.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
#!/usr/bin/env bash
echo ~----------~----------Startingd $HOSTNAME, pwd: `pwd`, dlr0: "$0", bashsource0: "${BASH_SOURCE[0]}", $(date +"%Y-%m-%d_%H.%M.%S")
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# read settings..
read appn sfil sfil2 mpwd parm0</tmp/"_brvar1202_${USER}".txt
echo $appn $sfil $sfil2 $mpwd $parm0
# timeout1=5 ; read -t "${timeout1}" -p "Press ENTER or wait $timeout1 seconds..." || true ; echo ;
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "gem 'paper_trail'" >> Gemfile
bundle
git add -A # Add all files and commit them
git commit -m "paper_trail - 1"
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bundle exec rails generate paper_trail:install --with-changes --with-associations
bundle exec rake db:migrate
git add -A # Add all files and commit them
git commit -m "paper_trail - 2. install and migrate"
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# add new lines of text after patrn...
#
filetarg='app/models/user.rb'
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
repl2 = %Q{
has_paper_trail
}
ARGF.each do |line|
puts line
puts repl2 if line =~ /class /
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
# add new lines of text after patrn...
#
filetarg='app/controllers/application_controller.rb'
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
repl2 = %Q{
before_action :set_paper_trail_whodunnit
}
ARGF.each do |line|
puts line
puts repl2 if line =~ /class /
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
# uncomment line containing pattern...
#
filetarg='config/initializers/rails_admin.rb'
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
repl2 = %Q{
notused
}
ARGF.each do |line|
line.sub!('#','') if line =~ /config\.audit.*paper_trail/
puts line
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
# uncomment line containing pattern...
#
filetarg='config/initializers/rails_admin.rb'
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
repl2 = %Q{
notused
}
ARGF.each do |line|
line.sub!('#','') if line =~ /history_show/
puts line
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
# uncomment line containing pattern...
#
filetarg='config/initializers/rails_admin.rb'
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
repl2 = %Q{
notused
}
ARGF.each do |line|
line.sub!('#','') if line =~ /history_index/
puts line
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# add new lines of text after patrn...
#
filetarg='config/initializers/rails_admin.rb'
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
repl2 = %Q{
# == Devise ==
config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)
# == Cancan ==
config.authorize_with :cancan
}
ARGF.each do |line|
puts line
puts repl2 if line =~ /RailsAdmin.*config /
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
git add -A # Add all files and commit them
git commit -m "paper_trail - 3. setup"
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# To specify different table name..
# ftp://albe@pmdsdata3/srv/web/hrapp361/app/models/papertrail_table.rb
# #
# class PapertrailTable < PaperTrail::Version
# self.table_name = :versions_dc
# end
# ftp://albe@pmdsdata3/srv/web/hrapp361/app/models/pp_parkingpass.rb
# #
# class PpParkingpass < ApplicationRecord
# has_paper_trail class_name: 'PapertrailTable'
# end
# I have not figured out how to get rails_admin to play nice with that..
# It said table versions was not present.
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~