openpkg/rpmdb

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 ## rpmdb -- OpenPKG RPM Database Administration 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 # program information
michael@13 27 progname="rpmdb"
michael@13 28
michael@13 29 # configuration defaults
michael@13 30 help=""
michael@13 31 prefix="@l_prefix@"
michael@13 32 dbpath=""
michael@13 33 rpm=""
michael@13 34 musr="@l_musr@"
michael@13 35 mgrp="@l_mgrp@"
michael@13 36 mode=""
michael@13 37 force=no
michael@13 38 verbose=2
michael@13 39
michael@13 40 ##
michael@13 41 ## PARSE COMMAND LINE
michael@13 42 ##
michael@13 43
michael@13 44 # iterate over argument line
michael@13 45 for opt
michael@13 46 do
michael@13 47 case $opt in
michael@13 48 -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
michael@13 49 *) arg='' ;;
michael@13 50 esac
michael@13 51 case $opt in
michael@13 52 -h|--help ) help="Usage" ;;
michael@13 53 -B|--build ) mode=build ;;
michael@13 54 -R|--rebuild ) mode=rebuild ;;
michael@13 55 -C|--cleanup ) mode=cleanup ;;
michael@13 56 -F|--fixate ) mode=fixate ;;
michael@13 57 -L|--list ) mode=list ;;
michael@13 58 -f|--force ) force=yes ;;
michael@13 59 -q|--quiet ) verbose=0 ;;
michael@13 60 -v|--verbose ) verbose=`expr $verbose + 1` ;;
michael@13 61 --prefix=* ) prefix=$arg ;;
michael@13 62 --dbpath=* ) dbpath=$arg ;;
michael@13 63 --rpm=* ) rpm=$arg ;;
michael@13 64 --musr=* ) musr=$arg ;;
michael@13 65 --mgrp=* ) mgrp=$arg ;;
michael@13 66 * ) help="Invalid option \`$opt'"; break ;;
michael@13 67 esac
michael@13 68 done
michael@13 69
michael@13 70 # makre sure exactly one run-time mode is specified
michael@13 71 if [ ".$mode" = . ]; then
michael@13 72 help="No or invalid run-time mode specified"
michael@13 73 fi
michael@13 74
michael@13 75 # error or usage message
michael@13 76 if [ ".$help" != . ]; then
michael@13 77 if [ ".$help" != ".Usage" ]; then
michael@13 78 echo "$progname:ERROR: $help" 1>&2
michael@13 79 fi
michael@13 80 cat 1>&2 <<EOT
michael@13 81 $progname:USAGE: $progname [options]
michael@13 82
michael@13 83 -h, --help print usage message (this one)
michael@13 84 -B, --build build new RPM database from scratch
michael@13 85 -R, --rebuild rebuild new from old RPM database
michael@13 86 -C, --cleanup cleanup existing RPM database
michael@13 87 -F, --fixate fixate existing RPM database
michael@13 88 -L, --list list all RPM database files
michael@13 89 -f, --force operate in force mode (no save operations)
michael@13 90 -q, --quiet operate in quiet mode (no verbose messages at all)
michael@13 91 -v, --verbose operate in more verbose mode (increase verbose level)
michael@13 92 --prefix=PREFIX use OpenPKG instance under PREFIX
michael@13 93 --dbpath=PATH use OpenPKG RPM database under PATH
michael@13 94 --rpm=PROG use OpenPKG RPM executable PROG
michael@13 95 --musr=USERNAME use OpenPKG management user USERNAME
michael@13 96 --mgrp=GROUPNAME use OpenPKG management group GROUPNAME
michael@13 97
michael@13 98 This is OpenPKG rpmdb, an RPM database administration utility, providing
michael@13 99 lower-level maintainance functions for the Berkeley-DB 4.1 based RPM 4.2
michael@13 100 database. It allows building new RPM databases from scratch, rebuilding
michael@13 101 a new from an old RPM database (content dumping and reloading),
michael@13 102 cleaning up problems on an existing RPM database (removal of DB region
michael@13 103 files, etc) and fixating the files in an existing RPM database (file
michael@13 104 attributes).
michael@13 105
michael@13 106 EOT
michael@13 107 if [ ".$help" != ".Usage" ]; then
michael@13 108 exit 2
michael@13 109 else
michael@13 110 exit 0
michael@13 111 fi
michael@13 112 fi
michael@13 113
michael@13 114 # delayed determination of variables
michael@13 115 if [ ".$dbpath" = . ]; then
michael@13 116 dbpath="$prefix/RPM/DB"
michael@13 117 fi
michael@13 118 if [ ".$rpm" = . ]; then
michael@13 119 rpm="$prefix/bin/openpkg rpm"
michael@13 120 fi
michael@13 121
michael@13 122 ##
michael@13 123 ## DATABASE FILE INFORMATION
michael@13 124 ##
michael@13 125
michael@13 126 dbfiles="
michael@13 127 hash:Basenames
michael@13 128 hash:Conflictname
michael@13 129 hash:Depends
michael@13 130 btree:Dirnames
michael@13 131 hash:Filemd5s
michael@13 132 hash:Group
michael@13 133 btree:Installtid
michael@13 134 hash:Name
michael@13 135 hash:Packages
michael@13 136 hash:Providename
michael@13 137 btree:Provideversion
michael@13 138 hash:Pubkeys
michael@13 139 hash:Requirename
michael@13 140 btree:Requireversion
michael@13 141 hash:Sha1header
michael@13 142 hash:Sigmd5
michael@13 143 hash:Triggername
michael@13 144 region:__db.001
michael@13 145 region:__db.002
michael@13 146 region:__db.003
michael@13 147 region:__db.004
michael@13 148 region:__db.005
michael@13 149 region:__db.006
michael@13 150 region:__db.007
michael@13 151 region:__db.008
michael@13 152 region:__db.009
michael@13 153 "
michael@13 154
michael@13 155 ##
michael@13 156 ## HELPER FUNCTIONS
michael@13 157 ##
michael@13 158
michael@13 159 error () {
michael@13 160 echo "$progname:ERROR: $*" 1>&2
michael@13 161 exit 1
michael@13 162 }
michael@13 163
michael@13 164 warning () {
michael@13 165 echo "$progname:WARNING: $*" 1>&2
michael@13 166 }
michael@13 167
michael@13 168 verbose () {
michael@13 169 local level=$1
michael@13 170 shift
michael@13 171 if [ $level -le $verbose ]; then
michael@13 172 local lead=""
michael@13 173 case "$level" in
michael@13 174 1 ) lead="" ;;
michael@13 175 2 ) lead="" ;;
michael@13 176 3 ) lead=" " ;;
michael@13 177 * ) lead=" " ;;
michael@13 178 esac
michael@13 179 echo "$progname: $lead$*" 1>&2
michael@13 180 fi
michael@13 181 }
michael@13 182
michael@13 183 rpm () {
michael@13 184 local opts="--dbpath `echo $dbpath | sed -e 's;/*$;;' -e 's;$;/;'`"
michael@13 185 if [ ".$force" = .yes ]; then
michael@13 186 opts="$opts --define '__dbi_private yes'"
michael@13 187 fi
michael@13 188 verbose 3 "run: $rpm $opts $@"
michael@13 189 eval "$rpm $opts \"\$@\""
michael@13 190 }
michael@13 191
michael@13 192 rpmdb_load () {
michael@13 193 $prefix/lib/openpkg/rpmdb_load ${1+"$@"}
michael@13 194 }
michael@13 195
michael@13 196 rpmdb_dump () {
michael@13 197 $prefix/lib/openpkg/rpmdb_dump ${1+"$@"}
michael@13 198 }
michael@13 199
michael@13 200 ##
michael@13 201 ## RPM DATABASE OPERATIONS
michael@13 202 ##
michael@13 203
michael@13 204 db_wait () {
michael@13 205 # wait until RPM has released the database in case we are called
michael@13 206 # asynchronously to RPM (especially important when upgrading from
michael@13 207 # RPM 4.0 where concurrent access is still not possible)
michael@13 208 verbose 2 "waiting for RPM database to be available"
michael@13 209 local i=0
michael@13 210 while [ $i -lt 10 ]; do
michael@13 211 if $prefix/libexec/openpkg/rpm -q openpkg >/dev/null 2>&1; then
michael@13 212 break
michael@13 213 fi
michael@13 214 sleep 1
michael@13 215 i=`expr $i + 1`
michael@13 216 done
michael@13 217 if [ $i -eq 10 ]; then
michael@13 218 exit 1
michael@13 219 else
michael@13 220 exit 0
michael@13 221 fi
michael@13 222 }
michael@13 223
michael@13 224 db_remove () {
michael@13 225 # remove all known files
michael@13 226 verbose 2 "removing (possibly existing) old RPM database DB files"
michael@13 227 for dbfile in $dbfiles; do
michael@13 228 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'`
michael@13 229 verbose 3 "removing database file: $dbpath/$dbfile ($dbtype)"
michael@13 230 rm -f $dbpath/$dbfile
michael@13 231 done
michael@13 232 }
michael@13 233
michael@13 234 db_init () {
michael@13 235 # perform official "initdb" operation
michael@13 236 # (is mostly a no-operation in RPM 4.2, but anyway)
michael@13 237 verbose 2 "creating new RPM database (built-in RPM procedure)"
michael@13 238 rpm --initdb
michael@13 239
michael@13 240 # perform some real RPM work, so more database files
michael@13 241 # magically spring into existence
michael@13 242 verbose 2 "operating on new RPM database"
michael@13 243 rpm --import $prefix/etc/openpkg/openpkg.org.pgp || true
michael@13 244 rpm -e gpg-pubkey-63c4cb9f-3c591eda --allmatches || true
michael@13 245
michael@13 246 # perform official "rebuilddb" operation in the hope it
michael@13 247 # creates even more database files now that we have some content
michael@13 248 verbose 2 "rebuilding new RPM database (built-in RPM procedure)"
michael@13 249 rpm --rebuilddb
michael@13 250 }
michael@13 251
michael@13 252 db_unbreak () {
michael@13 253 # cleanup DB region files
michael@13 254 verbose 2 "cleaning up RPM database DB region files"
michael@13 255 for dbfile in $dbfiles; do
michael@13 256 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'`
michael@13 257 if [ ".$dbtype" = .region ]; then
michael@13 258 verbose 3 "cleaning up DB file: $dbpath/$dbfile ($dbtype)"
michael@13 259 rm -f $dbpath/$dbfile || true
michael@13 260 touch $dbpath/$dbfile || true
michael@13 261 fi
michael@13 262 done
michael@13 263 }
michael@13 264
michael@13 265 db_extend () {
michael@13 266 # make sure all RPM database DB files are present
michael@13 267 verbose 2 "making sure RPM database contains all possible DB files"
michael@13 268 for dbfile in $dbfiles; do
michael@13 269 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'`
michael@13 270 if [ ! -f $dbpath/$dbfile ]; then
michael@13 271 verbose 3 "creating DB file: $dbpath/$dbfile ($dbtype)"
michael@13 272 if [ ".$dbtype" = .hash -o ".$dbtype" = .btree ]; then
michael@13 273 ( echo "VERSION=3"
michael@13 274 echo "format=bytevalue"
michael@13 275 echo "type=$dbtype"
michael@13 276 echo "db_pagesize=16384"
michael@13 277 echo "HEADER=END"
michael@13 278 echo "DATA=END"
michael@13 279 ) | rpmdb_load $dbpath/$dbfile || true
michael@13 280 else
michael@13 281 touch $dbpath/$dbfile || true
michael@13 282 fi
michael@13 283 fi
michael@13 284 done
michael@13 285 }
michael@13 286
michael@13 287 db_reload () {
michael@13 288 # rebuilding new from old RPM database DB files by dumping and
michael@13 289 # reloading their entire content
michael@13 290 verbose 2 "dumping and reloading RPM database DB file contents"
michael@13 291 for dbfile in $dbfiles; do
michael@13 292 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'`
michael@13 293 verbose 3 "dumping and reloading DB file: $dbpath/$dbfile ($dbtype)"
michael@13 294 if [ -f $dbpath/$dbfile ]; then
michael@13 295 if [ ".$dbtype" = .hash -o ".$dbtype" = .btree ]; then
michael@13 296 rpmdb_dump $dbpath/$dbfile |\
michael@13 297 rpmdb_load $dbpath/$dbfile.new
michael@13 298 rm -f $dbpath/$dbfile
michael@13 299 mv $dbpath/$dbfile.new $dbpath/$dbfile
michael@13 300 else
michael@13 301 rm -f $dbpath/$dbfile || true
michael@13 302 touch $dbpath/$dbfile || true
michael@13 303 fi
michael@13 304 fi
michael@13 305 done
michael@13 306 }
michael@13 307
michael@13 308 db_rebuild () {
michael@13 309 # perform official "rebuilddb" operation
michael@13 310 verbose 2 "rebuilding RPM database (built-in RPM procedure)"
michael@13 311 rpm --rebuilddb
michael@13 312 }
michael@13 313
michael@13 314 db_operate () {
michael@13 315 # perform some read/write operation on RPM database
michael@13 316 # (we have no package available, but removing and reimporting
michael@13 317 # the OpenPKG OpenPGP keys is a harmless thing and always possible)
michael@13 318 verbose 2 "performing read/write operation on RPM database"
michael@13 319 for spec in \
michael@13 320 openpkg.org.pgp:gpg-pubkey-63c4cb9f-3c591eda \
michael@13 321 openpkg.com.pgp:gpg-pubkey-61b7ae34-4544a6af \
michael@13 322 openpkg.net.pgp:gpg-pubkey-52197903-4544a74d \
michael@13 323 ; do
michael@13 324 eval `echo "$spec" | sed -e 's/^\(.*\):\(.*\)$/file="\1"; package="\2"/'`
michael@13 325 rpm -q $package >/dev/null 2>&1 && rpm -e $package --allmatches || true
michael@13 326 rpm -q $package >/dev/null 2>&1 || rpm --import $prefix/etc/openpkg/$file || true
michael@13 327 done
michael@13 328 rpm -qa >/dev/null 2>&1
michael@13 329 }
michael@13 330
michael@13 331 db_fixate () {
michael@13 332 # fix ownership and permissions of (especially newly created)
michael@13 333 # RPM database files to make sure they are consistent
michael@13 334 verbose 2 "making sure RPM database files have consistent attributes"
michael@13 335 for dbfile in $dbfiles; do
michael@13 336 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'`
michael@13 337 verbose 3 "fixating DB file: $dbpath/$dbfile ($dbtype)"
michael@13 338 chown $musr:$mgrp $dbpath/$dbfile 2>/dev/null || true
michael@13 339 chmod 644 $dbpath/$dbfile 2>/dev/null || true
michael@13 340 done
michael@13 341 }
michael@13 342
michael@13 343 db_list () {
michael@13 344 # list all database files
michael@13 345 for dbfile in $dbfiles; do
michael@13 346 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'`
michael@13 347 if [ $verbose -eq 0 ]; then
michael@13 348 echo "$dbfile"
michael@13 349 elif [ $verbose -eq 1 ]; then
michael@13 350 echo "$dbpath/$dbfile"
michael@13 351 elif [ $verbose -ge 2 ]; then
michael@13 352 echo "$dbpath/$dbfile ($dbtype)"
michael@13 353 fi
michael@13 354 done
michael@13 355 }
michael@13 356
michael@13 357 ##
michael@13 358 ## ENVIRONMENT CONSISTENCY CHECKS
michael@13 359 ##
michael@13 360
michael@13 361 # sanity check OpenPKG instance
michael@13 362 if [ ".$prefix" = . ]; then
michael@13 363 error "OpenPKG instance directory is empty"
michael@13 364 fi
michael@13 365 if [ ! -d $prefix ]; then
michael@13 366 error "OpenPKG instance directory \"$prefix\" not found"
michael@13 367 fi
michael@13 368 if [ ! -x $prefix/bin/openpkg ]; then
michael@13 369 error "OpenPKG instance directory \"$prefix\" not valid"
michael@13 370 fi
michael@13 371
michael@13 372 # sanity check OpenPKG RPM database
michael@13 373 if [ ".$dbpath" = . ]; then
michael@13 374 error "OpenPKG RPM database directory is empty"
michael@13 375 fi
michael@13 376 if [ ! -d $dbpath ]; then
michael@13 377 error "OpenPKG RPM database directory \"$dbpath\" not found"
michael@13 378 fi
michael@13 379 if [ ! -w $dbpath ]; then
michael@13 380 error "OpenPKG RPM database directory \"$dbpath\" not writable"
michael@13 381 fi
michael@13 382
michael@13 383 ##
michael@13 384 ## DISPATCH INTO COMMANDS
michael@13 385 ##
michael@13 386
michael@13 387 case "$mode" in
michael@13 388 build )
michael@13 389 verbose 1 "BUILDING NEW RPM DATABASE FROM SCRATCH ($dbpath)"
michael@13 390 db_remove
michael@13 391 db_init
michael@13 392 db_extend
michael@13 393 db_rebuild
michael@13 394 db_fixate
michael@13 395 db_operate
michael@13 396 ;;
michael@13 397
michael@13 398 rebuild )
michael@13 399 verbose 1 "REBUILDING NEW FROM OLD RPM DATABASE ($dbpath)"
michael@13 400 db_unbreak
michael@13 401 db_extend
michael@13 402 db_reload
michael@13 403 db_rebuild
michael@13 404 db_fixate
michael@13 405 db_operate
michael@13 406 ;;
michael@13 407
michael@13 408 cleanup )
michael@13 409 verbose 1 "CLEANING UP EXISTING RPM DATABASE ($dbpath)"
michael@13 410 db_unbreak
michael@13 411 db_extend
michael@13 412 db_rebuild
michael@13 413 db_fixate
michael@13 414 db_operate
michael@13 415 ;;
michael@13 416
michael@13 417 fixate )
michael@13 418 verbose 1 "FIXATING EXISTING RPM DATABASE ($dbpath)"
michael@13 419 db_extend
michael@13 420 db_fixate
michael@13 421 db_operate
michael@13 422 ;;
michael@13 423
michael@13 424 list )
michael@13 425 db_list
michael@13 426 ;;
michael@13 427 esac
michael@13 428
michael@13 429 exit 0
michael@13 430

mercurial