Merge lp:~jontai/openvista-gtm-integration/bug363080 into lp:openvista-gtm-integration
- bug363080
- Merge into mainline
Proposed by
Jon Tai
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~jontai/openvista-gtm-integration/bug363080 |
Merge into: | lp:openvista-gtm-integration |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~jontai/openvista-gtm-integration/bug363080 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
jeff.apple | Approve | ||
Review via email: mp+5706@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Jon Tai (jontai) wrote : | # |
> Looks good.
> The only corner case would be if the newline conversion converts within a
> string for a global value. I'm guessing that never happens with this data, the
> underlying tools may not support it anyway, it isn't a bad thing anyway, etc.
In ZWR format, a newline within a global is escaped with $C(...). I'm not sure what the other formats do, but if a newline shows up unescaped, it's going to confuse %RI/%GI anyway. So I don't think we're doing anything wrong here.
I'm going to commit.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'packages/rpm/openvista-utils.spec' | |||
2 | --- packages/rpm/openvista-utils.spec 2009-04-18 01:54:22 +0000 | |||
3 | +++ packages/rpm/openvista-utils.spec 2009-04-20 08:35:31 +0000 | |||
4 | @@ -51,6 +51,7 @@ | |||
5 | 51 | install scripts/usr/bin/ovtied %{buildroot}%{_bindir}/ | 51 | install scripts/usr/bin/ovtied %{buildroot}%{_bindir}/ |
6 | 52 | install scripts/usr/bin/ovbackup %{buildroot}%{_bindir}/ | 52 | install scripts/usr/bin/ovbackup %{buildroot}%{_bindir}/ |
7 | 53 | install scripts/usr/bin/ovpurgejournals %{buildroot}%{_bindir}/ | 53 | install scripts/usr/bin/ovpurgejournals %{buildroot}%{_bindir}/ |
8 | 54 | install scripts/usr/bin/ovimport %{buildroot}%{_bindir}/ | ||
9 | 54 | 55 | ||
10 | 55 | install -d %{buildroot}%{_sysconfdir}/rc.d/init.d/ | 56 | install -d %{buildroot}%{_sysconfdir}/rc.d/init.d/ |
11 | 56 | install scripts/etc/init.d/openvista-databases %{buildroot}%{_sysconfdir}/rc.d/init.d/ | 57 | install scripts/etc/init.d/openvista-databases %{buildroot}%{_sysconfdir}/rc.d/init.d/ |
12 | @@ -81,6 +82,7 @@ | |||
13 | 81 | %{_bindir}/ovtied | 82 | %{_bindir}/ovtied |
14 | 82 | %{_bindir}/ovbackup | 83 | %{_bindir}/ovbackup |
15 | 83 | %{_bindir}/ovpurgejournals | 84 | %{_bindir}/ovpurgejournals |
16 | 85 | %{_bindir}/ovimport | ||
17 | 84 | %{_sysconfdir}/rc.d/init.d/openvista-databases | 86 | %{_sysconfdir}/rc.d/init.d/openvista-databases |
18 | 85 | %{_sysconfdir}/rc.d/init.d/openvista | 87 | %{_sysconfdir}/rc.d/init.d/openvista |
19 | 86 | %{_sysconfdir}/bash_completion.d/openvista | 88 | %{_sysconfdir}/bash_completion.d/openvista |
20 | 87 | 89 | ||
21 | === added file 'scripts/usr/bin/ovimport' | |||
22 | --- scripts/usr/bin/ovimport 1970-01-01 00:00:00 +0000 | |||
23 | +++ scripts/usr/bin/ovimport 2009-04-20 08:35:23 +0000 | |||
24 | @@ -0,0 +1,274 @@ | |||
25 | 1 | #!/bin/bash | ||
26 | 2 | |||
27 | 3 | # This script imports routines and globals into a new OpenVista instance. | ||
28 | 4 | |||
29 | 5 | |||
30 | 6 | # Copyright (C) 2009 Medsphere Systems Corporation | ||
31 | 7 | # | ||
32 | 8 | # This program is free software; you can redistribute it and/or modify it solely | ||
33 | 9 | # under the terms of the GNU Affero General Public License version 3 as published | ||
34 | 10 | # by the Free Software Foundation. | ||
35 | 11 | # | ||
36 | 12 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
37 | 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
38 | 14 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | ||
39 | 15 | # for more details. | ||
40 | 16 | # | ||
41 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
42 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses>. | ||
43 | 19 | # | ||
44 | 20 | # You can contact Medsphere Systems Corporation headquarters at 1917 Palomar | ||
45 | 21 | # Oaks Way, Suite 200, Carlsbad, CA 92008 or at legal@medsphere.com. | ||
46 | 22 | |||
47 | 23 | |||
48 | 24 | # common functions | ||
49 | 25 | . /usr/lib/openvista/functions | ||
50 | 26 | |||
51 | 27 | # parse arguments | ||
52 | 28 | while getopts hqfr:g: option; do | ||
53 | 29 | case $option in | ||
54 | 30 | h) | ||
55 | 31 | echo "Usage: ovimport [-q] [-f] [-r ROUTINES] [-g GLOBALS] INSTANCE_NAME" | ||
56 | 32 | echo " or ovimport -h" | ||
57 | 33 | echo | ||
58 | 34 | echo " -q quiet; suppress status messages" | ||
59 | 35 | echo " -f force; import routines and globals even if target instance is not empty" | ||
60 | 36 | echo " -r path to routine export file, archive, or directory" | ||
61 | 37 | echo " -g path to global export file or archive" | ||
62 | 38 | echo " -h display this help text" | ||
63 | 39 | exit 0 | ||
64 | 40 | ;; | ||
65 | 41 | q) | ||
66 | 42 | skip_status=true | ||
67 | 43 | ;; | ||
68 | 44 | f) | ||
69 | 45 | force=true | ||
70 | 46 | ;; | ||
71 | 47 | r) | ||
72 | 48 | routines=$OPTARG | ||
73 | 49 | ;; | ||
74 | 50 | g) | ||
75 | 51 | globals=$OPTARG | ||
76 | 52 | ;; | ||
77 | 53 | esac | ||
78 | 54 | done | ||
79 | 55 | shift `expr $OPTIND - 1` | ||
80 | 56 | |||
81 | 57 | : ${skip_status:=false} | ||
82 | 58 | : ${force:=false} | ||
83 | 59 | real_routines=$routines | ||
84 | 60 | real_globals=$globals | ||
85 | 61 | |||
86 | 62 | # check command syntax | ||
87 | 63 | if [ -z "$1" ]; then | ||
88 | 64 | echo "ovimport: missing operand" >&2 | ||
89 | 65 | echo "Try 'ovimport -h' for more information" >&2 | ||
90 | 66 | exit 2 | ||
91 | 67 | fi | ||
92 | 68 | |||
93 | 69 | # check permissions | ||
94 | 70 | in_groups || { | ||
95 | 71 | echo "ovimport: permission denied" >&2 | ||
96 | 72 | exit 1 | ||
97 | 73 | } | ||
98 | 74 | |||
99 | 75 | # check for for valid arguments (requires correct permissions to do; must happen after permission checks) | ||
100 | 76 | set_gtm_env "$1" || { | ||
101 | 77 | echo "ovimport: $instance: Not an OpenVista instance" >&2 | ||
102 | 78 | exit 3 | ||
103 | 79 | } | ||
104 | 80 | |||
105 | 81 | if [ -z "$routines" ] && [ -z "$globals" ]; then | ||
106 | 82 | echo "ovimport: No routines or globals specified; please use -r ROUTINES, -g GLOBALS, or both" >&2 | ||
107 | 83 | exit 3 | ||
108 | 84 | fi | ||
109 | 85 | |||
110 | 86 | if [ "0x0000000000000001" != `dse dump -fileheader 2>&1 | grep -F 'Current transaction' | awk '{ print $3 }'` ]; then | ||
111 | 87 | $force || { | ||
112 | 88 | echo "ovimport: $instance: OpenVista instance is not new; use -f to force" | ||
113 | 89 | exit 1 | ||
114 | 90 | } | ||
115 | 91 | fi | ||
116 | 92 | |||
117 | 93 | if [ `find "$root/$instance/routines" -type f -name '*.m' | wc -l` -ne 0 ]; then | ||
118 | 94 | $force || { | ||
119 | 95 | echo "ovimport: $instance: OpenVista instance is not new; use -f to force" | ||
120 | 96 | exit 1 | ||
121 | 97 | } | ||
122 | 98 | fi | ||
123 | 99 | |||
124 | 100 | # we can't use a subshell to isolate the umask call because $tempdir wouldn't | ||
125 | 101 | # survive, so save/restore the umask instead | ||
126 | 102 | old_umask=`umask` | ||
127 | 103 | umask 077 | ||
128 | 104 | tempdir=`mktemp -d -p "$root/$instance/tmp" .ovimport.XXXXXXXXXX` || | ||
129 | 105 | exit_with_error "ovimport" "Unable to create temporary directory" | ||
130 | 106 | umask "$old_umask" | ||
131 | 107 | |||
132 | 108 | # the EXIT handler may or may not run if we're interrupted or killed depending | ||
133 | 109 | # on the shell used (from what I've read, it does run on bash, but not on | ||
134 | 110 | # dash); use $exit to exit with the correct status in both cases | ||
135 | 111 | trap '[ -z "$exit" ] && rm -rf "$tempdir"; exit ${exit:-0}' EXIT | ||
136 | 112 | |||
137 | 113 | trap 'print_status "ovimport" "Caught SIGINT, exiting" "$skip_status"; rm -rf "$tempdir"; exit ${exit:=130}' INT | ||
138 | 114 | trap 'print_status "ovimport" "Caught SIGTERM, exiting" "$skip_status"; rm -rf "$tempdir"; exit ${exit:=143}' TERM | ||
139 | 115 | |||
140 | 116 | if [ -n "$routines" ]; then | ||
141 | 117 | if [ -f "$routines" ]; then | ||
142 | 118 | # FIXME: handle compressed files | ||
143 | 119 | |||
144 | 120 | routines_format="RO" | ||
145 | 121 | |||
146 | 122 | if grep -E $'\r$' "$routines" > /dev/null; then | ||
147 | 123 | routines_convert_newlines=true | ||
148 | 124 | fi | ||
149 | 125 | elif [ -d "$routines" ]; then | ||
150 | 126 | if [ `find "$routines" -type f -name '*.m' | wc -l` -ne 0 ]; then | ||
151 | 127 | routines_format="M" | ||
152 | 128 | else | ||
153 | 129 | echo "ovimport: $routines: Directory does not contain .m files" >&2 | ||
154 | 130 | exit 1 | ||
155 | 131 | fi | ||
156 | 132 | else | ||
157 | 133 | echo "ovimport: $routines: No such file or directory" >&2 | ||
158 | 134 | exit 3 | ||
159 | 135 | fi | ||
160 | 136 | fi | ||
161 | 137 | |||
162 | 138 | if [ -n "$globals" ]; then | ||
163 | 139 | if [ -f "$globals" ]; then | ||
164 | 140 | # FIXME: handle compressed files | ||
165 | 141 | |||
166 | 142 | if awk '{ if (NR == 3) { print $0; exit 0 } }' "$globals" | grep -F '=' > /dev/null; then | ||
167 | 143 | globals_format=ZWR | ||
168 | 144 | else | ||
169 | 145 | globals_format=GO | ||
170 | 146 | fi | ||
171 | 147 | |||
172 | 148 | if grep -E $'\r$' "$globals" > /dev/null; then | ||
173 | 149 | globals_convert_newlines=true | ||
174 | 150 | fi | ||
175 | 151 | else | ||
176 | 152 | echo "ovimport: $globals: No such file" >&2 | ||
177 | 153 | exit 3 | ||
178 | 154 | fi | ||
179 | 155 | fi | ||
180 | 156 | |||
181 | 157 | if [ -n "$routines" ]; then | ||
182 | 158 | print_status "ovimport" "Starting load of $routines into $instance" "$skip_status" | ||
183 | 159 | |||
184 | 160 | print_status "ovimport" "Routines are in $routines_format format" "$skip_status" | ||
185 | 161 | |||
186 | 162 | if ${routines_convert_newlines:-false}; then | ||
187 | 163 | print_status "ovimport" "Converting file to UNIX-style line endings" "$skip_status" | ||
188 | 164 | |||
189 | 165 | real_routines=$tempdir/ovimport.ro | ||
190 | 166 | |||
191 | 167 | { | ||
192 | 168 | cp "$routines" "$real_routines" && | ||
193 | 169 | perl -pi -we 's/\r\n/\n/' "$real_routines" | ||
194 | 170 | } || exit_with_error "ovimport" "Unable to convert file to UNIX-style line endings" | ||
195 | 171 | fi | ||
196 | 172 | |||
197 | 173 | case $routines_format in | ||
198 | 174 | RO) | ||
199 | 175 | print_status "ovimport" "Loading routines using ^%RI" "$skip_status" | ||
200 | 176 | |||
201 | 177 | # convert $real_routines into an absolute path, since %RI may run | ||
202 | 178 | # with a different cwd than this script | ||
203 | 179 | dirname=`dirname "$real_routines"` | ||
204 | 180 | basename=`basename "$real_routines"` | ||
205 | 181 | real_routines=`cd "$dirname"; pwd`/"$basename" | ||
206 | 182 | |||
207 | 183 | # redirect output to a temporary file because we need to both log | ||
208 | 184 | # the output and inspect it to determine success | ||
209 | 185 | ( | ||
210 | 186 | umask 007 | ||
211 | 187 | mumps -run ^%RI > "$tempdir/ovimport.ri" 2>&1 <<EOF | ||
212 | 188 | N | ||
213 | 189 | $real_routines | ||
214 | 190 | $root/$instance/routines/ | ||
215 | 191 | EOF | ||
216 | 192 | ) | ||
217 | 193 | |||
218 | 194 | cat "$tempdir/ovimport.ri" \ | ||
219 | 195 | | grep -v '^$' \ | ||
220 | 196 | | logger -p user.info -t "ovimport[$$]" | ||
221 | 197 | |||
222 | 198 | grep '^Restored [0-9]\{1,\} lines in [0-9]\{1,\} routines' "$tempdir/ovimport.ri" > /dev/null || | ||
223 | 199 | exit_with_error "ovimport" "Unable to import routines" | ||
224 | 200 | ;; | ||
225 | 201 | M) | ||
226 | 202 | print_status "ovimport" "Copying routines" "$skip_status" | ||
227 | 203 | |||
228 | 204 | # use install to copy routines instead of cp because install allows | ||
229 | 205 | # setting the permissions at the same time | ||
230 | 206 | find "$real_routines" -type f -name '*.m' -exec install -m 660 {} "$root/$instance/routines/" \; || | ||
231 | 207 | exit_with_error "ovimport" "Unable to import routines" | ||
232 | 208 | ;; | ||
233 | 209 | esac | ||
234 | 210 | |||
235 | 211 | print_status "ovimport" "Compiling routines" "$skip_status" | ||
236 | 212 | |||
237 | 213 | ( | ||
238 | 214 | umask 007 | ||
239 | 215 | cd "$root/$instance/objects" && | ||
240 | 216 | find "$root/$instance/routines" -type f -name '*.m' -exec mumps {} \; 2> /dev/null | ||
241 | 217 | ) || exit_with_error "ovimport" "Unable to compile routines" | ||
242 | 218 | |||
243 | 219 | print_status "ovimport" "Finished loading $routines into $instance" "$skip_status" | ||
244 | 220 | fi | ||
245 | 221 | |||
246 | 222 | if [ -n "$globals" ]; then | ||
247 | 223 | print_status "ovimport" "Starting load of $globals into $instance" "$skip_status" | ||
248 | 224 | |||
249 | 225 | print_status "ovimport" "Globals are in $globals_format format" "$skip_status" | ||
250 | 226 | |||
251 | 227 | if ${globals_convert_newlines:-false}; then | ||
252 | 228 | print_status "ovimport" "Converting file to UNIX-style line endings" "$skip_status" | ||
253 | 229 | |||
254 | 230 | real_globals=$tempdir/ovimport.go | ||
255 | 231 | |||
256 | 232 | { | ||
257 | 233 | cp "$globals" "$real_globals" && | ||
258 | 234 | perl -pi -we 's/\r\n/\n/' "$real_globals" | ||
259 | 235 | } || exit_with_error "ovimport" "Unable to convert file to UNIX-style line endings" | ||
260 | 236 | fi | ||
261 | 237 | |||
262 | 238 | # disabling journaling while "mupip load" runs saves about a minute. this | ||
263 | 239 | # is pretty safe to do, since we check that the database is empty before we | ||
264 | 240 | # load, so even if the system crashes and the database is destroyed, we can | ||
265 | 241 | # just create a new one and run ovimport again. if -f was given, do not | ||
266 | 242 | # disable journaling because the database may have other data in it worth | ||
267 | 243 | # protecting | ||
268 | 244 | $force || { | ||
269 | 245 | print_status "ovimport" "Temporarily disabling journaling" "$skip_status" | ||
270 | 246 | mupip set -journal="OFF" -region DEFAULT 2>&1 \ | ||
271 | 247 | | grep -v '^$' \ | ||
272 | 248 | | logger -p user.info -t "ovimport[$$]" | ||
273 | 249 | } | ||
274 | 250 | |||
275 | 251 | print_status "ovimport" "Loading globals using 'mupip load'" "$skip_status" | ||
276 | 252 | |||
277 | 253 | mupip load -format="$globals_format" "$real_globals" 2>&1 \ | ||
278 | 254 | | grep -v '^$' \ | ||
279 | 255 | | logger -p user.info -t "ovimport[$$]" | ||
280 | 256 | retval=${PIPESTATUS[0]} | ||
281 | 257 | [ $retval -eq 0 ] || { | ||
282 | 258 | exit_with_error "ovimport" "Unable to import globals" | ||
283 | 259 | } | ||
284 | 260 | |||
285 | 261 | $force || { | ||
286 | 262 | print_status "ovimport" "Re-enabling journaling" "$skip_status" | ||
287 | 263 | mupip set -journal="ON,BEFORE_IMAGES" -region DEFAULT 2>&1 \ | ||
288 | 264 | | grep -v '^$' \ | ||
289 | 265 | | logger -p user.info -t "ovimport[$$]" | ||
290 | 266 | retval=${PIPESTATUS[0]} | ||
291 | 267 | [ $retval -eq 0 ] || { | ||
292 | 268 | exit_with_error "ovimport" "Unable to re-enable journaling" | ||
293 | 269 | } | ||
294 | 270 | } | ||
295 | 271 | |||
296 | 272 | print_status "ovimport" "Finished loading $globals into $instance" "$skip_status" | ||
297 | 273 | fi | ||
298 | 274 | |||
299 | 0 | 275 | ||
300 | === modified file 'scripts/usr/sbin/ovinstanceadd' | |||
301 | --- scripts/usr/sbin/ovinstanceadd 2009-04-18 04:42:59 +0000 | |||
302 | +++ scripts/usr/sbin/ovinstanceadd 2009-04-20 05:53:54 +0000 | |||
303 | @@ -239,7 +239,7 @@ | |||
304 | 239 | | logger -p user.info -t "ovinstanceadd[$$]" | 239 | | logger -p user.info -t "ovinstanceadd[$$]" |
305 | 240 | retval=${PIPESTATUS[0]} | 240 | retval=${PIPESTATUS[0]} |
306 | 241 | [ $retval -eq 0 ] || { | 241 | [ $retval -eq 0 ] || { |
308 | 242 | echo "ovinstanceadd: Unable to enable journaling for region DEFAULT" >&2 | 242 | echo "ovinstanceadd: Unable to enable journaling" >&2 |
309 | 243 | exit 1 | 243 | exit 1 |
310 | 244 | } | 244 | } |
311 | 245 | 245 | ||
312 | 246 | 246 | ||
313 | === modified file 'scripts/usr/sbin/ovrestore' | |||
314 | --- scripts/usr/sbin/ovrestore 2009-04-18 04:42:59 +0000 | |||
315 | +++ scripts/usr/sbin/ovrestore 2009-04-20 08:35:23 +0000 | |||
316 | @@ -188,12 +188,14 @@ | |||
317 | 188 | rsync -a --delete --exclude 'lost+found' "$tempdir/routines/" "$root/$instance/routines/" | 188 | rsync -a --delete --exclude 'lost+found' "$tempdir/routines/" "$root/$instance/routines/" |
318 | 189 | } || exit_with_error "ovrestore" "Unable to restore routines" | 189 | } || exit_with_error "ovrestore" "Unable to restore routines" |
319 | 190 | 190 | ||
320 | 191 | print_status "ovrestore" "Compiling routines" "$skip_status" | ||
321 | 192 | |||
322 | 191 | ( | 193 | ( |
323 | 192 | umask 007 | 194 | umask 007 |
324 | 193 | find "$root/$instance/objects" -type f -name '*.o' -exec rm -f {} \; && | 195 | find "$root/$instance/objects" -type f -name '*.o' -exec rm -f {} \; && |
325 | 194 | cd "$root/$instance/objects" && | 196 | cd "$root/$instance/objects" && |
326 | 195 | find "$root/$instance/routines" -type f -name '*.m' -exec mumps {} \; 2> /dev/null | 197 | find "$root/$instance/routines" -type f -name '*.m' -exec mumps {} \; 2> /dev/null |
328 | 196 | ) || exit_with_error "ovrestore" "Unable to recompile routines" | 198 | ) || exit_with_error "ovrestore" "Unable to compile routines" |
329 | 197 | 199 | ||
330 | 198 | # if we're not applying journals, shut off journaling on the old database so | 200 | # if we're not applying journals, shut off journaling on the old database so |
331 | 199 | # that there's a clean break, then move the journal file out of the way | 201 | # that there's a clean break, then move the journal file out of the way |
Looks good.
The only corner case would be if the newline conversion converts within a string for a global value. I'm guessing that never happens with this data, the underlying tools may not support it anyway, it isn't a bad thing anyway, etc.