michael@428: #!@l_prefix@/lib/openpkg/bash
michael@428: ##
michael@428: ## register -- OpenPKG Registry Command-Line Client
michael@428: ## Copyright (c) 2000-2012 OpenPKG GmbH
michael@428: ##
michael@428: ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
michael@428: ## All rights reserved. Licenses which grant limited permission to use,
michael@428: ## copy, modify and distribute this software are available from the
michael@428: ## OpenPKG GmbH.
michael@428: ##
michael@428: ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
michael@428: ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@428: ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@428: ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@428: ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@428: ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@428: ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@428: ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@428: ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@428: ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@428: ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@428: ## SUCH DAMAGE.
michael@428: ##
michael@428:
michael@428: ##
michael@428: ## configuration
michael@428: ##
michael@428:
michael@428: # program name, version and date
michael@428: progname="register"
michael@428: progvers="1.1.3"
michael@428: progdate="24-Aug-2007"
michael@428:
michael@428: # determine path to OpenPKG instance
michael@428: PREFIX="@l_prefix@"
michael@428: if [ ".${OPENPKG_PREFIX}" != . ]; then
michael@428: PREFIX="${OPENPKG_PREFIX}"
michael@428: fi
michael@428:
michael@428: # determine rpm
michael@428: rpm="$PREFIX/libexec/openpkg/rpm"
michael@428: [ -x "$PREFIX/lib/openpkg/rpm" ] && rpm="$PREFIX/lib/openpkg/rpm"
michael@428:
michael@428: # http post
michael@428: curl="$PREFIX/lib/openpkg/curl"
michael@428: useragent="openpkg-$progname/$progvers"
michael@428:
michael@428: error()
michael@428: {
michael@428: echo "$progname:ERROR: $@" 1>&2
michael@428: exit 1
michael@428: }
michael@428:
michael@428: [ ".$PREFIX" = . ] && error "empty PREFIX not allowed"
michael@428:
michael@428: ##
michael@428: ## read configuration unless already done during option parsing
michael@428: ##
michael@428: sanitycheck()
michael@428: {
michael@428: if [ ".$1" != . -a -r "$1" ]; then
michael@428: cat <"$1" | awk '
michael@428: BEGIN { rc=0 }
michael@428: !/^([A-Z][A-Z0-9_]+[A-Z0-9]="[^"]*")? *(#.*)?$/ { rc=1 }
michael@428: END { exit rc }' && return 0
michael@428: fi
michael@428: return 1
michael@428: }
michael@428:
michael@428: readconf()
michael@428: {
michael@428: [ ".$REGISTRY_CONF" = . ] && return
michael@428: if [ -r "$REGISTRY_CONF" ]; then
michael@428: sanitycheck "$REGISTRY_CONF" && . "$REGISTRY_CONF"
michael@428: fi
michael@428: }
michael@428:
michael@428: readuuid()
michael@428: {
michael@428: [ ".$REGISTRY_UUID" = . ] && return
michael@428: if [ -r "$REGISTRY_UUID" ]; then
michael@428: sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID"
michael@428: fi
michael@428: }
michael@428:
michael@428: readutil()
michael@428: {
michael@428: [ ".$REGISTRY_UTIL" = . ] && return
michael@428: if [ -r "$REGISTRY_UTIL" ]; then
michael@428: sanitycheck "$REGISTRY_UTIL" && . "$REGISTRY_UTIL"
michael@428: fi
michael@428: }
michael@428:
michael@428: ##
michael@428: ## command line option parsing
michael@428: ##
michael@428:
michael@428: # default parameters
michael@428: FQDN=`$PREFIX/lib/openpkg/shtool echo -e '%h%d'`
michael@428:
michael@428: # primary operations
michael@428: op="automatic"
michael@428:
michael@428: # standard options
michael@428: REGISTRY_AUTO="http://openpkg.org/go/autoregister"
michael@428: REGISTRY_MODE="post"
michael@428: REGISTRY_ARGS="http://registry.openpkg.org/register"
michael@428: REGISTRY_USER=""
michael@428: REGISTRY_LINK=""
michael@428: REGISTRY_DESC="openpkg://${FQDN}${PREFIX}"
michael@428:
michael@428: # advanced options
michael@428: # we are called from rpm URL rewrite wrapper,
michael@428: # so defer PLAT and OREL lookup to avoid rpm loop
michael@428: REGISTRY_PLAT=""
michael@428: REGISTRY_OREL=""
michael@428: REGISTRY_UUID="$PREFIX/etc/openpkg/uuid"
michael@428: REGISTRY_CONF="$PREFIX/etc/openpkg/register.conf"
michael@428: REGISTRY_PREP="$PREFIX/etc/openpkg/register.prep"
michael@428: REGISTRY_TRAN="$PREFIX/etc/openpkg/register.tran"
michael@428: REGISTRY_UTIL="$PREFIX/etc/openpkg/register.util"
michael@428:
michael@428: # amount of data being posted
michael@428: REGISTRY_DATA="request,package,provides"
michael@428:
michael@428: # read baseline config early and allow options to override contents
michael@428: readconf
michael@428:
michael@428: # debug options
michael@428: verbose="no"
michael@428: help="no"
michael@428:
michael@428: # iterate over argument line
michael@428: declare -a a
michael@428: declare -i i=0
michael@428: while [ $# -gt 0 ]; do
michael@428: opt=$1
michael@428: case $opt in
michael@428: -*=*) arg=`echo "${opt}" | sed 's/^[-_a-zA-Z0-9]*=//'`
michael@428: opt=`echo "${opt}" | sed 's/=.*//'`
michael@428: ;;
michael@428: *) arg='' ;;
michael@428: esac
michael@428: case $opt in
michael@428: # primary operations
michael@428: -P|--preparation ) op="preparation" ;;
michael@428: -T|--transaction ) op="transaction" ;;
michael@428: -U|--utilization ) op="utilization" ;;
michael@428: -C|--convenience ) op="convenience" ;;
michael@428: -I|--interaction ) op="interaction" ;;
michael@428:
michael@428: # additional features
michael@428: -S|--printstatus ) op="printstatus" ;;
michael@428: -R|--rewriteurls ) op="rewriteurls" ;;
michael@428:
michael@428: # standard options
michael@428: -m|--mode )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_MODE="$arg"
michael@428: ;;
michael@428: -a|--args )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_ARGS="$arg"
michael@428: ;;
michael@428: -u|--user )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_USER="$arg"
michael@428: ;;
michael@428: -l|--link )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_LINK="$arg"
michael@428: ;;
michael@428: -d|--desc )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_DESC="$arg"
michael@428: ;;
michael@428:
michael@428: # advanced options
michael@428: --plat )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_PLAT="$arg"
michael@428: ;;
michael@428: --orel )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_VERS="$arg"
michael@428: ;;
michael@428: --uuid )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_UUID="$arg"
michael@428: ;;
michael@428: --conf )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_CONF="$arg"; readconf
michael@428: ;;
michael@428: --prep )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_PREP="$arg"
michael@428: ;;
michael@428: --tran )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_TRAN="$arg"
michael@428: ;;
michael@428: --util )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_UTIL="$arg"
michael@428: ;;
michael@428: --data )
michael@428: if [ ".$arg" = . ]; then shift; arg="$1"; fi
michael@428: if [ ".$arg" = . ]; then help="Missing argument to \"$opt\""; break; fi
michael@428: REGISTRY_DATA="$arg"
michael@428: ;;
michael@428:
michael@428: # debug options
michael@428: -v|--verbose ) verbose="yes" ;;
michael@428: -h|--help ) help="Usage" ;;
michael@428: -* ) help="Invalid option \`$opt'"; break ;;
michael@428:
michael@428: # optional arguments
michael@428: * ) a[$i]="$opt"
michael@428: i=i+1
michael@428: ;;
michael@428: esac
michael@428: shift
michael@428: done
michael@428: set -- "${a[@]}"
michael@428: unset i a
michael@428:
michael@428: # advanced options, lookup PLAT and OREL default for all modes
michael@428: # but those called from rpm URL rewrite mapper
michael@428: if [ $op != "printstatus" -a $op != "rewriteurls" ]; then
michael@428: [ ".$REGISTRY_PLAT" = . ] && REGISTRY_PLAT="`$rpm --db-private --eval '%{l_platform -p}'`"
michael@428: [ ".$REGISTRY_OREL" = . ] && REGISTRY_OREL="`$rpm --db-private --eval '%{l_openpkg_release}'`"
michael@428: fi
michael@428:
michael@428: # display error or usage message
michael@428: if [ ".$help" != .no ]; then
michael@428: if [ ".$help" != ".Usage" ]; then
michael@428: echo "$progname:ERROR: $help" 1>&2
michael@428: fi
michael@428: echo "Usage: $progname [-u|--user=] [-l|--link=] [-d|--desc=]"
michael@428: echo " [-m|--mode=fake|post|wipe] [-a|--args=]"
michael@428: echo " [--plat=] [--orel=] [--uuid=]"
michael@428: echo " [--conf=] [--prep=] [--tran=] [--util=] [--data=[,...]]"
michael@428: echo " [-P|--preparation] [-T|--transaction] [-U|--utilization]"
michael@428: echo " [-C|--convenience] [-I|--interaction]"
michael@428: echo " [-v|--verbose] [-h|--help]"
michael@428: echo "Usage: $progname -S|--printstatus"
michael@428: echo "Usage: $progname -R|--rewriteurls [[url]...]]"
michael@428: if [ ".$help" != ".Usage" ]; then
michael@428: exit 1
michael@428: else
michael@428: exit 0
michael@428: fi
michael@428: fi
michael@428:
michael@428: ##
michael@428: ## Primary operation Preparation
michael@428: ##
michael@428: preparation()
michael@428: {
michael@428: if [ ".$REGISTRY_MODE" = .wipe ]; then
michael@428: if [ ".$REGISTRY_PREP" != . ]; then
michael@428: if [ -f $REGISTRY_PREP ]; then
michael@428: cat $REGISTRY_PREP
michael@428: fi
michael@428: fi
michael@428: return
michael@428: fi
michael@428:
michael@428: [ ".$REGISTRY_USER" = . ] && error "missing information REGISTRY_USER"
michael@428: [ ".$REGISTRY_DESC" = . ] && error "missing information REGISTRY_DESC"
michael@428: [ ".$REGISTRY_PLAT" = . ] && error "missing information REGISTRY_PLAT"
michael@428: [ ".$REGISTRY_OREL" = . ] && error "missing information REGISTRY_OREL"
michael@428: [ ".$REGISTRY_UUID" = . ] && error "missing information REGISTRY_UUID"
michael@428: [ ".$REGISTRY_PREP" = . ] && error "missing information REGISTRY_PREP"
michael@428:
michael@428: if [ -r "$REGISTRY_UUID" ]; then
michael@428: sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID"
michael@428: fi
michael@428: [ ".$UUID_REGISTRY" = . ] && error "missing information UUID_REGISTRY"
michael@428: [ ".$UUID_INSTANCE" = . ] && error "missing information UUID_INSTANCE"
michael@428: [ ".$UUID_PLATFORM" = . ] && error "missing information UUID_PLATFORM"
michael@428:
michael@428: # amount of data being posted
michael@428: Q='"'; I=" "; N=$'\n'; D=""
michael@428:
michael@428: echo "$REGISTRY_DATA" | grep request >/dev/null
michael@428: if [ $? = 0 ]; then
michael@428: D="${D}${N}"
michael@428: D="${D}${N}"
michael@428: D="${D}${N}"
michael@428: D="${D}${I}/dev/null
michael@428: if [ $? = 0 ]; then
michael@428: D="${D}${I}>${N}"
michael@428: F=""
michael@428: F="${F}${I}${I}/dev/null
michael@428: if [ $? = 0 ]; then
michael@428: F="${F}>\n"
michael@428: F="${F}[${I}${I}${I}\n]"
michael@428: F="${F}${I}${I}\n"
michael@428: else
michael@428: F="${F}/>\n"
michael@428: fi
michael@428: D="${D}`$rpm --db-private --qf \"${F}\" -qa | sed '//d'`${N}"
michael@428: D="${D} ${N}"
michael@428: else
michael@428: D="${D}${I}/>${N}"
michael@428: fi
michael@428: D="${D}${N}"
michael@428: fi
michael@428: echo "$D" | tee $REGISTRY_PREP
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Primary operation Transaction
michael@428: ##
michael@428: transaction()
michael@428: {
michael@428: if [ ".$REGISTRY_MODE" = .wipe ]; then
michael@428: if [ ".$REGISTRY_TRAN" != . ]; then
michael@428: if [ -f $REGISTRY_TRAN ]; then
michael@428: cat $REGISTRY_TRAN
michael@428: fi
michael@428: fi
michael@428: return
michael@428: fi
michael@428:
michael@428: [ ".$REGISTRY_MODE" = . ] && error "missing information REGISTRY_MODE"
michael@428: [ ".$REGISTRY_ARGS" = . ] && error "missing information REGISTRY_ARGS"
michael@428: [ ".$REGISTRY_TRAN" = . ] && error "missing information REGISTRY_TRAN"
michael@428:
michael@428: if [ ".$REGISTRY_MODE" = .fake ]; then
michael@428: request=`awk '
michael@428: BEGIN { registry=0 }
michael@428: // { registry=1 }
michael@428: // { registry=0 }' | \
michael@428: sed -e 's;^.*"
michael@428: echo ""
michael@428: echo ""
michael@428: echo " fake"
michael@428: echo ""
michael@428: ) | tee $REGISTRY_TRAN
michael@428: fi
michael@428:
michael@428: if [ ".$REGISTRY_MODE" = .post ]; then
michael@428: O=""
michael@428: if [ $verbose = no ]; then O="$O --silent"; fi
michael@428: $curl \
michael@428: $O \
michael@428: --user-agent "$useragent" \
michael@428: --connect-timeout 15 \
michael@428: --max-time 120 \
michael@428: --form 'page=dropxml' \
michael@428: --form 'data=<-' \
michael@428: --form 'submit=DROPXML' \
michael@428: $REGISTRY_ARGS \
michael@428: | tee $REGISTRY_TRAN
michael@428: fi
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Primary operation Utilization
michael@428: ##
michael@428: utilization()
michael@428: {
michael@428: if [ ".$REGISTRY_MODE" = .wipe ]; then
michael@428: if [ ".$REGISTRY_UTIL" != . ]; then
michael@428: if [ -f $REGISTRY_UTIL ]; then
michael@428: cat $REGISTRY_UTIL
michael@428: fi
michael@428: fi
michael@428: return
michael@428: fi
michael@428:
michael@428: [ ".$REGISTRY_UTIL" = . ] && error "missing information REGISTRY_UTIL"
michael@428:
michael@428: response=`awk '
michael@428: BEGIN { registry=0 }
michael@428: // { registry=1 }
michael@428: // { registry=0 }' | \
michael@428: sed -e 's;^.*; ;' -e 's;.*$;;'`
michael@428: if [ ".$response" = . ]; then error "no response seen on stdin"; fi
michael@428:
michael@428: REGISTRY_DBID=`echo $response | awk '/./ { print $1 }'`
michael@428: REGISTRY_DONE=`echo $response | awk '/./ { print $2 }'`
michael@428: REGISTRY_RESP=`echo $response | sed -e 's;^[^ ][^ ]* [^ ][^ ]* ;;'`
michael@428:
michael@428: [ ".$REGISTRY_DBID" = . ] && error "missing information REGISTRY_DBID"
michael@428: [ ".$REGISTRY_DONE" = . ] && error "missing information REGISTRY_DONE"
michael@428: [ ".$REGISTRY_RESP" = . ] && error "missing information REGISTRY_RESP"
michael@428:
michael@428: (
michael@428: echo "REGISTRY_DBID=\"$REGISTRY_DBID\""
michael@428: echo "REGISTRY_DONE=\"$REGISTRY_DONE\""
michael@428: echo "REGISTRY_RESP=\"$REGISTRY_RESP\""
michael@428: ) | tee $REGISTRY_UTIL
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Automatic registration data retrieval
michael@428: ##
michael@428: autoregdata()
michael@428: {
michael@428: if [ ".$REGISTRY_AUTO" != . ]; then
michael@428: O=""
michael@428: if [ $verbose = no ]; then O="$O --silent"; fi
michael@428: response=`$curl \
michael@428: $O -L \
michael@428: --user-agent "$useragent" \
michael@428: --connect-timeout 8 \
michael@428: --max-time 16 \
michael@428: $REGISTRY_AUTO \
michael@428: | awk '
michael@428: BEGIN { registry=0 }
michael@428: // { registry=1 }
michael@428: // { registry=0 }' \
michael@428: | sed -e 's;^.*[^>]*.*$;;' \
michael@428: -e 's;\([^=]*\)="\([^"]*\)" *;\1="\2"\\
michael@428: ;g' \
michael@428: | awk -F= '/=/ { print "REGISTRY_"toupper($1)"="$2"" }'`
michael@428: if [ $verbose = yes ]; then echo "autoregdata from $REGISTRY_AUTO"; echo "$response"; fi
michael@428: eval "$response"
michael@428: fi
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Primary operation Convenience
michael@428: ##
michael@428: convenience()
michael@428: {
michael@428: if [ ".$REGISTRY_MODE" = .wipe ]; then
michael@428: utilization
michael@428: transaction
michael@428: preparation
michael@428: return
michael@428: fi
michael@428:
michael@428: preparation | transaction | utilization
michael@428:
michael@428: readutil || error "problem reading util"
michael@428: if [ ".$REGISTRY_DONE" = .yes ]; then
michael@428: echo "#`TZ= date '+%Y-%m-%d %H:%M:%S'` UTC" | tee "$REGISTRY_CONF" || return
michael@428: (
michael@428: echo "REGISTRY_USER=\"$REGISTRY_USER\""
michael@428: echo "REGISTRY_LINK=\"$REGISTRY_LINK\""
michael@428: echo "REGISTRY_DESC=\"$REGISTRY_DESC\""
michael@428: echo "REGISTRY_PLAT=\"$REGISTRY_PLAT\""
michael@428: echo "REGISTRY_OREL=\"$REGISTRY_OREL\""
michael@428: echo "REGISTRY_UUID=\"$REGISTRY_UUID\""
michael@428: echo "REGISTRY_PREP=\"$REGISTRY_PREP\""
michael@428: echo "REGISTRY_MODE=\"$REGISTRY_MODE\""
michael@428: echo "REGISTRY_ARGS=\"$REGISTRY_ARGS\""
michael@428: echo "REGISTRY_TRAN=\"$REGISTRY_TRAN\""
michael@428: echo "REGISTRY_UTIL=\"$REGISTRY_UTIL\""
michael@428: ) | tee -a "$REGISTRY_CONF"
michael@428: fi
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Primary operation Interaction
michael@428: ##
michael@428: interaction()
michael@428: {
michael@428: if [ ".$REGISTRY_MODE" = .wipe ]; then
michael@428: if [ ".$REGISTRY_CONF" != . ]; then
michael@428: if [ -f $REGISTRY_CONF ]; then
michael@428: cat $REGISTRY_CONF
michael@428: fi
michael@428: fi
michael@428: return
michael@428: fi
michael@428:
michael@428: echo "OpenPKG Registry Client ($useragent)"
michael@428: echo ""
michael@428: echo "Interactive step-by-step registration procedure."
michael@428: echo "You can abort at any time by just pressing CTRL-C."
michael@428: echo ""
michael@428: echo "Registration is a three step process:"
michael@428: echo "1. Preparation = create a configuration file and locally prepare a registration request"
michael@428: echo "2. Transaction = run a transaction to submit the request to the registry"
michael@428: echo "3. Utilization = memorize the response to activate local URL rewriting"
michael@428: echo ""
michael@428: echo "A (*) marks an optional field where the empty string \"\" is allowed."
michael@428: echo "Just press RETURN to continue and/or keep a default setting."
michael@428:
michael@428: echo ""
michael@428: echo "==== Step 1/3: Preparation ===="
michael@428: echo "Attempting to write to the configuration file \"$REGISTRY_CONF\""
michael@428: echo "#`TZ= date '+%Y-%m-%d %H:%M:%S'` UTC" | tee -a "$REGISTRY_CONF" 2>/dev/null \
michael@428: || error "Configuration file not writable. Get more permissions and try again"
michael@428:
michael@428: read -p "[REGISTRY_USER=\"$REGISTRY_USER\"] username? "; [ ".$REPLY" != . ] && REGISTRY_USER="$REPLY"
michael@428: read -p "[REGISTRY_DESC=\"$REGISTRY_DESC\"] description (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY"
michael@428: read -p "[REGISTRY_PLAT=\"$REGISTRY_PLAT\"] platform (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY"
michael@428: read -p "[REGISTRY_OREL=\"$REGISTRY_OREL\"] release (*)? "; [ ".$REPLY" != . ] && REGISTRY_DESC="$REPLY"
michael@428: read -p "[REGISTRY_UUID=\"$REGISTRY_UUID\"] uuid file to read? "; [ ".$REPLY" != . ] && REGISTRY_UUID="$REPLY"
michael@428: read -p "[REGISTRY_DATA=\"$REGISTRY_DATA\"] data to prepare? "; [ ".$REPLY" != . ] && REGISTRY_DATA="$REPLY"
michael@428: read -p "[REGISTRY_PREP=\"$REGISTRY_PREP\"] prep dump file? "; [ ".$REPLY" != . ] && REGISTRY_PREP="$REPLY"
michael@428:
michael@428: [ ".$REGISTRY_USER" = . ] && error "missing information REGISTRY_USER"
michael@428: [ ".$REGISTRY_DESC" = . ] && error "missing information REGISTRY_DESC"
michael@428: [ ".$REGISTRY_PLAT" = . ] && error "missing information REGISTRY_PLAT"
michael@428: [ ".$REGISTRY_OREL" = . ] && error "missing information REGISTRY_OREL"
michael@428: [ ".$REGISTRY_UUID" = . ] && error "missing information REGISTRY_UUID"
michael@428: [ ".$REGISTRY_DATA" = . ] && error "missing information REGISTRY_DATA"
michael@428: [ ".$REGISTRY_PREP" = . ] && error "missing information REGISTRY_PREP"
michael@428:
michael@428: if [ -r "$REGISTRY_UUID" ]; then
michael@428: sanitycheck "$REGISTRY_UUID" && . "$REGISTRY_UUID"
michael@428: fi
michael@428: [ ".$UUID_REGISTRY" = . ] && error "missing information UUID_REGISTRY"
michael@428: [ ".$UUID_INSTANCE" = . ] && error "missing information UUID_INSTANCE"
michael@428: [ ".$UUID_PLATFORM" = . ] && error "missing information UUID_PLATFORM"
michael@428:
michael@428: echo "Appending to configuration file \"$REGISTRY_CONF\""
michael@428: (
michael@428: echo "REGISTRY_USER=\"$REGISTRY_USER\""
michael@428: echo "REGISTRY_LINK=\"$REGISTRY_LINK\""
michael@428: echo "REGISTRY_DESC=\"$REGISTRY_DESC\""
michael@428: echo "REGISTRY_PLAT=\"$REGISTRY_PLAT\""
michael@428: echo "REGISTRY_OREL=\"$REGISTRY_OREL\""
michael@428: echo "REGISTRY_UUID=\"$REGISTRY_UUID\""
michael@428: echo "REGISTRY_PREP=\"$REGISTRY_PREP\""
michael@428: ) | tee -a "$REGISTRY_CONF"
michael@428:
michael@428: preparation
michael@428:
michael@428: echo ""
michael@428: echo "==== Step 2/3: Transaction ===="
michael@428: read -p "[REGISTRY_MODE=\"$REGISTRY_MODE\"] mode (post or fake)? "; [ ".$REPLY" != . ] && REGISTRY_MODE="$REPLY"
michael@428: read -p "[REGISTRY_ARGS=\"$REGISTRY_ARGS\"] args? "; [ ".$REPLY" != . ] && REGISTRY_ARGS="$REPLY"
michael@428: read -p "[REGISTRY_TRAN=\"$REGISTRY_TRAN\"] tran dump file? "; [ ".$REPLY" != . ] && REGISTRY_TRAN="$REPLY"
michael@428:
michael@428: [ ".$REGISTRY_MODE" = . ] && error "missing information REGISTRY_MODE"
michael@428: [ ".$REGISTRY_ARGS" = . ] && error "missing information REGISTRY_ARGS"
michael@428: [ ".$REGISTRY_TRAN" = . ] && error "missing information REGISTRY_TRAN"
michael@428:
michael@428: echo "Appending to configuration file \"$REGISTRY_CONF\""
michael@428: (
michael@428: echo "REGISTRY_MODE=\"$REGISTRY_MODE\""
michael@428: echo "REGISTRY_ARGS=\"$REGISTRY_ARGS\""
michael@428: echo "REGISTRY_TRAN=\"$REGISTRY_TRAN\""
michael@428: ) | tee -a "$REGISTRY_CONF"
michael@428:
michael@428: transaction <$REGISTRY_PREP
michael@428:
michael@428: echo ""
michael@428: echo "==== Step 3/3: Utilization ===="
michael@428: read -p "[REGISTRY_UTIL=\"$REGISTRY_UTIL\"] util dump file? "; [ ".$REPLY" != . ] && REGISTRY_UTIL="$REPLY"
michael@428:
michael@428: [ ".$REGISTRY_UTIL" = . ] && error "missing information REGISTRY_UTIL"
michael@428:
michael@428: echo "Appending to configuration file \"$REGISTRY_CONF\""
michael@428: (
michael@428: echo "REGISTRY_UTIL=\"$REGISTRY_UTIL\""
michael@428: ) | tee -a "$REGISTRY_CONF"
michael@428:
michael@428: utilization <$REGISTRY_TRAN
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Additional feature printstatus
michael@428: ##
michael@428: printstatus()
michael@428: {
michael@428: rc=0
michael@428: readconf || error "problem reading conf"
michael@428: readuuid || error "problem reading uuid"
michael@428: readutil || error "problem reading util"
michael@428: if [ ".$REGISTRY_DONE" = .yes ]; then
michael@428: cat "$REGISTRY_UTIL"
michael@428: return 0
michael@428: fi
michael@428: return 1
michael@428: }
michael@428:
michael@428: ##
michael@428: ## Additional feature rewriteurls
michael@428: ##
michael@428: rewriteurls()
michael@428: {
michael@428: readconf && readuuid && readutil || return $?
michael@428: if [ ".$REGISTRY_DONE" = .yes ]; then
michael@428: # URL rewriting
michael@428: while [ ".$1" != . ]; do
michael@428: printf '%s\n' "$1" | \
michael@428: sed -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.com\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" \
michael@428: -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.org\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;" \
michael@428: -e "s;^\([^:/]*\)://\([^:/]*\.openpkg\.net\)/;\1://$UUID_REGISTRY:$UUID_INSTANCE.$UUID_PLATFORM@\2/;"
michael@428: shift
michael@428: done
michael@428: return 0
michael@428: else
michael@428: # stealth mode
michael@428: return 1
michael@428: fi
michael@428: }
michael@428:
michael@428: ##
michael@428: ## check whether important configuration data is missing
michael@428: ##
michael@428: checkmissing()
michael@428: {
michael@428: missing=""
michael@428: [ ".$REGISTRY_USER" = . ] && missing="$missing REGISTRY_USER"
michael@428: [ ".$REGISTRY_DESC" = . ] && missing="$missing REGISTRY_DESC"
michael@428: [ ".$REGISTRY_PLAT" = . ] && missing="$missing REGISTRY_PLAT"
michael@428: [ ".$REGISTRY_OREL" = . ] && missing="$missing REGISTRY_OREL"
michael@428: [ ".$REGISTRY_UUID" = . ] && missing="$missing REGISTRY_UUID"
michael@428: [ ".$REGISTRY_PREP" = . ] && missing="$missing REGISTRY_PREP"
michael@428: [ ".$REGISTRY_MODE" = . ] && missing="$missing REGISTRY_MODE"
michael@428: [ ".$REGISTRY_ARGS" = . ] && missing="$missing REGISTRY_ARGS"
michael@428: [ ".$REGISTRY_TRAN" = . ] && missing="$missing REGISTRY_TRAN"
michael@428: [ ".$REGISTRY_UTIL" = . ] && missing="$missing REGISTRY_UTIL"
michael@428: }
michael@428:
michael@428: ##
michael@428: ## automatically pick interaction or convenience
michael@428: ##
michael@428: automatic()
michael@428: {
michael@428: if [ ".$REGISTRY_MODE" = .wipe ]; then
michael@428: convenience
michael@428: interaction
michael@428: return
michael@428: fi
michael@428:
michael@428: checkmissing
michael@428: if [ ".$missing" != . ]; then
michael@428: autoregdata
michael@428: fi
michael@428:
michael@428: checkmissing
michael@428: if [ ".$missing" = . ]; then
michael@428: convenience
michael@428: else
michael@428: tty -s || return
michael@428: echo "missing $missing"
michael@428: interaction
michael@428: fi
michael@428: }
michael@428:
michael@428: ##
michael@428: ## primary operation switch
michael@428: ##
michael@428: eval $op "\"$@\""
michael@428: exit $?
michael@428:
michael@428: ##
michael@428: ## MANUAL PAGE
michael@428: ##
michael@428: