openpkg/uuid.sh

Fri, 15 Oct 2010 18:46:25 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 15 Oct 2010 18:46:25 +0200
changeset 261
4f973c756446
child 428
f880f219c566
permissions
-rw-r--r--

Update copyright, file server URL, modify doc and link logic.
Now documentation is installed by default to the correct path,
and QtCreator links against Qt shared libraries instead of Qt
static libraries. This unfortunate change supports Nokia's
unfortunate decision to poorly support static linking in Qt.

michael@13 1 #!@l_prefix@/lib/openpkg/bash
michael@13 2 ##
michael@13 3 ## uuid -- OpenPKG UUID Update Utility
michael@13 4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
michael@13 5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
michael@13 6 ##
michael@13 7 ## Permission to use, copy, modify, and distribute this software for
michael@13 8 ## any purpose with or without fee is hereby granted, provided that
michael@13 9 ## the above copyright notice and this permission notice appear in all
michael@13 10 ## copies.
michael@13 11 ##
michael@13 12 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
michael@13 13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@13 14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@13 15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@13 16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@13 17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@13 18 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@13 19 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@13 20 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@13 21 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@13 22 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@13 23 ## SUCH DAMAGE.
michael@13 24 ##
michael@13 25
michael@13 26 # configuration
michael@13 27 prefix="@l_prefix@"
michael@13 28 musr="@l_musr@"
michael@13 29 mgrp="@l_mgrp@"
michael@13 30 prog_rpm="$prefix/libexec/openpkg/rpm"
michael@13 31 prog_shtool="$prefix/lib/openpkg/shtool"
michael@13 32 prog_miniperl="$prefix/lib/openpkg/miniperl"
michael@13 33 prog_uuid="$prefix/lib/openpkg/uuid"
michael@13 34 file_uuid="$prefix/etc/openpkg/uuid"
michael@13 35
michael@13 36 # minimum command line parsing
michael@13 37 opt_v=no
michael@13 38 opt_m=no
michael@13 39 while [ 1 ]; do
michael@13 40 case "$1" in
michael@13 41 -v | --verbose ) opt_v=yes; shift ;;
michael@13 42 -m | --multicast ) opt_m=yes; shift ;;
michael@13 43 * ) break ;;
michael@13 44 esac
michael@13 45 done
michael@13 46
michael@13 47 # special "Nil UUID"
michael@13 48 UUID_NIL="00000000-0000-0000-0000-000000000000"
michael@13 49
michael@13 50 # Query Dynamic Information
michael@13 51 do_query () {
michael@13 52 # query RPM information
michael@13 53 query=":"
michael@13 54 for var in \
michael@13 55 l_openpkg_release \
michael@13 56 l_prefix \
michael@13 57 l_susr l_suid l_sgrp l_sgid \
michael@13 58 l_musr l_muid l_mgrp l_mgid \
michael@13 59 l_rusr l_ruid l_rgrp l_rgid \
michael@13 60 l_nusr l_nuid l_ngrp l_ngid; do
michael@13 61 query="$query; `echo $var | sed -e 's;^l_;Q_;'`=\"%{$var}\""
michael@13 62 done
michael@13 63 eval `$prog_rpm --eval "$query" 2>/dev/null`
michael@13 64
michael@13 65 # query OS information
michael@13 66 Q_platform=`$prog_shtool platform --type=binary 2>/dev/null |\
michael@13 67 sed -e 's;^\([^-][^-]*-[^.-][^.-]*\)\..*$;\1;'`
michael@13 68 if [ ".$Q_platform" = . ]; then
michael@13 69 Q_platform="unknown"
michael@13 70 fi
michael@13 71 Q_discriminator=`$prog_uuid -v1 | $prog_uuid -d -- - | awk '/node:.*global unicast/ { printf("mac:%s", $2); }'`
michael@13 72 if [ ".$Q_discriminator" = . ]; then
michael@13 73 Q_discriminator=`$prog_miniperl -e 'if (-f "/etc/openpkg") { printf("inode:%s", (stat("/etc/openpkg"))[1]); }' 2>/dev/null`
michael@13 74 if [ ".$Q_discriminator" = . ]; then
michael@13 75 Q_discriminator=`$prog_shtool echo -e 'fqdn:%h%d' 2>/dev/null`
michael@13 76 fi
michael@13 77 fi
michael@13 78 }
michael@13 79
michael@13 80 # Load Configuration
michael@13 81 do_load () {
michael@13 82 # start with reasonable defaults
michael@13 83 UUID_REGISTRY="$UUID_NIL"
michael@13 84 UUID_INSTANCE="$UUID_NIL"
michael@13 85 UUID_PLATFORM="$UUID_NIL"
michael@13 86
michael@13 87 # load configuration (and override defaults)
michael@13 88 if [ -r $file_uuid ]; then
michael@13 89 if [ ".$opt_v" = .yes ]; then
michael@13 90 echo "uuid: loading UUID configuration file ($file_uuid)"
michael@13 91 fi
michael@13 92 . $file_uuid
michael@13 93 fi
michael@13 94
michael@13 95 # remember whether something was changed
michael@13 96 changed=no
michael@13 97 }
michael@13 98
michael@13 99 # Save Configuration
michael@13 100 do_save () {
michael@13 101 if [ ".$changed" = .yes ]; then
michael@13 102 # save configuration
michael@13 103 if [ ".$opt_v" = .yes ]; then
michael@13 104 echo "uuid: saving UUID configuration file ($file_uuid)"
michael@13 105 fi
michael@13 106 if [ -f $file_uuid ] && [ ! -w $file_uuid ]; then
michael@13 107 echo "uuid:ERROR: cannot write to $file_uuid" 1>&2
michael@13 108 exit 1
michael@13 109 fi
michael@13 110 ( echo "UUID_REGISTRY=\"$UUID_REGISTRY\""
michael@13 111 echo "UUID_INSTANCE=\"$UUID_INSTANCE\""
michael@13 112 echo "UUID_PLATFORM=\"$UUID_PLATFORM\""
michael@13 113 ) >$file_uuid.new || exit $?
michael@13 114 n=`egrep 'UUID_(REGISTRY|INSTANCE|PLATFORM)="[0-9a-f-]*"' \
michael@13 115 $file_uuid.new | wc -l | awk '{ print $1; }'`
michael@13 116 if [ ".$n" != .3 ]; then
michael@13 117 echo "uuid:ERROR: failed to update $file_uuid" 1>&2
michael@13 118 rm -f $file_uuid.new
michael@13 119 exit 1
michael@13 120 fi
michael@13 121 cp $file_uuid.new $file_uuid || exit $?
michael@13 122 rm -f $file_uuid.new || true
michael@13 123 chown $musr:$mgrp $file_uuid >/dev/null 2>&1 || true
michael@13 124 chmod 644 $file_uuid >/dev/null 2>&1 || true
michael@13 125
michael@13 126 # remember that no more changes exist
michael@13 127 changed=no
michael@13 128 fi
michael@13 129 }
michael@13 130
michael@13 131 # Reset UUIDs
michael@13 132 do_reset () {
michael@13 133 # reset all UUIDs to the "Nil UUID"
michael@13 134 if [ ".$UUID_REGISTRY" != ".$UUID_NIL" ]; then
michael@13 135 UUID_REGISTRY="$UUID_NIL"
michael@13 136 changed=yes
michael@13 137 fi
michael@13 138 if [ ".$UUID_INSTANCE" != ".$UUID_NIL" ]; then
michael@13 139 UUID_INSTANCE="$UUID_NIL"
michael@13 140 changed=yes
michael@13 141 fi
michael@13 142 if [ ".$UUID_PLATFORM" != ".$UUID_NIL" ]; then
michael@13 143 UUID_PLATFORM="$UUID_NIL"
michael@13 144 changed=yes
michael@13 145 fi
michael@13 146 }
michael@13 147
michael@13 148 # Update UUIDs
michael@13 149 do_update () {
michael@13 150 # update registry UUID
michael@13 151 if [ ".$UUID_REGISTRY" = ".$UUID_NIL" -o ".$UUID_REGISTRY" = . ]; then
michael@13 152 opt=""
michael@13 153 if [ ".$opt_m" = .yes ]; then
michael@13 154 opt="-m"
michael@13 155 fi
michael@13 156 if [ ".$opt_v" = .yes ]; then
michael@13 157 echo "uuid: calculating OpenPKG Registry UUID (UUID_REGISTRY):"
michael@13 158 echo "uuid: << $prog_uuid -v1 $opt"
michael@13 159 fi
michael@13 160 uuid=`$prog_uuid -v1 $opt`
michael@13 161 if [ ".$UUID_REGISTRY" != ".$uuid" -a ".$uuid" != . ]; then
michael@13 162 UUID_REGISTRY="$uuid"
michael@13 163 if [ ".$opt_v" = .yes ]; then
michael@13 164 echo "uuid: >> $UUID_REGISTRY (NOT REPEATABLE)"
michael@13 165 fi
michael@13 166 changed=yes
michael@13 167 fi
michael@13 168 fi
michael@13 169
michael@13 170 # update instance UUID
michael@13 171 name="${Q_openpkg_release}"
michael@13 172 name="$name:${Q_prefix}"
michael@13 173 name="$name:${Q_susr}:${Q_suid}:${Q_sgrp}:${Q_sgid}"
michael@13 174 name="$name:${Q_musr}:${Q_muid}:${Q_mgrp}:${Q_mgid}"
michael@13 175 name="$name:${Q_rusr}:${Q_ruid}:${Q_rgrp}:${Q_rgid}"
michael@13 176 name="$name:${Q_nusr}:${Q_nuid}:${Q_ngrp}:${Q_ngid}"
michael@13 177 if [ ".$opt_v" = .yes ]; then
michael@13 178 echo "uuid: querying OpenPKG Instance OID"
michael@13 179 echo "uuid: << $prog_rpm --eval '%{l_openpkg_oid_instance}'"
michael@13 180 fi
michael@13 181 OID_NS_INSTANCE="`$prog_rpm --eval '%{l_openpkg_oid_instance}'`"
michael@13 182 if [ ".$opt_v" = .yes ]; then
michael@13 183 echo "uuid: >> $OID_NS_INSTANCE"
michael@13 184 fi
michael@13 185 if [ ".$opt_v" = .yes ]; then
michael@13 186 echo "uuid: calculating OpenPKG Instance Namespace UUID"
michael@13 187 echo "uuid: << $prog_uuid -v3 ns:OID \"$OID_NS_INSTANCE\""
michael@13 188 fi
michael@13 189 UUID_NS_INSTANCE=`$prog_uuid -v3 ns:OID "$OID_NS_INSTANCE"`
michael@13 190 if [ ".$opt_v" = .yes ]; then
michael@13 191 echo "uuid: >> $UUID_NS_INSTANCE"
michael@13 192 fi
michael@13 193 if [ ".$opt_v" = .yes ]; then
michael@13 194 echo "uuid: calculating OpenPKG Instance UUID (UUID_INSTANCE):"
michael@13 195 echo "uuid: << $prog_uuid -v3 \"$UUID_NS_INSTANCE\" \"$name\""
michael@13 196 fi
michael@13 197 uuid=`$prog_uuid -v3 "$UUID_NS_INSTANCE" "$name"`
michael@13 198 if [ ".$opt_v" = .yes ]; then
michael@13 199 echo "uuid: >> $uuid"
michael@13 200 fi
michael@13 201 if [ ".$UUID_INSTANCE" != ".$uuid" -a ".$uuid" != . ]; then
michael@13 202 UUID_INSTANCE="$uuid"
michael@13 203 changed=yes
michael@13 204 fi
michael@13 205
michael@13 206 # update platform UUID
michael@13 207 name="${Q_platform}"
michael@13 208 name="$name:${Q_discriminator}"
michael@13 209 if [ ".$opt_v" = .yes ]; then
michael@13 210 echo "uuid: querying OpenPKG Platform OID"
michael@13 211 echo "uuid: << $prog_rpm --eval '%{l_openpkg_oid_platform}'"
michael@13 212 fi
michael@13 213 OID_NS_PLATFORM="`$prog_rpm --eval '%{l_openpkg_oid_platform}'`"
michael@13 214 if [ ".$opt_v" = .yes ]; then
michael@13 215 echo "uuid: >> $OID_NS_PLATFORM"
michael@13 216 fi
michael@13 217 if [ ".$opt_v" = .yes ]; then
michael@13 218 echo "uuid: calculating OpenPKG Platform Namespace UUID"
michael@13 219 echo "uuid: << $prog_uuid -v3 ns:OID \"$OID_NS_PLATFORM\""
michael@13 220 fi
michael@13 221 UUID_NS_PLATFORM=`$prog_uuid -v3 ns:OID "$OID_NS_PLATFORM"`
michael@13 222 if [ ".$opt_v" = .yes ]; then
michael@13 223 echo "uuid: >> $UUID_NS_PLATFORM"
michael@13 224 fi
michael@13 225 if [ ".$opt_v" = .yes ]; then
michael@13 226 echo "uuid: calculating OpenPKG Platform UUID (UUID_PLATFORM):"
michael@13 227 echo "uuid: << $prog_uuid -v3 \"$UUID_NS_PLATFORM\" \"$name\""
michael@13 228 fi
michael@13 229 uuid=`$prog_uuid -v3 "$UUID_NS_PLATFORM" "$name"`
michael@13 230 if [ ".$opt_v" = .yes ]; then
michael@13 231 echo "uuid: >> $uuid"
michael@13 232 fi
michael@13 233 if [ ".$UUID_PLATFORM" != ".$uuid" -a ".$uuid" != . ]; then
michael@13 234 UUID_PLATFORM="$uuid"
michael@13 235 changed=yes
michael@13 236 fi
michael@13 237 }
michael@13 238
michael@13 239 # Info about input and resulting UUIDs
michael@13 240 do_info () {
michael@13 241 echo "OpenPKG Summary of Identification Information"
michael@13 242 echo "============================================="
michael@13 243 echo ""
michael@13 244 echo "OpenPKG Registry"
michael@13 245 time=""; clock=""; node=""
michael@13 246 eval `$prog_uuid -d "$UUID_REGISTRY" 2>/dev/null |\
michael@13 247 sed -e 's/^/X/' \
michael@13 248 -e 's/X.*time: *\(.*\)$/time="\1";/' \
michael@13 249 -e 's/X.*clock: *\(.*\)$/clock="\1";/' \
michael@13 250 -e 's/X.*node: *\(.*\)$/node="\1";/' \
michael@13 251 -e 's/^X.*//'`
michael@13 252 echo " System Time: ${time:-unknown}"
michael@13 253 echo " System Clock Sequence: ${clock:-unknown}"
michael@13 254 echo " System Node Address: ${node:-unknown}"
michael@13 255 echo " UUID_REGISTRY: $UUID_REGISTRY"
michael@13 256 echo ""
michael@13 257 echo "OpenPKG Instance"
michael@13 258 echo " Release: ${Q_openpkg_release}"
michael@13 259 echo " Prefix: ${Q_prefix}"
michael@13 260 echo " Super Account: ${Q_susr}(${Q_suid}):${Q_sgrp}(${Q_sgid})"
michael@13 261 echo " Management Account: ${Q_musr}(${Q_muid}):${Q_mgrp}(${Q_mgid})"
michael@13 262 echo " Restricted Account: ${Q_rusr}(${Q_ruid}):${Q_rgrp}(${Q_rgid})"
michael@13 263 echo " Nonprivileged Account: ${Q_nusr}(${Q_nuid}):${Q_ngrp}(${Q_ngid})"
michael@13 264 echo " UUID_INSTANCE: $UUID_INSTANCE"
michael@13 265 echo ""
michael@13 266 echo "OpenPKG Platform"
michael@13 267 echo " Platform Id: $Q_platform"
michael@13 268 echo " Discriminator: $Q_discriminator"
michael@13 269 echo " UUID_PLATFORM: $UUID_PLATFORM"
michael@13 270 echo ""
michael@13 271 echo "(run \"$0 --verbose update\" to reproduce the UUID generation)"
michael@13 272 }
michael@13 273
michael@13 274 # Command Line Dispatching
michael@13 275 cmd="$1"
michael@13 276 shift
michael@13 277 case "$cmd" in
michael@13 278 reset )
michael@13 279 do_load; do_reset; do_save
michael@13 280 ;;
michael@13 281 update )
michael@13 282 do_query; do_load; do_update; do_save
michael@13 283 ;;
michael@13 284 info )
michael@13 285 do_query; do_load; do_info
michael@13 286 ;;
michael@13 287 * )
michael@13 288 echo "uuid:ERROR: invalid command \"$cmd\"" 1>&2
michael@13 289 exit 1
michael@13 290 ;;
michael@13 291 esac
michael@13 292

mercurial