openpkg/register.sh

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

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

mercurial