1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/openpkg/register.sh Tue Jul 31 12:23:42 2012 +0200 1.3 @@ -0,0 +1,686 @@ 1.4 +#!@l_prefix@/lib/openpkg/bash 1.5 +## 1.6 +## register -- OpenPKG Registry Command-Line Client 1.7 +## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/> 1.8 +## 1.9 +## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. 1.10 +## All rights reserved. Licenses which grant limited permission to use, 1.11 +## copy, modify and distribute this software are available from the 1.12 +## OpenPKG GmbH. 1.13 +## 1.14 +## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 1.15 +## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1.16 +## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1.17 +## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR 1.18 +## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.19 +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.20 +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 1.21 +## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 1.22 +## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 1.23 +## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 1.24 +## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1.25 +## SUCH DAMAGE. 1.26 +## 1.27 + 1.28 +## 1.29 +## configuration 1.30 +## 1.31 + 1.32 +# program name, version and date 1.33 +progname="register" 1.34 +progvers="1.1.3" 1.35 +progdate="24-Aug-2007" 1.36 + 1.37 +# determine path to OpenPKG instance 1.38 +PREFIX="@l_prefix@" 1.39 +if [ ".${OPENPKG_PREFIX}" != . ]; then 1.40 + PREFIX="${OPENPKG_PREFIX}" 1.41 +fi 1.42 + 1.43 +# determine rpm 1.44 +rpm="$PREFIX/libexec/openpkg/rpm" 1.45 +[ -x "$PREFIX/lib/openpkg/rpm" ] && rpm="$PREFIX/lib/openpkg/rpm" 1.46 + 1.47 +# http post 1.48 +curl="$PREFIX/lib/openpkg/curl" 1.49 +useragent="openpkg-$progname/$progvers" 1.50 + 1.51 +error() 1.52 +{ 1.53 + echo "$progname:ERROR: $@" 1>&2 1.54 + exit 1 1.55 +} 1.56 + 1.57 +[ ".$PREFIX" = . ] && error "empty PREFIX not allowed" 1.58 + 1.59 +## 1.60 +## read configuration unless already done during option parsing 1.61 +## 1.62 +sanitycheck() 1.63 +{ 1.64 + if [ ".$1" != . -a -r "$1" ]; then 1.65 + cat <"$1" | awk ' 1.66 + BEGIN { rc=0 } 1.67 + !/^([A-Z][A-Z0-9_]+[A-Z0-9]="[^"]*")? *(#.*)?$/ { rc=1 } 1.68 + END { exit rc }' && return 0 1.69 + fi 1.70 + return 1 1.71 +} 1.72 + 1.73 +readconf() 1.74 +{ 1.75 + [ ".$REGISTRY_CONF" = . ] && return 1.76 + if [ -r "$REGISTRY_CONF" ]; then 1.77 + sanitycheck "$REGISTRY_CONF" && . "$REGISTRY_CONF" 1.78 + fi 1.79 +} 1.80 + 1.81 +readuuid() 1.82 +{ 1.83 + [ ".$REGISTRY_UUID" = . ] && return 1.84 + if [ -r "$REGISTRY_UUID" ]; then 1.85 + sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID" 1.86 + fi 1.87 +} 1.88 + 1.89 +readutil() 1.90 +{ 1.91 + [ ".$REGISTRY_UTIL" = . ] && return 1.92 + if [ -r "$REGISTRY_UTIL" ]; then 1.93 + sanitycheck "$REGISTRY_UTIL" && . "$REGISTRY_UTIL" 1.94 + fi 1.95 +} 1.96 + 1.97 +## 1.98 +## command line option parsing 1.99 +## 1.100 + 1.101 +# default parameters 1.102 +FQDN=`$PREFIX/lib/openpkg/shtool echo -e '%h%d'` 1.103 + 1.104 +# primary operations 1.105 +op="automatic" 1.106 + 1.107 +# standard options 1.108 +REGISTRY_AUTO="http://openpkg.org/go/autoregister" 1.109 +REGISTRY_MODE="post" 1.110 +REGISTRY_ARGS="http://registry.openpkg.org/register" 1.111 +REGISTRY_USER="" 1.112 +REGISTRY_LINK="" 1.113 +REGISTRY_DESC="openpkg://${FQDN}${PREFIX}" 1.114 + 1.115 +# advanced options 1.116 +# we are called from rpm URL rewrite wrapper, 1.117 +# so defer PLAT and OREL lookup to avoid rpm loop 1.118 +REGISTRY_PLAT="" 1.119 +REGISTRY_OREL="" 1.120 +REGISTRY_UUID="$PREFIX/etc/openpkg/uuid" 1.121 +REGISTRY_CONF="$PREFIX/etc/openpkg/register.conf" 1.122 +REGISTRY_PREP="$PREFIX/etc/openpkg/register.prep" 1.123 +REGISTRY_TRAN="$PREFIX/etc/openpkg/register.tran" 1.124 +REGISTRY_UTIL="$PREFIX/etc/openpkg/register.util" 1.125 + 1.126 +# amount of data being posted 1.127 +REGISTRY_DATA="request,package,provides" 1.128 + 1.129 +# read baseline config early and allow options to override contents 1.130 +readconf 1.131 + 1.132 +# debug options 1.133 +verbose="no" 1.134 +help="no" 1.135 + 1.136 +# iterate over argument line 1.137 +declare -a a 1.138 +declare -i i=0 1.139 +while [ $# -gt 0 ]; do 1.140 + opt=$1 1.141 + case $opt in 1.142 + -*=*) arg=`echo "${opt}" | sed 's/^[-_a-zA-Z0-9]*=//'` 1.143 + opt=`echo "${opt}" | sed 's/=.*//'` 1.144 + ;; 1.145 + *) arg='' ;; 1.146 + esac 1.147 + case $opt in 1.148 + # primary operations 1.149 + -P|--preparation ) op="preparation" ;; 1.150 + -T|--transaction ) op="transaction" ;; 1.151 + -U|--utilization ) op="utilization" ;; 1.152 + -C|--convenience ) op="convenience" ;; 1.153 + -I|--interaction ) op="interaction" ;; 1.154 + 1.155 + # additional features 1.156 + -S|--printstatus ) op="printstatus" ;; 1.157 + -R|--rewriteurls ) op="rewriteurls" ;; 1.158 + 1.159 + # standard options 1.160 + -m|--mode ) 1.161 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.162 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.163 + REGISTRY_MODE="$arg" 1.164 + ;; 1.165 + -a|--args ) 1.166 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.167 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.168 + REGISTRY_ARGS="$arg" 1.169 + ;; 1.170 + -u|--user ) 1.171 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.172 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.173 + REGISTRY_USER="$arg" 1.174 + ;; 1.175 + -l|--link ) 1.176 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.177 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.178 + REGISTRY_LINK="$arg" 1.179 + ;; 1.180 + -d|--desc ) 1.181 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.182 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.183 + REGISTRY_DESC="$arg" 1.184 + ;; 1.185 + 1.186 + # advanced options 1.187 + --plat ) 1.188 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.189 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.190 + REGISTRY_PLAT="$arg" 1.191 + ;; 1.192 + --orel ) 1.193 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.194 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.195 + REGISTRY_VERS="$arg" 1.196 + ;; 1.197 + --uuid ) 1.198 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.199 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.200 + REGISTRY_UUID="$arg" 1.201 + ;; 1.202 + --conf ) 1.203 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.204 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.205 + REGISTRY_CONF="$arg"; readconf 1.206 + ;; 1.207 + --prep ) 1.208 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.209 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.210 + REGISTRY_PREP="$arg" 1.211 + ;; 1.212 + --tran ) 1.213 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.214 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.215 + REGISTRY_TRAN="$arg" 1.216 + ;; 1.217 + --util ) 1.218 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.219 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.220 + REGISTRY_UTIL="$arg" 1.221 + ;; 1.222 + --data ) 1.223 + if [ ".$arg" = . ]; then shift; arg="$1"; fi 1.224 + if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi 1.225 + REGISTRY_DATA="$arg" 1.226 + ;; 1.227 + 1.228 + # debug options 1.229 + -v|--verbose ) verbose="yes" ;; 1.230 + -h|--help ) help="Usage" ;; 1.231 + -* ) help="Invalid option \`$opt'"; break ;; 1.232 + 1.233 + # optional arguments 1.234 + * ) a[$i]="$opt" 1.235 + i=i+1 1.236 + ;; 1.237 + esac 1.238 + shift 1.239 +done 1.240 +set -- "${a[@]}" 1.241 +unset i a 1.242 + 1.243 +# advanced options, lookup PLAT and OREL default for all modes 1.244 +# but those called from rpm URL rewrite mapper 1.245 +if [ $op != "printstatus" -a $op != "rewriteurls" ]; then 1.246 + [ ".$REGISTRY_PLAT" = . ] && REGISTRY_PLAT="`$rpm --db-private --eval '%{l_platform -p}'`" 1.247 + [ ".$REGISTRY_OREL" = . ] && REGISTRY_OREL="`$rpm --db-private --eval '%{l_openpkg_release}'`" 1.248 +fi 1.249 + 1.250 +# display error or usage message 1.251 +if [ ".$help" != .no ]; then 1.252 + if [ ".$help" != ".Usage" ]; then 1.253 + echo "$progname:ERROR: $help" 1>&2 1.254 + fi 1.255 + echo "Usage: $progname [-u|--user=<user>] [-l|--link=<token>] [-d|--desc=<text>]" 1.256 + echo " [-m|--mode=fake|post|wipe] [-a|--args=<args>]" 1.257 + echo " [--plat=<text>] [--orel=<text>] [--uuid=<file>]" 1.258 + echo " [--conf=<file>] [--prep=<file>] [--tran=<file>] [--util=<file>] [--data=<tag>[,<tag>...]]" 1.259 + echo " [-P|--preparation] [-T|--transaction] [-U|--utilization]" 1.260 + echo " [-C|--convenience] [-I|--interaction]" 1.261 + echo " [-v|--verbose] [-h|--help]" 1.262 + echo "Usage: $progname -S|--printstatus" 1.263 + echo "Usage: $progname -R|--rewriteurls [[url]...]]" 1.264 + if [ ".$help" != ".Usage" ]; then 1.265 + exit 1 1.266 + else 1.267 + exit 0 1.268 + fi 1.269 +fi 1.270 + 1.271 +## 1.272 +## Primary operation Preparation 1.273 +## 1.274 +preparation() 1.275 +{ 1.276 + if [ ".$REGISTRY_MODE" = .wipe ]; then 1.277 + if [ ".$REGISTRY_PREP" != . ]; then 1.278 + if [ -f $REGISTRY_PREP ]; then 1.279 + cat </dev/null >$REGISTRY_PREP 1.280 + fi 1.281 + fi 1.282 + return 1.283 + fi 1.284 + 1.285 + [ ".$REGISTRY_USER" = . ] && error "missing information REGISTRY_USER" 1.286 + [ ".$REGISTRY_DESC" = . ] && error "missing information REGISTRY_DESC" 1.287 + [ ".$REGISTRY_PLAT" = . ] && error "missing information REGISTRY_PLAT" 1.288 + [ ".$REGISTRY_OREL" = . ] && error "missing information REGISTRY_OREL" 1.289 + [ ".$REGISTRY_UUID" = . ] && error "missing information REGISTRY_UUID" 1.290 + [ ".$REGISTRY_PREP" = . ] && error "missing information REGISTRY_PREP" 1.291 + 1.292 + if [ -r "$REGISTRY_UUID" ]; then 1.293 + sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID" 1.294 + fi 1.295 + [ ".$UUID_REGISTRY" = . ] && error "missing information UUID_REGISTRY" 1.296 + [ ".$UUID_INSTANCE" = . ] && error "missing information UUID_INSTANCE" 1.297 + [ ".$UUID_PLATFORM" = . ] && error "missing information UUID_PLATFORM" 1.298 + 1.299 + # amount of data being posted 1.300 + Q='"'; I=" "; N=$'\n'; D="" 1.301 + 1.302 + echo "$REGISTRY_DATA" | grep request >/dev/null 1.303 + if [ $? = 0 ]; then 1.304 + D="${D}<?xml version=${Q}1.0${Q} encoding=${Q}iso-8859-1${Q} standalone=${Q}no${Q}?>${N}" 1.305 + D="${D}<!DOCTYPE registry${N}" 1.306 + D="${D} PUBLIC ${Q}-//OpenPKG//DTD OpenPKG Registry 0.0.1//EN${Q}${N}" 1.307 + D="${D} ${Q}http://registry.openpkg.org/registry.dtd${Q} []>${N}" 1.308 + D="${D}<registry>${N}" 1.309 + D="${D}${I}<request id=${Q}$UUID_REGISTRY${Q}${N}" 1.310 + D="${D}${I}${I}registry_user=${Q}$REGISTRY_USER${Q}${N}" 1.311 + [ ".$REGISTRY_LINK" != . ] && \ 1.312 + D="${D}${I}${I}registry_link=${Q}$REGISTRY_LINK${Q}${N}" # optional 1.313 + D="${D}${I}${I}registry_desc=${Q}$REGISTRY_DESC${Q}${N}" 1.314 + D="${D}${I}${I}registry_plat=${Q}$REGISTRY_PLAT${Q}${N}" 1.315 + D="${D}${I}${I}registry_orel=${Q}$REGISTRY_OREL${Q}${N}" 1.316 + D="${D}${I}${I}uuid_registry=${Q}$UUID_REGISTRY${Q}${N}" 1.317 + D="${D}${I}${I}uuid_instance=${Q}$UUID_INSTANCE${Q}${N}" 1.318 + D="${D}${I}${I}uuid_platform=${Q}$UUID_PLATFORM${Q}${N}" 1.319 + 1.320 + echo "$REGISTRY_DATA" | grep package >/dev/null 1.321 + if [ $? = 0 ]; then 1.322 + D="${D}${I}>${N}" 1.323 + F="" 1.324 + F="${F}${I}${I}<package id=${Q}%{PKGID}${Q} name=${Q}%{NAME}${Q} version=${Q}%{VERSION}${Q} release=${Q}%{RELEASE}${Q}" 1.325 + echo "$REGISTRY_DATA" | grep provides >/dev/null 1.326 + if [ $? = 0 ]; then 1.327 + F="${F}>\n" 1.328 + F="${F}[${I}${I}${I}<provides name=${Q}%{PROVIDENAME}${Q} flag=${Q}%{PROVIDEFLAGS:depflags}${Q} version=${Q}%{PROVIDEVERSION}${Q}/>\n]" 1.329 + F="${F}${I}${I}</package>\n" 1.330 + else 1.331 + F="${F}/>\n" 1.332 + fi 1.333 + D="${D}`$rpm --db-private --qf \"${F}\" -qa | sed '/<package id="(none)"/,/<\/package>/d'`${N}" 1.334 + D="${D} </request>${N}" 1.335 + else 1.336 + D="${D}${I}/>${N}" 1.337 + fi 1.338 + D="${D}</registry>${N}" 1.339 + fi 1.340 + echo "$D" | tee $REGISTRY_PREP 1.341 +} 1.342 + 1.343 +## 1.344 +## Primary operation Transaction 1.345 +## 1.346 +transaction() 1.347 +{ 1.348 + if [ ".$REGISTRY_MODE" = .wipe ]; then 1.349 + if [ ".$REGISTRY_TRAN" != . ]; then 1.350 + if [ -f $REGISTRY_TRAN ]; then 1.351 + cat </dev/null >$REGISTRY_TRAN 1.352 + fi 1.353 + fi 1.354 + return 1.355 + fi 1.356 + 1.357 + [ ".$REGISTRY_MODE" = . ] && error "missing information REGISTRY_MODE" 1.358 + [ ".$REGISTRY_ARGS" = . ] && error "missing information REGISTRY_ARGS" 1.359 + [ ".$REGISTRY_TRAN" = . ] && error "missing information REGISTRY_TRAN" 1.360 + 1.361 + if [ ".$REGISTRY_MODE" = .fake ]; then 1.362 + request=`awk ' 1.363 + BEGIN { registry=0 } 1.364 + /<registry>/ { registry=1 } 1.365 + /<request / { if (registry) { print $0 } } 1.366 + /<\/registry>/ { registry=0 }' | \ 1.367 + sed -e 's;^.*<request id=";;' -e 's;"$;;'` 1.368 + if [ ".$request" = . ]; then error "no request seen on stdin"; fi 1.369 + ( 1.370 + echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"no\"?>" 1.371 + echo "<!DOCTYPE registry" 1.372 + echo " PUBLIC \"-//OpenPKG//DTD OpenPKG Registry 0.0.1//EN\"" 1.373 + echo " \"http://registry.openpkg.org/registry.dtd\" []>" 1.374 + echo "<registry>" 1.375 + echo " <response id=\"$request\" done=\"yes\">fake</response>" 1.376 + echo "</registry>" 1.377 + ) | tee $REGISTRY_TRAN 1.378 + fi 1.379 + 1.380 + if [ ".$REGISTRY_MODE" = .post ]; then 1.381 + O="" 1.382 + if [ $verbose = no ]; then O="$O --silent"; fi 1.383 + $curl \ 1.384 + $O \ 1.385 + --user-agent "$useragent" \ 1.386 + --connect-timeout 15 \ 1.387 + --max-time 120 \ 1.388 + --form 'page=dropxml' \ 1.389 + --form 'data=<-' \ 1.390 + --form 'submit=DROPXML' \ 1.391 + $REGISTRY_ARGS \ 1.392 + | tee $REGISTRY_TRAN 1.393 + fi 1.394 +} 1.395 + 1.396 +## 1.397 +## Primary operation Utilization 1.398 +## 1.399 +utilization() 1.400 +{ 1.401 + if [ ".$REGISTRY_MODE" = .wipe ]; then 1.402 + if [ ".$REGISTRY_UTIL" != . ]; then 1.403 + if [ -f $REGISTRY_UTIL ]; then 1.404 + cat </dev/null >$REGISTRY_UTIL 1.405 + fi 1.406 + fi 1.407 + return 1.408 + fi 1.409 + 1.410 + [ ".$REGISTRY_UTIL" = . ] && error "missing information REGISTRY_UTIL" 1.411 + 1.412 + response=`awk ' 1.413 + BEGIN { registry=0 } 1.414 + /<registry>/ { registry=1 } 1.415 + /<response / { if (registry) { print $0 } } 1.416 + /<\/registry>/ { registry=0 }' | \ 1.417 + sed -e 's;^.*<response id=";;' -e 's;" done="; ;' -e 's;">; ;' -e 's;</response>.*$;;'` 1.418 + if [ ".$response" = . ]; then error "no response seen on stdin"; fi 1.419 + 1.420 + REGISTRY_DBID=`echo $response | awk '/./ { print $1 }'` 1.421 + REGISTRY_DONE=`echo $response | awk '/./ { print $2 }'` 1.422 + REGISTRY_RESP=`echo $response | sed -e 's;^[^ ][^ ]* [^ ][^ ]* ;;'` 1.423 + 1.424 + [ ".$REGISTRY_DBID" = . ] && error "missing information REGISTRY_DBID" 1.425 + [ ".$REGISTRY_DONE" = . ] && error "missing information REGISTRY_DONE" 1.426 + [ ".$REGISTRY_RESP" = . ] && error "missing information REGISTRY_RESP" 1.427 + 1.428 + ( 1.429 + echo "REGISTRY_DBID=\"$REGISTRY_DBID\"" 1.430 + echo "REGISTRY_DONE=\"$REGISTRY_DONE\"" 1.431 + echo "REGISTRY_RESP=\"$REGISTRY_RESP\"" 1.432 + ) | tee $REGISTRY_UTIL 1.433 +} 1.434 + 1.435 +## 1.436 +## Automatic registration data retrieval 1.437 +## 1.438 +autoregdata() 1.439 +{ 1.440 + if [ ".$REGISTRY_AUTO" != . ]; then 1.441 + O="" 1.442 + if [ $verbose = no ]; then O="$O --silent"; fi 1.443 + response=`$curl \ 1.444 + $O -L \ 1.445 + --user-agent "$useragent" \ 1.446 + --connect-timeout 8 \ 1.447 + --max-time 16 \ 1.448 + $REGISTRY_AUTO \ 1.449 + | awk ' 1.450 + BEGIN { registry=0 } 1.451 + /<registry>/ { registry=1 } 1.452 + /<autoregister / { if (registry) { print $0 } } 1.453 + /<\/registry>/ { registry=0 }' \ 1.454 + | sed -e 's;^.*<autoregister *;;' -e 's;>[^>]*</autoregister>.*$;;' \ 1.455 + -e 's;\([^=]*\)="\([^"]*\)" *;\1="\2"\\ 1.456 +;g' \ 1.457 + | awk -F= '/=/ { print "REGISTRY_"toupper($1)"="$2"" }'` 1.458 + if [ $verbose = yes ]; then echo "autoregdata from $REGISTRY_AUTO"; echo "$response"; fi 1.459 + eval "$response" 1.460 + fi 1.461 +} 1.462 + 1.463 +## 1.464 +## Primary operation Convenience 1.465 +## 1.466 +convenience() 1.467 +{ 1.468 + if [ ".$REGISTRY_MODE" = .wipe ]; then 1.469 + utilization 1.470 + transaction 1.471 + preparation 1.472 + return 1.473 + fi 1.474 + 1.475 + preparation | transaction | utilization 1.476 + 1.477 + readutil || error "problem reading util" 1.478 + if [ ".$REGISTRY_DONE" = .yes ]; then 1.479 + echo "#`TZ= date '+%Y-%m-%d %H:%M:%S'` UTC" | tee "$REGISTRY_CONF" || return 1.480 + ( 1.481 + echo "REGISTRY_USER=\"$REGISTRY_USER\"" 1.482 + echo "REGISTRY_LINK=\"$REGISTRY_LINK\"" 1.483 + echo "REGISTRY_DESC=\"$REGISTRY_DESC\"" 1.484 + echo "REGISTRY_PLAT=\"$REGISTRY_PLAT\"" 1.485 + echo "REGISTRY_OREL=\"$REGISTRY_OREL\"" 1.486 + echo "REGISTRY_UUID=\"$REGISTRY_UUID\"" 1.487 + echo "REGISTRY_PREP=\"$REGISTRY_PREP\"" 1.488 + echo "REGISTRY_MODE=\"$REGISTRY_MODE\"" 1.489 + echo "REGISTRY_ARGS=\"$REGISTRY_ARGS\"" 1.490 + echo "REGISTRY_TRAN=\"$REGISTRY_TRAN\"" 1.491 + echo "REGISTRY_UTIL=\"$REGISTRY_UTIL\"" 1.492 + ) | tee -a "$REGISTRY_CONF" 1.493 + fi 1.494 +} 1.495 + 1.496 +## 1.497 +## Primary operation Interaction 1.498 +## 1.499 +interaction() 1.500 +{ 1.501 + if [ ".$REGISTRY_MODE" = .wipe ]; then 1.502 + if [ ".$REGISTRY_CONF" != . ]; then 1.503 + if [ -f $REGISTRY_CONF ]; then 1.504 + cat </dev/null >$REGISTRY_CONF 1.505 + fi 1.506 + fi 1.507 + return 1.508 + fi 1.509 + 1.510 + echo "OpenPKG Registry Client ($useragent)" 1.511 + echo "" 1.512 + echo "Interactive step-by-step registration procedure." 1.513 + echo "You can abort at any time by just pressing CTRL-C." 1.514 + echo "" 1.515 + echo "Registration is a three step process:" 1.516 + echo "1. Preparation = create a configuration file and locally prepare a registration request" 1.517 + echo "2. Transaction = run a transaction to submit the request to the registry" 1.518 + echo "3. Utilization = memorize the response to activate local URL rewriting" 1.519 + echo "" 1.520 + echo "A (*) marks an optional field where the empty string \"\" is allowed." 1.521 + echo "Just press RETURN to continue and/or keep a default setting." 1.522 + 1.523 + echo "" 1.524 + echo "==== Step 1/3: Preparation ====" 1.525 + echo "Attempting to write to the configuration file \"$REGISTRY_CONF\"" 1.526 + echo "#`TZ= date '+%Y-%m-%d %H:%M:%S'` UTC" | tee -a "$REGISTRY_CONF" 2>/dev/null \ 1.527 + || error "Configuration file not writable. Get more permissions and try again" 1.528 + 1.529 + read -p "[REGISTRY_USER=\"$REGISTRY_USER\"] username? "; [ ".$REPLY" != . ] && REGISTRY_USER="$REPLY" 1.530 + read -p "[REGISTRY_DESC=\"$REGISTRY_DESC\"] description (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY" 1.531 + read -p "[REGISTRY_PLAT=\"$REGISTRY_PLAT\"] platform (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY" 1.532 + read -p "[REGISTRY_OREL=\"$REGISTRY_OREL\"] release (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY" 1.533 + read -p "[REGISTRY_UUID=\"$REGISTRY_UUID\"] uuid file to read? "; [ ".$REPLY" != . ] && REGISTRY_UUID="$REPLY" 1.534 + read -p "[REGISTRY_DATA=\"$REGISTRY_DATA\"] data to prepare? "; [ ".$REPLY" != . ] && REGISTRY_DATA="$REPLY" 1.535 + read -p "[REGISTRY_PREP=\"$REGISTRY_PREP\"] prep dump file? "; [ ".$REPLY" != . ] && REGISTRY_PREP="$REPLY" 1.536 + 1.537 + [ ".$REGISTRY_USER" = . ] && error "missing information REGISTRY_USER" 1.538 + [ ".$REGISTRY_DESC" = . ] && error "missing information REGISTRY_DESC" 1.539 + [ ".$REGISTRY_PLAT" = . ] && error "missing information REGISTRY_PLAT" 1.540 + [ ".$REGISTRY_OREL" = . ] && error "missing information REGISTRY_OREL" 1.541 + [ ".$REGISTRY_UUID" = . ] && error "missing information REGISTRY_UUID" 1.542 + [ ".$REGISTRY_DATA" = . ] && error "missing information REGISTRY_DATA" 1.543 + [ ".$REGISTRY_PREP" = . ] && error "missing information REGISTRY_PREP" 1.544 + 1.545 + if [ -r "$REGISTRY_UUID" ]; then 1.546 + sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID" 1.547 + fi 1.548 + [ ".$UUID_REGISTRY" = . ] && error "missing information UUID_REGISTRY" 1.549 + [ ".$UUID_INSTANCE" = . ] && error "missing information UUID_INSTANCE" 1.550 + [ ".$UUID_PLATFORM" = . ] && error "missing information UUID_PLATFORM" 1.551 + 1.552 + echo "Appending to configuration file \"$REGISTRY_CONF\"" 1.553 + ( 1.554 + echo "REGISTRY_USER=\"$REGISTRY_USER\"" 1.555 + echo "REGISTRY_LINK=\"$REGISTRY_LINK\"" 1.556 + echo "REGISTRY_DESC=\"$REGISTRY_DESC\"" 1.557 + echo "REGISTRY_PLAT=\"$REGISTRY_PLAT\"" 1.558 + echo "REGISTRY_OREL=\"$REGISTRY_OREL\"" 1.559 + echo "REGISTRY_UUID=\"$REGISTRY_UUID\"" 1.560 + echo "REGISTRY_PREP=\"$REGISTRY_PREP\"" 1.561 + ) | tee -a "$REGISTRY_CONF" 1.562 + 1.563 + preparation 1.564 + 1.565 + echo "" 1.566 + echo "==== Step 2/3: Transaction ====" 1.567 + read -p "[REGISTRY_MODE=\"$REGISTRY_MODE\"] mode (post or fake)? "; [ ".$REPLY" != . ] && REGISTRY_MODE="$REPLY" 1.568 + read -p "[REGISTRY_ARGS=\"$REGISTRY_ARGS\"] args? "; [ ".$REPLY" != . ] && REGISTRY_ARGS="$REPLY" 1.569 + read -p "[REGISTRY_TRAN=\"$REGISTRY_TRAN\"] tran dump file? "; [ ".$REPLY" != . ] && REGISTRY_TRAN="$REPLY" 1.570 + 1.571 + [ ".$REGISTRY_MODE" = . ] && error "missing information REGISTRY_MODE" 1.572 + [ ".$REGISTRY_ARGS" = . ] && error "missing information REGISTRY_ARGS" 1.573 + [ ".$REGISTRY_TRAN" = . ] && error "missing information REGISTRY_TRAN" 1.574 + 1.575 + echo "Appending to configuration file \"$REGISTRY_CONF\"" 1.576 + ( 1.577 + echo "REGISTRY_MODE=\"$REGISTRY_MODE\"" 1.578 + echo "REGISTRY_ARGS=\"$REGISTRY_ARGS\"" 1.579 + echo "REGISTRY_TRAN=\"$REGISTRY_TRAN\"" 1.580 + ) | tee -a "$REGISTRY_CONF" 1.581 + 1.582 + transaction <$REGISTRY_PREP 1.583 + 1.584 + echo "" 1.585 + echo "==== Step 3/3: Utilization ====" 1.586 + read -p "[REGISTRY_UTIL=\"$REGISTRY_UTIL\"] util dump file? "; [ ".$REPLY" != . ] && REGISTRY_UTIL="$REPLY" 1.587 + 1.588 + [ ".$REGISTRY_UTIL" = . ] && error "missing information REGISTRY_UTIL" 1.589 + 1.590 + echo "Appending to configuration file \"$REGISTRY_CONF\"" 1.591 + ( 1.592 + echo "REGISTRY_UTIL=\"$REGISTRY_UTIL\"" 1.593 + ) | tee -a "$REGISTRY_CONF" 1.594 + 1.595 + utilization <$REGISTRY_TRAN 1.596 +} 1.597 + 1.598 +## 1.599 +## Additional feature printstatus 1.600 +## 1.601 +printstatus() 1.602 +{ 1.603 + rc=0 1.604 + readconf || error "problem reading conf" 1.605 + readuuid || error "problem reading uuid" 1.606 + readutil || error "problem reading util" 1.607 + if [ ".$REGISTRY_DONE" = .yes ]; then 1.608 + cat "$REGISTRY_UTIL" 1.609 + return 0 1.610 + fi 1.611 + return 1 1.612 +} 1.613 + 1.614 +## 1.615 +## Additional feature rewriteurls 1.616 +## 1.617 +rewriteurls() 1.618 +{ 1.619 + readconf && readuuid && readutil || return $? 1.620 + if [ ".$REGISTRY_DONE" = .yes ]; then 1.621 + # URL rewriting 1.622 + while [ ".$1" != . ]; do 1.623 + printf '%s\n' "$1" | \ 1.624 + sed -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.com\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" \ 1.625 + -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.org\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" \ 1.626 + -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.net\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" 1.627 + shift 1.628 + done 1.629 + return 0 1.630 + else 1.631 + # stealth mode 1.632 + return 1 1.633 + fi 1.634 +} 1.635 + 1.636 +## 1.637 +## check whether important configuration data is missing 1.638 +## 1.639 +checkmissing() 1.640 +{ 1.641 + missing="" 1.642 + [ ".$REGISTRY_USER" = . ] && missing="$missing REGISTRY_USER" 1.643 + [ ".$REGISTRY_DESC" = . ] && missing="$missing REGISTRY_DESC" 1.644 + [ ".$REGISTRY_PLAT" = . ] && missing="$missing REGISTRY_PLAT" 1.645 + [ ".$REGISTRY_OREL" = . ] && missing="$missing REGISTRY_OREL" 1.646 + [ ".$REGISTRY_UUID" = . ] && missing="$missing REGISTRY_UUID" 1.647 + [ ".$REGISTRY_PREP" = . ] && missing="$missing REGISTRY_PREP" 1.648 + [ ".$REGISTRY_MODE" = . ] && missing="$missing REGISTRY_MODE" 1.649 + [ ".$REGISTRY_ARGS" = . ] && missing="$missing REGISTRY_ARGS" 1.650 + [ ".$REGISTRY_TRAN" = . ] && missing="$missing REGISTRY_TRAN" 1.651 + [ ".$REGISTRY_UTIL" = . ] && missing="$missing REGISTRY_UTIL" 1.652 +} 1.653 + 1.654 +## 1.655 +## automatically pick interaction or convenience 1.656 +## 1.657 +automatic() 1.658 +{ 1.659 + if [ ".$REGISTRY_MODE" = .wipe ]; then 1.660 + convenience 1.661 + interaction 1.662 + return 1.663 + fi 1.664 + 1.665 + checkmissing 1.666 + if [ ".$missing" != . ]; then 1.667 + autoregdata 1.668 + fi 1.669 + 1.670 + checkmissing 1.671 + if [ ".$missing" = . ]; then 1.672 + convenience 1.673 + else 1.674 + tty -s || return 1.675 + echo "missing $missing" 1.676 + interaction 1.677 + fi 1.678 +} 1.679 + 1.680 +## 1.681 +## primary operation switch 1.682 +## 1.683 +eval $op "\"$@\"" 1.684 +exit $? 1.685 + 1.686 +## 1.687 +## MANUAL PAGE 1.688 +## 1.689 +