michael@428: #!@l_prefix@/lib/openpkg/bash
michael@428: ##
michael@428: ## uuid -- OpenPKG UUID Update Utility
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: # configuration
michael@428: prefix="@l_prefix@"
michael@428: musr="@l_musr@"
michael@428: mgrp="@l_mgrp@"
michael@428:
michael@428: # minimum command line parsing
michael@428: opt_v=no
michael@428: while [ 1 ]; do
michael@428: case "$1" in
michael@428: -v | --verbose ) opt_v=yes; shift ;;
michael@428: * ) break ;;
michael@428: esac
michael@428: done
michael@428:
michael@428: # determine temporary directory
michael@428: tmpdir="${TMPDIR-/tmp}"
michael@428:
michael@428: # helper function for checking the signature
michael@428: valid_signature () {
michael@428: script="%{lua: print(rpm.signature(\"$1\", nil,"
michael@428: script="$script \"$prefix/etc/openpkg/openpkg.com.pgp\","
michael@428: script="$script \"7D121A8FC05DC18A4329E9EF67042EC961B7AE34\")) }"
michael@428: result=`$prefix/bin/openpkg rpm --eval "$script" 2>/dev/null || true`
michael@428: if [ ".$result" == .true ]; then
michael@428: return 0
michael@428: else
michael@428: return 1
michael@428: fi
michael@428: }
michael@428:
michael@428: # display usage help
michael@428: do_help () {
michael@428: echo "openpkg license help .......................... show usage help (this text)"
michael@428: echo "openpkg license install ||- ... install a new license"
michael@428: echo "openpkg license update ||- .... update an installed license"
michael@428: echo "openpkg license uninstall ................ uninstall an installed license"
michael@428: echo "openpkg license activate ................. activate an installed license"
michael@428: echo "openpkg license view ..................... view an installed license"
michael@428: echo "openpkg license list .......................... list all installed licenses"
michael@428: echo "openpkg license active ........................ list the currently activated license"
michael@428: echo "openpkg license sanity ........................ sanity check installed license"
michael@428: }
michael@428:
michael@428: # install license
michael@428: do_install () {
michael@428: if [ $# -ne 2 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license install |-" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id="$1"
michael@428: src="$2"
michael@428: case "$src" in
michael@428: http:* | https:* | ftp:* )
michael@428: tmp="$tmpdir/openpkg.license.txt"
michael@428: ( rm -f $tmp >/dev/null 2>&1 || true
michael@428: set -o noclobber
michael@428: $prefix/lib/openpkg/curl -s -q -f -L $src >$tmp
michael@428: ) || exit $?
michael@428: src="$tmp"
michael@428: ;;
michael@428: "-" )
michael@428: src="$tmpdir/openpkg.license.txt"
michael@428: ( rm -f $src >/dev/null 2>&1 || true
michael@428: set -o noclobber
michael@428: cat >$src
michael@428: ) || exit $?
michael@428: ;;
michael@428: esac
michael@428: if [ -f $prefix/etc/openpkg/license.d/$id ]; then
michael@428: echo "openpkg:license:ERROR: license with id \"$id\" already exists -- uninstall first" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: if ! valid_signature $src; then
michael@428: echo "openpkg:license:ERROR: invalid signature on license file" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: if [ ! -w $prefix/etc/openpkg/license.d ]; then
michael@428: echo "openpkg:license:ERROR: unable to store signature -- permission problems?" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: cat $src >$prefix/etc/openpkg/license.d/$id || exit $?
michael@428: chown $musr:$mgrp $prefix/etc/openpkg/license.d/$id >/dev/null 2>&1 || true
michael@428: }
michael@428:
michael@428: # update license
michael@428: do_update () {
michael@428: if [ $# -ne 2 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license update |-" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id="$1"
michael@428: src="$2"
michael@428: case "$src" in
michael@428: http:* | https:* | ftp:* )
michael@428: tmp="$tmpdir/openpkg.license.txt"
michael@428: ( rm -f $tmp >/dev/null 2>&1 || true
michael@428: set -o noclobber
michael@428: $prefix/lib/openpkg/curl -s -q -f -L $src >$tmp
michael@428: ) || exit $?
michael@428: src="$tmp"
michael@428: ;;
michael@428: "-" )
michael@428: src="$tmpdir/openpkg.license.txt"
michael@428: ( rm -f $src >/dev/null 2>&1 || true
michael@428: set -o noclobber
michael@428: cat >$src
michael@428: ) || exit $?
michael@428: ;;
michael@428: esac
michael@428: if [ ! -f $prefix/etc/openpkg/license.d/$id ]; then
michael@428: echo "openpkg:license:ERROR: license with id \"$id\" does not exist -- install first to update" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: if ! valid_signature $src; then
michael@428: echo "openpkg:license:ERROR: invalid signature on license file" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: if [ ! -w $prefix/etc/openpkg/license.d ]; then
michael@428: echo "openpkg:license:ERROR: unable to store signature -- permission problems?" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: cat $src >$prefix/etc/openpkg/license.d/$id || exit $?
michael@428: chown $musr:$mgrp $prefix/etc/openpkg/license.d/$id >/dev/null 2>&1 || true
michael@428: }
michael@428:
michael@428: # uninstall license
michael@428: do_uninstall () {
michael@428: if [ $# -ne 1 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license uninstall " 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id="$1"
michael@428: if [ ! -f $prefix/etc/openpkg/license.d/$id ]; then
michael@428: echo "openpkg:license:ERROR: no license under id \"$id\" installed" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id_active="`cat $prefix/etc/openpkg/license`"
michael@428: if [ ".$id" = ".$id_active" ]; then
michael@428: echo "openpkg:license:ERROR: license under id \"$id\" still activated -- activate a different one first" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: rm -f $prefix/etc/openpkg/license.d/$id
michael@428: if [ $? -ne 0 ]; then
michael@428: echo "openpkg:license:ERROR: failed to uninstall license" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: }
michael@428:
michael@428: # activate license
michael@428: do_activate () {
michael@428: if [ $# -ne 1 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license activate " 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id="$1"
michael@428: if [ ! -f $prefix/etc/openpkg/license.d/$id ]; then
michael@428: echo "openpkg:license:ERROR: no license under id \"$id\" installed" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id_active="`cat $prefix/etc/openpkg/license`"
michael@428: if [ ".$id" = ".$id_active" ]; then
michael@428: echo "openpkg:license:ERROR: license id \"$id\" is already activated" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: echo "$id" >$prefix/etc/openpkg/license
michael@428: if [ $? -ne 0 ]; then
michael@428: echo "openpkg:license:ERROR: failed to activate license under id \"$id\"" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: }
michael@428:
michael@428: # view license
michael@428: do_view () {
michael@428: if [ $# -ne 1 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license view " 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id="$1"
michael@428: if [ ! -f $prefix/etc/openpkg/license.d/$id ]; then
michael@428: echo "openpkg:license:ERROR: no license under id \"$id\" installed" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: viewer=""
michael@428: for name in less more cat; do
michael@428: for dir in `echo $PATH | sed -e 's;:; ;g'`; do
michael@428: if [ -x $dir/$name ]; then
michael@428: viewer="$dir/$name"
michael@428: break
michael@428: fi
michael@428: done
michael@428: if [ ".$viewer" != . ]; then
michael@428: break
michael@428: fi
michael@428: done
michael@428: eval $viewer $prefix/etc/openpkg/license.d/$id
michael@428: }
michael@428:
michael@428: # list license
michael@428: do_list () {
michael@428: if [ $# -ne 0 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license list" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id_active="`cat $prefix/etc/openpkg/license`"
michael@428: for file in `cd / && find $prefix/etc/openpkg/license.d -type f -print | sort`; do
michael@428: id=`echo $file | sed -e "s;^$prefix/etc/openpkg/license.d/;;"`
michael@428: status="-"
michael@428: if [ ".$id" = ".$id_active" ]; then
michael@428: status="+"
michael@428: fi
michael@428: echo . | awk '{ printf("%s %s\n", status, id); }' id="$id" status="$status"
michael@428: done
michael@428: }
michael@428:
michael@428: # list currently activate license
michael@428: do_active () {
michael@428: if [ $# -ne 0 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license active" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: cat $prefix/etc/openpkg/license
michael@428: }
michael@428:
michael@428: # sanity-check license
michael@428: do_sanity () {
michael@428: if [ $# -ne 0 ]; then
michael@428: echo "openpkg:license:USAGE: openpkg license sanity" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: id="`cat $prefix/etc/openpkg/license`"
michael@428: if [ ! -f $prefix/etc/openpkg/license.d/$id ]; then
michael@428: echo "openpkg:license:ERROR: active license with id \"$id\" does not exist" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: if ! valid_signature $prefix/etc/openpkg/license.d/$id; then
michael@428: echo "openpkg:license:ERROR: invalid signature on active license" 1>&2
michael@428: exit 1
michael@428: fi
michael@428: }
michael@428:
michael@428: # Command Line Dispatching
michael@428: cmd="$1"
michael@428: shift
michael@428: case "$cmd" in
michael@428: help ) do_help ${1+"$@"} ;;
michael@428: install ) do_install ${1+"$@"} ;;
michael@428: update ) do_update ${1+"$@"} ;;
michael@428: uninstall ) do_uninstall ${1+"$@"} ;;
michael@428: activate ) do_activate ${1+"$@"} ;;
michael@428: view ) do_view ${1+"$@"} ;;
michael@428: list ) do_list ${1+"$@"} ;;
michael@428: active ) do_active ${1+"$@"} ;;
michael@428: sanity ) do_sanity ${1+"$@"} ;;
michael@428: "" ) echo "openpkg:license:ERROR: no command given (use \"help\" for usage)" 1>&2; exit 1 ;;
michael@428: * ) echo "openpkg:license:ERROR: invalid command \"$cmd\" (use \"help\" for usage)" 1>&2; exit 1 ;;
michael@428: esac
michael@428: