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