Mon, 28 Jan 2013 17:37:18 +0100
Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.
1 #!@l_prefix@/lib/openpkg/bash
2 ##
3 ## register -- OpenPKG Registry Command-Line Client
4 ## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
5 ##
6 ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
7 ## All rights reserved. Licenses which grant limited permission to use,
8 ## copy, modify and distribute this software are available from the
9 ## OpenPKG GmbH.
10 ##
11 ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
12 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
15 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
17 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
21 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 ## SUCH DAMAGE.
23 ##
25 ##
26 ## configuration
27 ##
29 # program name, version and date
30 progname="register"
31 progvers="1.1.3"
32 progdate="24-Aug-2007"
34 # determine path to OpenPKG instance
35 PREFIX="@l_prefix@"
36 if [ ".${OPENPKG_PREFIX}" != . ]; then
37 PREFIX="${OPENPKG_PREFIX}"
38 fi
40 # determine rpm
41 rpm="$PREFIX/libexec/openpkg/rpm"
42 [ -x "$PREFIX/lib/openpkg/rpm" ] && rpm="$PREFIX/lib/openpkg/rpm"
44 # http post
45 curl="$PREFIX/lib/openpkg/curl"
46 useragent="openpkg-$progname/$progvers"
48 error()
49 {
50 echo "$progname:ERROR: $@" 1>&2
51 exit 1
52 }
54 [ ".$PREFIX" = . ] && error "empty PREFIX not allowed"
56 ##
57 ## read configuration unless already done during option parsing
58 ##
59 sanitycheck()
60 {
61 if [ ".$1" != . -a -r "$1" ]; then
62 cat <"$1" | awk '
63 BEGIN { rc=0 }
64 !/^([A-Z][A-Z0-9_]+[A-Z0-9]="[^"]*")? *(#.*)?$/ { rc=1 }
65 END { exit rc }' && return 0
66 fi
67 return 1
68 }
70 readconf()
71 {
72 [ ".$REGISTRY_CONF" = . ] && return
73 if [ -r "$REGISTRY_CONF" ]; then
74 sanitycheck "$REGISTRY_CONF" && . "$REGISTRY_CONF"
75 fi
76 }
78 readuuid()
79 {
80 [ ".$REGISTRY_UUID" = . ] && return
81 if [ -r "$REGISTRY_UUID" ]; then
82 sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID"
83 fi
84 }
86 readutil()
87 {
88 [ ".$REGISTRY_UTIL" = . ] && return
89 if [ -r "$REGISTRY_UTIL" ]; then
90 sanitycheck "$REGISTRY_UTIL" && . "$REGISTRY_UTIL"
91 fi
92 }
94 ##
95 ## command line option parsing
96 ##
98 # default parameters
99 FQDN=`$PREFIX/lib/openpkg/shtool echo -e '%h%d'`
101 # primary operations
102 op="automatic"
104 # standard options
105 REGISTRY_AUTO="http://openpkg.org/go/autoregister"
106 REGISTRY_MODE="post"
107 REGISTRY_ARGS="http://registry.openpkg.org/register"
108 REGISTRY_USER=""
109 REGISTRY_LINK=""
110 REGISTRY_DESC="openpkg://${FQDN}${PREFIX}"
112 # advanced options
113 # we are called from rpm URL rewrite wrapper,
114 # so defer PLAT and OREL lookup to avoid rpm loop
115 REGISTRY_PLAT=""
116 REGISTRY_OREL=""
117 REGISTRY_UUID="$PREFIX/etc/openpkg/uuid"
118 REGISTRY_CONF="$PREFIX/etc/openpkg/register.conf"
119 REGISTRY_PREP="$PREFIX/etc/openpkg/register.prep"
120 REGISTRY_TRAN="$PREFIX/etc/openpkg/register.tran"
121 REGISTRY_UTIL="$PREFIX/etc/openpkg/register.util"
123 # amount of data being posted
124 REGISTRY_DATA="request,package,provides"
126 # read baseline config early and allow options to override contents
127 readconf
129 # debug options
130 verbose="no"
131 help="no"
133 # iterate over argument line
134 declare -a a
135 declare -i i=0
136 while [ $# -gt 0 ]; do
137 opt=$1
138 case $opt in
139 -*=*) arg=`echo "${opt}" | sed 's/^[-_a-zA-Z0-9]*=//'`
140 opt=`echo "${opt}" | sed 's/=.*//'`
141 ;;
142 *) arg='' ;;
143 esac
144 case $opt in
145 # primary operations
146 -P|--preparation ) op="preparation" ;;
147 -T|--transaction ) op="transaction" ;;
148 -U|--utilization ) op="utilization" ;;
149 -C|--convenience ) op="convenience" ;;
150 -I|--interaction ) op="interaction" ;;
152 # additional features
153 -S|--printstatus ) op="printstatus" ;;
154 -R|--rewriteurls ) op="rewriteurls" ;;
156 # standard options
157 -m|--mode )
158 if [ ".$arg" = . ]; then shift; arg="$1"; fi
159 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
160 REGISTRY_MODE="$arg"
161 ;;
162 -a|--args )
163 if [ ".$arg" = . ]; then shift; arg="$1"; fi
164 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
165 REGISTRY_ARGS="$arg"
166 ;;
167 -u|--user )
168 if [ ".$arg" = . ]; then shift; arg="$1"; fi
169 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
170 REGISTRY_USER="$arg"
171 ;;
172 -l|--link )
173 if [ ".$arg" = . ]; then shift; arg="$1"; fi
174 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
175 REGISTRY_LINK="$arg"
176 ;;
177 -d|--desc )
178 if [ ".$arg" = . ]; then shift; arg="$1"; fi
179 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
180 REGISTRY_DESC="$arg"
181 ;;
183 # advanced options
184 --plat )
185 if [ ".$arg" = . ]; then shift; arg="$1"; fi
186 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
187 REGISTRY_PLAT="$arg"
188 ;;
189 --orel )
190 if [ ".$arg" = . ]; then shift; arg="$1"; fi
191 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
192 REGISTRY_VERS="$arg"
193 ;;
194 --uuid )
195 if [ ".$arg" = . ]; then shift; arg="$1"; fi
196 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
197 REGISTRY_UUID="$arg"
198 ;;
199 --conf )
200 if [ ".$arg" = . ]; then shift; arg="$1"; fi
201 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
202 REGISTRY_CONF="$arg"; readconf
203 ;;
204 --prep )
205 if [ ".$arg" = . ]; then shift; arg="$1"; fi
206 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
207 REGISTRY_PREP="$arg"
208 ;;
209 --tran )
210 if [ ".$arg" = . ]; then shift; arg="$1"; fi
211 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
212 REGISTRY_TRAN="$arg"
213 ;;
214 --util )
215 if [ ".$arg" = . ]; then shift; arg="$1"; fi
216 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
217 REGISTRY_UTIL="$arg"
218 ;;
219 --data )
220 if [ ".$arg" = . ]; then shift; arg="$1"; fi
221 if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
222 REGISTRY_DATA="$arg"
223 ;;
225 # debug options
226 -v|--verbose ) verbose="yes" ;;
227 -h|--help ) help="Usage" ;;
228 -* ) help="Invalid option \`$opt'"; break ;;
230 # optional arguments
231 * ) a[$i]="$opt"
232 i=i+1
233 ;;
234 esac
235 shift
236 done
237 set -- "${a[@]}"
238 unset i a
240 # advanced options, lookup PLAT and OREL default for all modes
241 # but those called from rpm URL rewrite mapper
242 if [ $op != "printstatus" -a $op != "rewriteurls" ]; then
243 [ ".$REGISTRY_PLAT" = . ] && REGISTRY_PLAT="`$rpm --db-private --eval '%{l_platform -p}'`"
244 [ ".$REGISTRY_OREL" = . ] && REGISTRY_OREL="`$rpm --db-private --eval '%{l_openpkg_release}'`"
245 fi
247 # display error or usage message
248 if [ ".$help" != .no ]; then
249 if [ ".$help" != ".Usage" ]; then
250 echo "$progname:ERROR: $help" 1>&2
251 fi
252 echo "Usage: $progname [-u|--user=<user>] [-l|--link=<token>] [-d|--desc=<text>]"
253 echo " [-m|--mode=fake|post|wipe] [-a|--args=<args>]"
254 echo " [--plat=<text>] [--orel=<text>] [--uuid=<file>]"
255 echo " [--conf=<file>] [--prep=<file>] [--tran=<file>] [--util=<file>] [--data=<tag>[,<tag>...]]"
256 echo " [-P|--preparation] [-T|--transaction] [-U|--utilization]"
257 echo " [-C|--convenience] [-I|--interaction]"
258 echo " [-v|--verbose] [-h|--help]"
259 echo "Usage: $progname -S|--printstatus"
260 echo "Usage: $progname -R|--rewriteurls [[url]...]]"
261 if [ ".$help" != ".Usage" ]; then
262 exit 1
263 else
264 exit 0
265 fi
266 fi
268 ##
269 ## Primary operation Preparation
270 ##
271 preparation()
272 {
273 if [ ".$REGISTRY_MODE" = .wipe ]; then
274 if [ ".$REGISTRY_PREP" != . ]; then
275 if [ -f $REGISTRY_PREP ]; then
276 cat </dev/null >$REGISTRY_PREP
277 fi
278 fi
279 return
280 fi
282 [ ".$REGISTRY_USER" = . ] && error "missing information REGISTRY_USER"
283 [ ".$REGISTRY_DESC" = . ] && error "missing information REGISTRY_DESC"
284 [ ".$REGISTRY_PLAT" = . ] && error "missing information REGISTRY_PLAT"
285 [ ".$REGISTRY_OREL" = . ] && error "missing information REGISTRY_OREL"
286 [ ".$REGISTRY_UUID" = . ] && error "missing information REGISTRY_UUID"
287 [ ".$REGISTRY_PREP" = . ] && error "missing information REGISTRY_PREP"
289 if [ -r "$REGISTRY_UUID" ]; then
290 sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID"
291 fi
292 [ ".$UUID_REGISTRY" = . ] && error "missing information UUID_REGISTRY"
293 [ ".$UUID_INSTANCE" = . ] && error "missing information UUID_INSTANCE"
294 [ ".$UUID_PLATFORM" = . ] && error "missing information UUID_PLATFORM"
296 # amount of data being posted
297 Q='"'; I=" "; N=$'\n'; D=""
299 echo "$REGISTRY_DATA" | grep request >/dev/null
300 if [ $? = 0 ]; then
301 D="${D}<?xml version=${Q}1.0${Q} encoding=${Q}iso-8859-1${Q} standalone=${Q}no${Q}?>${N}"
302 D="${D}<!DOCTYPE registry${N}"
303 D="${D} PUBLIC ${Q}-//OpenPKG//DTD OpenPKG Registry 0.0.1//EN${Q}${N}"
304 D="${D} ${Q}http://registry.openpkg.org/registry.dtd${Q} []>${N}"
305 D="${D}<registry>${N}"
306 D="${D}${I}<request id=${Q}$UUID_REGISTRY${Q}${N}"
307 D="${D}${I}${I}registry_user=${Q}$REGISTRY_USER${Q}${N}"
308 [ ".$REGISTRY_LINK" != . ] && \
309 D="${D}${I}${I}registry_link=${Q}$REGISTRY_LINK${Q}${N}" # optional
310 D="${D}${I}${I}registry_desc=${Q}$REGISTRY_DESC${Q}${N}"
311 D="${D}${I}${I}registry_plat=${Q}$REGISTRY_PLAT${Q}${N}"
312 D="${D}${I}${I}registry_orel=${Q}$REGISTRY_OREL${Q}${N}"
313 D="${D}${I}${I}uuid_registry=${Q}$UUID_REGISTRY${Q}${N}"
314 D="${D}${I}${I}uuid_instance=${Q}$UUID_INSTANCE${Q}${N}"
315 D="${D}${I}${I}uuid_platform=${Q}$UUID_PLATFORM${Q}${N}"
317 echo "$REGISTRY_DATA" | grep package >/dev/null
318 if [ $? = 0 ]; then
319 D="${D}${I}>${N}"
320 F=""
321 F="${F}${I}${I}<package id=${Q}%{PKGID}${Q} name=${Q}%{NAME}${Q} version=${Q}%{VERSION}${Q} release=${Q}%{RELEASE}${Q}"
322 echo "$REGISTRY_DATA" | grep provides >/dev/null
323 if [ $? = 0 ]; then
324 F="${F}>\n"
325 F="${F}[${I}${I}${I}<provides name=${Q}%{PROVIDENAME}${Q} flag=${Q}%{PROVIDEFLAGS:depflags}${Q} version=${Q}%{PROVIDEVERSION}${Q}/>\n]"
326 F="${F}${I}${I}</package>\n"
327 else
328 F="${F}/>\n"
329 fi
330 D="${D}`$rpm --db-private --qf \"${F}\" -qa | sed '/<package id="(none)"/,/<\/package>/d'`${N}"
331 D="${D} </request>${N}"
332 else
333 D="${D}${I}/>${N}"
334 fi
335 D="${D}</registry>${N}"
336 fi
337 echo "$D" | tee $REGISTRY_PREP
338 }
340 ##
341 ## Primary operation Transaction
342 ##
343 transaction()
344 {
345 if [ ".$REGISTRY_MODE" = .wipe ]; then
346 if [ ".$REGISTRY_TRAN" != . ]; then
347 if [ -f $REGISTRY_TRAN ]; then
348 cat </dev/null >$REGISTRY_TRAN
349 fi
350 fi
351 return
352 fi
354 [ ".$REGISTRY_MODE" = . ] && error "missing information REGISTRY_MODE"
355 [ ".$REGISTRY_ARGS" = . ] && error "missing information REGISTRY_ARGS"
356 [ ".$REGISTRY_TRAN" = . ] && error "missing information REGISTRY_TRAN"
358 if [ ".$REGISTRY_MODE" = .fake ]; then
359 request=`awk '
360 BEGIN { registry=0 }
361 /<registry>/ { registry=1 }
362 /<request / { if (registry) { print $0 } }
363 /<\/registry>/ { registry=0 }' | \
364 sed -e 's;^.*<request id=";;' -e 's;"$;;'`
365 if [ ".$request" = . ]; then error "no request seen on stdin"; fi
366 (
367 echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"no\"?>"
368 echo "<!DOCTYPE registry"
369 echo " PUBLIC \"-//OpenPKG//DTD OpenPKG Registry 0.0.1//EN\""
370 echo " \"http://registry.openpkg.org/registry.dtd\" []>"
371 echo "<registry>"
372 echo " <response id=\"$request\" done=\"yes\">fake</response>"
373 echo "</registry>"
374 ) | tee $REGISTRY_TRAN
375 fi
377 if [ ".$REGISTRY_MODE" = .post ]; then
378 O=""
379 if [ $verbose = no ]; then O="$O --silent"; fi
380 $curl \
381 $O \
382 --user-agent "$useragent" \
383 --connect-timeout 15 \
384 --max-time 120 \
385 --form 'page=dropxml' \
386 --form 'data=<-' \
387 --form 'submit=DROPXML' \
388 $REGISTRY_ARGS \
389 | tee $REGISTRY_TRAN
390 fi
391 }
393 ##
394 ## Primary operation Utilization
395 ##
396 utilization()
397 {
398 if [ ".$REGISTRY_MODE" = .wipe ]; then
399 if [ ".$REGISTRY_UTIL" != . ]; then
400 if [ -f $REGISTRY_UTIL ]; then
401 cat </dev/null >$REGISTRY_UTIL
402 fi
403 fi
404 return
405 fi
407 [ ".$REGISTRY_UTIL" = . ] && error "missing information REGISTRY_UTIL"
409 response=`awk '
410 BEGIN { registry=0 }
411 /<registry>/ { registry=1 }
412 /<response / { if (registry) { print $0 } }
413 /<\/registry>/ { registry=0 }' | \
414 sed -e 's;^.*<response id=";;' -e 's;" done="; ;' -e 's;">; ;' -e 's;</response>.*$;;'`
415 if [ ".$response" = . ]; then error "no response seen on stdin"; fi
417 REGISTRY_DBID=`echo $response | awk '/./ { print $1 }'`
418 REGISTRY_DONE=`echo $response | awk '/./ { print $2 }'`
419 REGISTRY_RESP=`echo $response | sed -e 's;^[^ ][^ ]* [^ ][^ ]* ;;'`
421 [ ".$REGISTRY_DBID" = . ] && error "missing information REGISTRY_DBID"
422 [ ".$REGISTRY_DONE" = . ] && error "missing information REGISTRY_DONE"
423 [ ".$REGISTRY_RESP" = . ] && error "missing information REGISTRY_RESP"
425 (
426 echo "REGISTRY_DBID=\"$REGISTRY_DBID\""
427 echo "REGISTRY_DONE=\"$REGISTRY_DONE\""
428 echo "REGISTRY_RESP=\"$REGISTRY_RESP\""
429 ) | tee $REGISTRY_UTIL
430 }
432 ##
433 ## Automatic registration data retrieval
434 ##
435 autoregdata()
436 {
437 if [ ".$REGISTRY_AUTO" != . ]; then
438 O=""
439 if [ $verbose = no ]; then O="$O --silent"; fi
440 response=`$curl \
441 $O -L \
442 --user-agent "$useragent" \
443 --connect-timeout 8 \
444 --max-time 16 \
445 $REGISTRY_AUTO \
446 | awk '
447 BEGIN { registry=0 }
448 /<registry>/ { registry=1 }
449 /<autoregister / { if (registry) { print $0 } }
450 /<\/registry>/ { registry=0 }' \
451 | sed -e 's;^.*<autoregister *;;' -e 's;>[^>]*</autoregister>.*$;;' \
452 -e 's;\([^=]*\)="\([^"]*\)" *;\1="\2"\\
453 ;g' \
454 | awk -F= '/=/ { print "REGISTRY_"toupper($1)"="$2"" }'`
455 if [ $verbose = yes ]; then echo "autoregdata from $REGISTRY_AUTO"; echo "$response"; fi
456 eval "$response"
457 fi
458 }
460 ##
461 ## Primary operation Convenience
462 ##
463 convenience()
464 {
465 if [ ".$REGISTRY_MODE" = .wipe ]; then
466 utilization
467 transaction
468 preparation
469 return
470 fi
472 preparation | transaction | utilization
474 readutil || error "problem reading util"
475 if [ ".$REGISTRY_DONE" = .yes ]; then
476 echo "#`TZ= date '+%Y-%m-%d %H:%M:%S'` UTC" | tee "$REGISTRY_CONF" || return
477 (
478 echo "REGISTRY_USER=\"$REGISTRY_USER\""
479 echo "REGISTRY_LINK=\"$REGISTRY_LINK\""
480 echo "REGISTRY_DESC=\"$REGISTRY_DESC\""
481 echo "REGISTRY_PLAT=\"$REGISTRY_PLAT\""
482 echo "REGISTRY_OREL=\"$REGISTRY_OREL\""
483 echo "REGISTRY_UUID=\"$REGISTRY_UUID\""
484 echo "REGISTRY_PREP=\"$REGISTRY_PREP\""
485 echo "REGISTRY_MODE=\"$REGISTRY_MODE\""
486 echo "REGISTRY_ARGS=\"$REGISTRY_ARGS\""
487 echo "REGISTRY_TRAN=\"$REGISTRY_TRAN\""
488 echo "REGISTRY_UTIL=\"$REGISTRY_UTIL\""
489 ) | tee -a "$REGISTRY_CONF"
490 fi
491 }
493 ##
494 ## Primary operation Interaction
495 ##
496 interaction()
497 {
498 if [ ".$REGISTRY_MODE" = .wipe ]; then
499 if [ ".$REGISTRY_CONF" != . ]; then
500 if [ -f $REGISTRY_CONF ]; then
501 cat </dev/null >$REGISTRY_CONF
502 fi
503 fi
504 return
505 fi
507 echo "OpenPKG Registry Client ($useragent)"
508 echo ""
509 echo "Interactive step-by-step registration procedure."
510 echo "You can abort at any time by just pressing CTRL-C."
511 echo ""
512 echo "Registration is a three step process:"
513 echo "1. Preparation = create a configuration file and locally prepare a registration request"
514 echo "2. Transaction = run a transaction to submit the request to the registry"
515 echo "3. Utilization = memorize the response to activate local URL rewriting"
516 echo ""
517 echo "A (*) marks an optional field where the empty string \"\" is allowed."
518 echo "Just press RETURN to continue and/or keep a default setting."
520 echo ""
521 echo "==== Step 1/3: Preparation ===="
522 echo "Attempting to write to the configuration file \"$REGISTRY_CONF\""
523 echo "#`TZ= date '+%Y-%m-%d %H:%M:%S'` UTC" | tee -a "$REGISTRY_CONF" 2>/dev/null \
524 || error "Configuration file not writable. Get more permissions and try again"
526 read -p "[REGISTRY_USER=\"$REGISTRY_USER\"] username? "; [ ".$REPLY" != . ] && REGISTRY_USER="$REPLY"
527 read -p "[REGISTRY_DESC=\"$REGISTRY_DESC\"] description (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY"
528 read -p "[REGISTRY_PLAT=\"$REGISTRY_PLAT\"] platform (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY"
529 read -p "[REGISTRY_OREL=\"$REGISTRY_OREL\"] release (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY"
530 read -p "[REGISTRY_UUID=\"$REGISTRY_UUID\"] uuid file to read? "; [ ".$REPLY" != . ] && REGISTRY_UUID="$REPLY"
531 read -p "[REGISTRY_DATA=\"$REGISTRY_DATA\"] data to prepare? "; [ ".$REPLY" != . ] && REGISTRY_DATA="$REPLY"
532 read -p "[REGISTRY_PREP=\"$REGISTRY_PREP\"] prep dump file? "; [ ".$REPLY" != . ] && REGISTRY_PREP="$REPLY"
534 [ ".$REGISTRY_USER" = . ] && error "missing information REGISTRY_USER"
535 [ ".$REGISTRY_DESC" = . ] && error "missing information REGISTRY_DESC"
536 [ ".$REGISTRY_PLAT" = . ] && error "missing information REGISTRY_PLAT"
537 [ ".$REGISTRY_OREL" = . ] && error "missing information REGISTRY_OREL"
538 [ ".$REGISTRY_UUID" = . ] && error "missing information REGISTRY_UUID"
539 [ ".$REGISTRY_DATA" = . ] && error "missing information REGISTRY_DATA"
540 [ ".$REGISTRY_PREP" = . ] && error "missing information REGISTRY_PREP"
542 if [ -r "$REGISTRY_UUID" ]; then
543 sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID"
544 fi
545 [ ".$UUID_REGISTRY" = . ] && error "missing information UUID_REGISTRY"
546 [ ".$UUID_INSTANCE" = . ] && error "missing information UUID_INSTANCE"
547 [ ".$UUID_PLATFORM" = . ] && error "missing information UUID_PLATFORM"
549 echo "Appending to configuration file \"$REGISTRY_CONF\""
550 (
551 echo "REGISTRY_USER=\"$REGISTRY_USER\""
552 echo "REGISTRY_LINK=\"$REGISTRY_LINK\""
553 echo "REGISTRY_DESC=\"$REGISTRY_DESC\""
554 echo "REGISTRY_PLAT=\"$REGISTRY_PLAT\""
555 echo "REGISTRY_OREL=\"$REGISTRY_OREL\""
556 echo "REGISTRY_UUID=\"$REGISTRY_UUID\""
557 echo "REGISTRY_PREP=\"$REGISTRY_PREP\""
558 ) | tee -a "$REGISTRY_CONF"
560 preparation
562 echo ""
563 echo "==== Step 2/3: Transaction ===="
564 read -p "[REGISTRY_MODE=\"$REGISTRY_MODE\"] mode (post or fake)? "; [ ".$REPLY" != . ] && REGISTRY_MODE="$REPLY"
565 read -p "[REGISTRY_ARGS=\"$REGISTRY_ARGS\"] args? "; [ ".$REPLY" != . ] && REGISTRY_ARGS="$REPLY"
566 read -p "[REGISTRY_TRAN=\"$REGISTRY_TRAN\"] tran dump file? "; [ ".$REPLY" != . ] && REGISTRY_TRAN="$REPLY"
568 [ ".$REGISTRY_MODE" = . ] && error "missing information REGISTRY_MODE"
569 [ ".$REGISTRY_ARGS" = . ] && error "missing information REGISTRY_ARGS"
570 [ ".$REGISTRY_TRAN" = . ] && error "missing information REGISTRY_TRAN"
572 echo "Appending to configuration file \"$REGISTRY_CONF\""
573 (
574 echo "REGISTRY_MODE=\"$REGISTRY_MODE\""
575 echo "REGISTRY_ARGS=\"$REGISTRY_ARGS\""
576 echo "REGISTRY_TRAN=\"$REGISTRY_TRAN\""
577 ) | tee -a "$REGISTRY_CONF"
579 transaction <$REGISTRY_PREP
581 echo ""
582 echo "==== Step 3/3: Utilization ===="
583 read -p "[REGISTRY_UTIL=\"$REGISTRY_UTIL\"] util dump file? "; [ ".$REPLY" != . ] && REGISTRY_UTIL="$REPLY"
585 [ ".$REGISTRY_UTIL" = . ] && error "missing information REGISTRY_UTIL"
587 echo "Appending to configuration file \"$REGISTRY_CONF\""
588 (
589 echo "REGISTRY_UTIL=\"$REGISTRY_UTIL\""
590 ) | tee -a "$REGISTRY_CONF"
592 utilization <$REGISTRY_TRAN
593 }
595 ##
596 ## Additional feature printstatus
597 ##
598 printstatus()
599 {
600 rc=0
601 readconf || error "problem reading conf"
602 readuuid || error "problem reading uuid"
603 readutil || error "problem reading util"
604 if [ ".$REGISTRY_DONE" = .yes ]; then
605 cat "$REGISTRY_UTIL"
606 return 0
607 fi
608 return 1
609 }
611 ##
612 ## Additional feature rewriteurls
613 ##
614 rewriteurls()
615 {
616 readconf && readuuid && readutil || return $?
617 if [ ".$REGISTRY_DONE" = .yes ]; then
618 # URL rewriting
619 while [ ".$1" != . ]; do
620 printf '%s\n' "$1" | \
621 sed -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.com\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" \
622 -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.org\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" \
623 -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.net\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;"
624 shift
625 done
626 return 0
627 else
628 # stealth mode
629 return 1
630 fi
631 }
633 ##
634 ## check whether important configuration data is missing
635 ##
636 checkmissing()
637 {
638 missing=""
639 [ ".$REGISTRY_USER" = . ] && missing="$missing REGISTRY_USER"
640 [ ".$REGISTRY_DESC" = . ] && missing="$missing REGISTRY_DESC"
641 [ ".$REGISTRY_PLAT" = . ] && missing="$missing REGISTRY_PLAT"
642 [ ".$REGISTRY_OREL" = . ] && missing="$missing REGISTRY_OREL"
643 [ ".$REGISTRY_UUID" = . ] && missing="$missing REGISTRY_UUID"
644 [ ".$REGISTRY_PREP" = . ] && missing="$missing REGISTRY_PREP"
645 [ ".$REGISTRY_MODE" = . ] && missing="$missing REGISTRY_MODE"
646 [ ".$REGISTRY_ARGS" = . ] && missing="$missing REGISTRY_ARGS"
647 [ ".$REGISTRY_TRAN" = . ] && missing="$missing REGISTRY_TRAN"
648 [ ".$REGISTRY_UTIL" = . ] && missing="$missing REGISTRY_UTIL"
649 }
651 ##
652 ## automatically pick interaction or convenience
653 ##
654 automatic()
655 {
656 if [ ".$REGISTRY_MODE" = .wipe ]; then
657 convenience
658 interaction
659 return
660 fi
662 checkmissing
663 if [ ".$missing" != . ]; then
664 autoregdata
665 fi
667 checkmissing
668 if [ ".$missing" = . ]; then
669 convenience
670 else
671 tty -s || return
672 echo "missing $missing"
673 interaction
674 fi
675 }
677 ##
678 ## primary operation switch
679 ##
680 eval $op "\"$@\""
681 exit $?
683 ##
684 ## MANUAL PAGE
685 ##