openpkg/rpmdb

changeset 794
07be25b95aca
parent 13
cb59d6afeb61
equal deleted inserted replaced
0:c90a77e85139 1:17e17c6ee488
1 #!@l_prefix@/lib/openpkg/bash 1 #!@l_prefix@/lib/openpkg/bash
2 ## 2 ##
3 ## rpmdb -- OpenPKG RPM Database Administration Utility 3 ## rpmdb -- OpenPKG RPM Database Administration Utility
4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/> 4 ## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>
5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/> 5 ##
6 ## 6 ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
7 ## Permission to use, copy, modify, and distribute this software for 7 ## All rights reserved. Licenses which grant limited permission to use,
8 ## any purpose with or without fee is hereby granted, provided that 8 ## copy, modify and distribute this software are available from the
9 ## the above copyright notice and this permission notice appear in all 9 ## OpenPKG GmbH.
10 ## copies. 10 ##
11 ## 11 ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
12 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 12 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 13 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR 14 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 15 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 16 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 27
29 # configuration defaults 28 # configuration defaults
30 help="" 29 help=""
31 prefix="@l_prefix@" 30 prefix="@l_prefix@"
32 dbpath="" 31 dbpath=""
32 dbapi=""
33 tmpdir=""
33 rpm="" 34 rpm=""
34 musr="@l_musr@" 35 musr="@l_musr@"
35 mgrp="@l_mgrp@" 36 mgrp="@l_mgrp@"
36 mode="" 37 mode=""
37 force=no 38 force=no
40 ## 41 ##
41 ## PARSE COMMAND LINE 42 ## PARSE COMMAND LINE
42 ## 43 ##
43 44
44 # iterate over argument line 45 # iterate over argument line
46 args=""
45 for opt 47 for opt
46 do 48 do
47 case $opt in 49 case $opt in
48 -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;; 50 -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
49 *) arg='' ;; 51 *) arg='' ;;
50 esac 52 esac
51 case $opt in 53 case $opt in
52 -h|--help ) help="Usage" ;; 54 -h|--help ) help="Usage" ;;
53 -B|--build ) mode=build ;; 55 -B|--build ) mode=build ;;
56 -M|--migrate ) mode=migrate ;;
54 -R|--rebuild ) mode=rebuild ;; 57 -R|--rebuild ) mode=rebuild ;;
55 -C|--cleanup ) mode=cleanup ;; 58 -C|--cleanup ) mode=cleanup ;;
56 -F|--fixate ) mode=fixate ;; 59 -F|--fixate ) mode=fixate ;;
57 -L|--list ) mode=list ;; 60 -L|--list ) mode=list ;;
58 -f|--force ) force=yes ;; 61 -f|--force ) force=yes ;;
59 -q|--quiet ) verbose=0 ;; 62 -q|--quiet ) verbose=0 ;;
60 -v|--verbose ) verbose=`expr $verbose + 1` ;; 63 -v|--verbose ) verbose=`expr $verbose + 1` ;;
61 --prefix=* ) prefix=$arg ;; 64 --prefix=* ) prefix=$arg ;;
62 --dbpath=* ) dbpath=$arg ;; 65 --dbpath=* ) dbpath=$arg ;;
66 --dblib=* ) dblib=$arg ;;
67 --tmpdir=* ) tmpdir=$arg ;;
63 --rpm=* ) rpm=$arg ;; 68 --rpm=* ) rpm=$arg ;;
64 --musr=* ) musr=$arg ;; 69 --musr=* ) musr=$arg ;;
65 --mgrp=* ) mgrp=$arg ;; 70 --mgrp=* ) mgrp=$arg ;;
66 * ) help="Invalid option \`$opt'"; break ;; 71 -- ) ;;
72 -* ) help="Invalid option \`$opt'"; break ;;
73 * ) args="$args \"$opt\"" ;;
67 esac 74 esac
68 done 75 done
69 76 eval "set -- $args"
70 # makre sure exactly one run-time mode is specified 77
78 # make sure exactly one run-time mode is specified
71 if [ ".$mode" = . ]; then 79 if [ ".$mode" = . ]; then
72 help="No or invalid run-time mode specified" 80 help="No or invalid run-time mode specified"
73 fi 81 fi
74 82
75 # error or usage message 83 # error or usage message
80 cat 1>&2 <<EOT 88 cat 1>&2 <<EOT
81 $progname:USAGE: $progname [options] 89 $progname:USAGE: $progname [options]
82 90
83 -h, --help print usage message (this one) 91 -h, --help print usage message (this one)
84 -B, --build build new RPM database from scratch 92 -B, --build build new RPM database from scratch
93 -M, --migrate migrate RPM database to new format
85 -R, --rebuild rebuild new from old RPM database 94 -R, --rebuild rebuild new from old RPM database
86 -C, --cleanup cleanup existing RPM database 95 -C, --cleanup cleanup existing RPM database
87 -F, --fixate fixate existing RPM database 96 -F, --fixate fixate existing RPM database
88 -L, --list list all RPM database files 97 -L, --list list all RPM database files
89 -f, --force operate in force mode (no save operations) 98 -f, --force operate in force mode (no save operations)
90 -q, --quiet operate in quiet mode (no verbose messages at all) 99 -q, --quiet operate in quiet mode (no verbose messages at all)
91 -v, --verbose operate in more verbose mode (increase verbose level) 100 -v, --verbose operate in more verbose mode (increase verbose level)
92 --prefix=PREFIX use OpenPKG instance under PREFIX 101 --prefix=PREFIX use OpenPKG instance under PREFIX
93 --dbpath=PATH use OpenPKG RPM database under PATH 102 --dbpath=PATH use OpenPKG RPM database under PATH
103 --dblib=LIB use OpenPKG RPM database backend library ("db" or "sqlite")
104 --tmpdir=PATH use OpenPKG temporary directory under PATH
94 --rpm=PROG use OpenPKG RPM executable PROG 105 --rpm=PROG use OpenPKG RPM executable PROG
95 --musr=USERNAME use OpenPKG management user USERNAME 106 --musr=USERNAME use OpenPKG management user USERNAME
96 --mgrp=GROUPNAME use OpenPKG management group GROUPNAME 107 --mgrp=GROUPNAME use OpenPKG management group GROUPNAME
97 108
98 This is OpenPKG rpmdb, an RPM database administration utility, providing 109 This is OpenPKG rpmdb, an RPM database administration utility, providing
99 lower-level maintainance functions for the Berkeley-DB 4.1 based RPM 4.2 110 lower-level maintainance functions for the Berkeley-DB based RPM
100 database. It allows building new RPM databases from scratch, rebuilding 111 database. It allows building new RPM databases from scratch, rebuilding
101 a new from an old RPM database (content dumping and reloading), 112 a new from an old RPM database (content dumping and reloading),
102 cleaning up problems on an existing RPM database (removal of DB region 113 cleaning up problems on an existing RPM database (removal of DB region
103 files, etc) and fixating the files in an existing RPM database (file 114 files, etc) and fixating the files in an existing RPM database (file
104 attributes). 115 attributes).
113 124
114 # delayed determination of variables 125 # delayed determination of variables
115 if [ ".$dbpath" = . ]; then 126 if [ ".$dbpath" = . ]; then
116 dbpath="$prefix/RPM/DB" 127 dbpath="$prefix/RPM/DB"
117 fi 128 fi
129 if [ ".$dblib" = . ]; then
130 dblib="${1-db}"
131 fi
132 if [ ".$tmpdir" = . ]; then
133 tmpdir="$prefix/RPM/TMP"
134 fi
118 if [ ".$rpm" = . ]; then 135 if [ ".$rpm" = . ]; then
119 rpm="$prefix/bin/openpkg rpm" 136 rpm="$prefix/bin/openpkg rpm"
120 fi 137 fi
121 138
122 ## 139 ##
123 ## DATABASE FILE INFORMATION 140 ## DATABASE FILE INFORMATION
124 ## 141 ##
125 142
126 dbfiles=" 143 dbfiles="
127 hash:Basenames 144 3:btree:Basenames
128 hash:Conflictname 145 3:btree:Conflictname
129 hash:Depends 146 3:temporary:Depends
130 btree:Dirnames 147 3:btree:Dirnames
131 hash:Filemd5s 148 3:btree:Filedigests
132 hash:Group 149 3:btree:Filepaths
133 btree:Installtid 150 3:btree:Group
134 hash:Name 151 3:btree:Installtid
135 hash:Packages 152 3:btree:Name
136 hash:Providename 153 3:hash:Packagecolor
137 btree:Provideversion 154 3:btree:Packages
138 hash:Pubkeys 155 3:btree:Providename
139 hash:Requirename 156 3:btree:Provideversion
140 btree:Requireversion 157 3:hash:Pubkeys
141 hash:Sha1header 158 3:btree:Requirename
142 hash:Sigmd5 159 3:btree:Requireversion
143 hash:Triggername 160 3:hash:Sha1header
144 region:__db.001 161 3:hash:Sigmd5
145 region:__db.002 162 3:btree:Triggername
146 region:__db.003 163 3:btree:Obsoletename
147 region:__db.004 164 3:btree:Nvra
148 region:__db.005 165 3:btree:Sourcepkgid
149 region:__db.006 166 3:btree:BuildEnvironment
150 region:__db.007 167 3:region:__db.001
151 region:__db.008 168 3:region:__db.002
152 region:__db.009 169 3:region:__db.003
170 3:region:__db.004
171 3:region:__db.005
172 3:region:__db.006
173 3:region:__db.007
174 3:region:__db.008
175 3:region:__db.009
176 4:*:Basenames
177 4:*:Conflictname
178 4:temporary:Depends
179 4:*:Dirnames
180 4:*:Filedigests
181 4:*:Filepaths
182 4:*:Group
183 4:*:Installtid
184 4:*:Name
185 4:*:Packagecolor
186 4:*:Packages
187 4:*:Providename
188 4:*:Provideversion
189 4:*:Pubkeys
190 4:*:Requirename
191 4:*:Requireversion
192 4:*:Sha1header
193 4:*:Sigmd5
194 4:*:Triggername
195 4:*:Obsoletename
196 4:*:Nvra
197 4:*:Sourcepkgid
198 4:*:BuildEnvironment
153 " 199 "
154 200
155 ## 201 ##
156 ## HELPER FUNCTIONS 202 ## HELPER FUNCTIONS
157 ## 203 ##
178 esac 224 esac
179 echo "$progname: $lead$*" 1>&2 225 echo "$progname: $lead$*" 1>&2
180 fi 226 fi
181 } 227 }
182 228
229 rpmdb_version_load () {
230 if [ -f $dbpath/VERSION ]; then
231 eval `(. $dbpath/VERSION || exit $?; echo "DBAPI=\"$DBAPI\"; DBLIB=\"$DBLIB\"; DBVER=\"$DBVER\"")`
232 fi
233 if [ ".$DBAPI" = . ]; then DBAPI="3"; fi
234 if [ ".$DBLIB" = . ]; then DBLIB="db"; fi
235 if [ ".$DBVER" = . ]; then DBVER="4.1.2"; fi
236 }
237
238 rpmdb_version_save () {
239 if [ ".$DBAPI" = .3 ]; then
240 DBLIB="db"
241 DBVER=`$rpmdb_load -V 2>&1 |\
242 grep 'Berkeley DB [0-9][0-9]*\.[0-9][0-9]*' |\
243 sed -e 's;^;X;' \
244 -e 's;^X[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$;\1;' \
245 -e 's;^X[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1.0;' \
246 -e 's;^X.*$;0.0.0;'`
247 elif [ ".$DBAPI" = .4 ]; then
248 DBLIB="sqlite"
249 DBVER=`$rpmdb_sqlite --version 2>&1 |\
250 grep '^[0-9][0-9]*\.[0-9][0-9]*' |\
251 sed -e 's;^;X;' \
252 -e 's;^X[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$;\1;' \
253 -e 's;^X[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1.0;' \
254 -e 's;^X.*$;0.0.0;'`
255 fi
256 ( echo "DBAPI=$DBAPI"
257 echo "DBLIB=$DBLIB"
258 echo "DBVER=$DBVER"
259 ) >$dbpath/VERSION.new || exit $?
260 mv $dbpath/VERSION.new $dbpath/VERSION || exit $?
261 chown $musr:$mgrp $dbpath/VERSION 2>/dev/null || true
262 chmod 644 $dbpath/VERSION 2>/dev/null || true
263 }
264
183 rpm () { 265 rpm () {
184 local opts="--dbpath `echo $dbpath | sed -e 's;/*$;;' -e 's;$;/;'`" 266 local opts="--define '_dbpath `echo $dbpath | sed -e 's;/*$;;' -e 's;$;/;'`'"
267 opts="$opts --define '_repackage_all_erasures 0'"
185 if [ ".$force" = .yes ]; then 268 if [ ".$force" = .yes ]; then
186 opts="$opts --define '__dbi_private yes'" 269 opts="$opts --define '__dbi_private yes'"
187 fi 270 fi
188 verbose 3 "run: $rpm $opts $@" 271 verbose 3 "run: $rpm $opts $@"
189 eval "$rpm $opts \"\$@\"" 272 eval "$rpm $opts \"\$@\""
190 } 273 }
191 274
192 rpmdb_load () { 275 rpmdb_load="$prefix/lib/openpkg/db_tool load"
193 $prefix/lib/openpkg/rpmdb_load ${1+"$@"} 276 rpmdb_dump="$prefix/lib/openpkg/db_tool dump"
194 } 277 rpmdb_sqlite="$prefix/lib/openpkg/sqlite3"
195
196 rpmdb_dump () {
197 $prefix/lib/openpkg/rpmdb_dump ${1+"$@"}
198 }
199 278
200 ## 279 ##
201 ## RPM DATABASE OPERATIONS 280 ## RPM DATABASE OPERATIONS
202 ## 281 ##
203 282
223 302
224 db_remove () { 303 db_remove () {
225 # remove all known files 304 # remove all known files
226 verbose 2 "removing (possibly existing) old RPM database DB files" 305 verbose 2 "removing (possibly existing) old RPM database DB files"
227 for dbfile in $dbfiles; do 306 for dbfile in $dbfiles; do
228 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'` 307 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\):\(.*\)$/dbapi="\1"; dbtype="\2"; dbfile="\3";/'`
229 verbose 3 "removing database file: $dbpath/$dbfile ($dbtype)" 308 verbose 3 "removing database file: $dbpath/$dbfile ($dbapi:$dbtype)"
230 rm -f $dbpath/$dbfile 309 rm -f $dbpath/$dbfile
231 done 310 done
232 } 311 }
233 312
234 db_init () { 313 db_init () {
235 # perform official "initdb" operation 314 # perform official "initdb" operation
236 # (is mostly a no-operation in RPM 4.2, but anyway)
237 verbose 2 "creating new RPM database (built-in RPM procedure)" 315 verbose 2 "creating new RPM database (built-in RPM procedure)"
238 rpm --initdb 316 rpm --initdb
239 317 rpmdb_version_save
240 # perform some real RPM work, so more database files
241 # magically spring into existence
242 verbose 2 "operating on new RPM database"
243 rpm --import $prefix/etc/openpkg/openpkg.org.pgp || true
244 rpm -e gpg-pubkey-63c4cb9f-3c591eda --allmatches || true
245
246 # perform official "rebuilddb" operation in the hope it
247 # creates even more database files now that we have some content
248 verbose 2 "rebuilding new RPM database (built-in RPM procedure)"
249 rpm --rebuilddb
250 } 318 }
251 319
252 db_unbreak () { 320 db_unbreak () {
253 # cleanup DB region files 321 # cleanup DB files
254 verbose 2 "cleaning up RPM database DB region files" 322 verbose 2 "cleaning up RPM database DB files"
255 for dbfile in $dbfiles; do 323 for dbfile in $dbfiles; do
256 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'` 324 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\):\(.*\)$/dbapi="\1"; dbtype="\2"; dbfile="\3";/'`
257 if [ ".$dbtype" = .region ]; then 325 if [ -f $dbpath/$dbfile ]; then
258 verbose 3 "cleaning up DB file: $dbpath/$dbfile ($dbtype)" 326 if [ ".$dbapi" = .3 -a ".$dbtype" = .region ]; then
259 rm -f $dbpath/$dbfile || true 327 verbose 3 "cleaning up DB file: $dbpath/$dbfile ($dbapi:$dbtype)"
260 touch $dbpath/$dbfile || true 328 rm -f $dbpath/$dbfile || true
261 fi 329 elif [ ".$dbtype" = .temporary ]; then
262 done 330 verbose 3 "cleaning up DB file: $dbpath/$dbfile ($dbapi:$dbtype)"
263 } 331 rm -f $dbpath/$dbfile || true
264 332 fi
265 db_extend () { 333 fi
266 # make sure all RPM database DB files are present 334 done
267 verbose 2 "making sure RPM database contains all possible DB files" 335 }
336
337 db_convert () {
338 # make sure all RPM database DB files have the correct type
339 # (as the type can be different during upgrading from RPM 4 to RPM 5)
340 verbose 2 "making sure RPM database are of the correct type"
268 for dbfile in $dbfiles; do 341 for dbfile in $dbfiles; do
269 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'` 342 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\):\(.*\)$/dbapi="\1"; dbtype="\2"; dbfile="\3";/'`
270 if [ ! -f $dbpath/$dbfile ]; then 343 if [ ".$dbapi" != ".$DBAPI" ]; then
271 verbose 3 "creating DB file: $dbpath/$dbfile ($dbtype)" 344 continue
272 if [ ".$dbtype" = .hash -o ".$dbtype" = .btree ]; then 345 fi
273 ( echo "VERSION=3" 346 if [ -f $dbpath/$dbfile ]; then
274 echo "format=bytevalue" 347 if [ ".$dbapi" = .3 ] && [ ".$dbtype" = .hash -o ".$dbtype" = .btree ]; then
275 echo "type=$dbtype" 348 dbtype_old="`$rpmdb_dump -h $tmpdir -r $dbpath/$dbfile | grep '^type=' | sed -e 'q' | sed -e 's/^type=//'`"
276 echo "db_pagesize=16384" 349 if [ ".$dbtype_old" != ".$dbtype" ]; then
277 echo "HEADER=END" 350 verbose 3 "converting DB file: $dbpath/$dbfile ($dbtype_old -> $dbtype)"
278 echo "DATA=END" 351 rm -f $dbpath/$dbfile.new
279 ) | rpmdb_load $dbpath/$dbfile || true 352 $rpmdb_dump -h $tmpdir -r $dbpath/$dbfile |\
280 else 353 sed -e "s/^type=.*/type=$dbtype/" -e '/^h_nelem=.*/d' |\
281 touch $dbpath/$dbfile || true 354 $rpmdb_load -h $tmpdir $dbpath/$dbfile.new
355 if $rpmdb_dump -h $tmpdir -r $dbpath/$dbfile.new >/dev/null 2>&1; then
356 rm -f $dbpath/$dbfile
357 mv $dbpath/$dbfile.new $dbpath/$dbfile
358 else
359 warning "failed to convert RPM DB file \"$dbfile\""
360 fi
361 fi
282 fi 362 fi
283 fi 363 fi
284 done 364 done
285 } 365 }
286 366
287 db_reload () { 367 db_reload () {
288 # rebuilding new from old RPM database DB files by dumping and 368 # rebuilding new from old RPM database DB files by dumping and
289 # reloading their entire content 369 # reloading their entire content
290 verbose 2 "dumping and reloading RPM database DB file contents" 370 verbose 2 "dumping and reloading RPM database DB file contents"
291 for dbfile in $dbfiles; do 371 for dbfile in $dbfiles; do
292 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'` 372 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\):\(.*\)$/dbapi="\1"; dbtype="\2"; dbfile="\3";/'`
293 verbose 3 "dumping and reloading DB file: $dbpath/$dbfile ($dbtype)" 373 if [ ".$dbapi" != ".$DBAPI" ]; then
374 continue
375 fi
294 if [ -f $dbpath/$dbfile ]; then 376 if [ -f $dbpath/$dbfile ]; then
295 if [ ".$dbtype" = .hash -o ".$dbtype" = .btree ]; then 377 if [ ".$dbapi" = .3 ]; then
296 rpmdb_dump $dbpath/$dbfile |\ 378 verbose 3 "dumping and reloading DB file: $dbpath/$dbfile ($dbtype)"
297 rpmdb_load $dbpath/$dbfile.new 379 if [ ".$dbtype" = .hash -o ".$dbtype" = .btree ]; then
298 rm -f $dbpath/$dbfile 380 rm -f $dbpath/$dbfile.new
299 mv $dbpath/$dbfile.new $dbpath/$dbfile 381 $rpmdb_dump -h $tmpdir -r $dbpath/$dbfile |\
300 else 382 $rpmdb_load -h $tmpdir $dbpath/$dbfile.new
301 rm -f $dbpath/$dbfile || true 383 if $rpmdb_dump -h $tmpdir -r $dbpath/$dbfile.new >/dev/null 2>&1; then
302 touch $dbpath/$dbfile || true 384 rm -f $dbpath/$dbfile
385 mv $dbpath/$dbfile.new $dbpath/$dbfile
386 else
387 warning "failed to reload RPM DB file \"$dbfile\""
388 fi
389 elif [ ".$dbtype" = .region ]; then
390 rm -f $dbpath/$dbfile || true
391 elif [ ".$dbtype" = .temporary ]; then
392 rm -f $dbpath/$dbfile || true
393 fi
394 elif [ ".$dbapi" = .4 ]; then
395 verbose 3 "dumping and reloading DB file: $dbpath/$dbfile ($dbtype)"
396 rm -f $dbpath/$dbfile.new
397 $rpmdb_sqlite $dbpath/$dbfile .dump |\
398 $rpmdb_sqlite $dbpath/$dbfile.new
399 if $rpmdb_sqlite $dbpath/$dbfile.new >/dev/null 2>&1; then
400 rm -f $dbpath/$dbfile
401 mv $dbpath/$dbfile.new $dbpath/$dbfile
402 else
403 warning "failed to reload RPM DB file \"$dbfile\""
404 fi
303 fi 405 fi
304 fi 406 fi
305 done 407 done
408 rpmdb_version_save
409 }
410
411 db_migrate () {
412 # perform database migration
413 if [ ".$1" != . ]; then
414 dblib="$1"
415 fi
416 dbapi_old="$DBAPI"
417 if [ ".$dblib" = .db ]; then
418 dbapi_new="3"
419 elif [ ".$dblib" = .sqlite ]; then
420 dbapi_new="4"
421 else
422 error "unknown RPM database backend library \"$dblib\""
423 fi
424 if [ ".$dbapi_new" = ".$dbapi_old" ]; then
425 error "RPM database already uses requested backend ($DBAPI:$DBLIB:$DBVER)"
426 fi
427 verbose 2 "migrating RPM database"
428 rpm --rebuilddb --dbapi "$dbapi_old" --rebuilddbapi "$dbapi_new"
429 verbose 3 "old RPM database format: $DBAPI:$DBLIB:$DBVER"
430 DBAPI="$dbapi_new"
431 rpmdb_version_save
432 rpmdb_version_load
433 verbose 3 "new RPM database format: $DBAPI:$DBLIB:$DBVER"
306 } 434 }
307 435
308 db_rebuild () { 436 db_rebuild () {
309 # perform official "rebuilddb" operation 437 # perform official "rebuilddb" operation
310 verbose 2 "rebuilding RPM database (built-in RPM procedure)" 438 verbose 2 "rebuilding RPM database (built-in RPM procedure)"
311 rpm --rebuilddb 439 rpm --rebuilddb
440 rpmdb_version_save
312 } 441 }
313 442
314 db_operate () { 443 db_operate () {
315 # perform some read/write operation on RPM database 444 # perform some read/write operation on RPM database
316 # (we have no package available, but removing and reimporting 445 # (we have no package available, but removing and reimporting
331 db_fixate () { 460 db_fixate () {
332 # fix ownership and permissions of (especially newly created) 461 # fix ownership and permissions of (especially newly created)
333 # RPM database files to make sure they are consistent 462 # RPM database files to make sure they are consistent
334 verbose 2 "making sure RPM database files have consistent attributes" 463 verbose 2 "making sure RPM database files have consistent attributes"
335 for dbfile in $dbfiles; do 464 for dbfile in $dbfiles; do
336 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'` 465 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\):\(.*\)$/dbapi="\1"; dbtype="\2"; dbfile="\3";/'`
466 if [ ".$dbapi" != ".$DBAPI" ]; then
467 continue
468 fi
337 verbose 3 "fixating DB file: $dbpath/$dbfile ($dbtype)" 469 verbose 3 "fixating DB file: $dbpath/$dbfile ($dbtype)"
338 chown $musr:$mgrp $dbpath/$dbfile 2>/dev/null || true 470 if [ -f $dbpath/$dbfile ]; then
339 chmod 644 $dbpath/$dbfile 2>/dev/null || true 471 chown $musr:$mgrp $dbpath/$dbfile 2>/dev/null || true
340 done 472 chmod 644 $dbpath/$dbfile 2>/dev/null || true
473 fi
474 done
475 chown $musr:$mgrp $dbpath/VERSION 2>/dev/null || true
476 chmod 644 $dbpath/VERSION 2>/dev/null || true
341 } 477 }
342 478
343 db_list () { 479 db_list () {
344 # list all database files 480 # list all database files
345 for dbfile in $dbfiles; do 481 for dbfile in $dbfiles; do
346 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\)$/dbtype="\1"; dbfile="\2";/'` 482 eval `echo $dbfile | sed -e 's/^\(.*\):\(.*\):\(.*\)$/dbapi="\1"; dbtype="\2"; dbfile="\3";/'`
483 if [ ".$dbapi" != ".$DBAPI" ]; then
484 continue
485 fi
486 if [ ! -f "$dbpath/$dbfile" ]; then
487 continue
488 fi
347 if [ $verbose -eq 0 ]; then 489 if [ $verbose -eq 0 ]; then
348 echo "$dbfile" 490 echo "$dbfile"
349 elif [ $verbose -eq 1 ]; then 491 elif [ $verbose -eq 1 ]; then
350 echo "$dbpath/$dbfile" 492 echo "$dbpath/$dbfile"
351 elif [ $verbose -ge 2 ]; then 493 elif [ $verbose -ge 2 ]; then
378 fi 520 fi
379 if [ ! -w $dbpath ]; then 521 if [ ! -w $dbpath ]; then
380 error "OpenPKG RPM database directory \"$dbpath\" not writable" 522 error "OpenPKG RPM database directory \"$dbpath\" not writable"
381 fi 523 fi
382 524
525 # load database information
526 rpmdb_version_load
527
383 ## 528 ##
384 ## DISPATCH INTO COMMANDS 529 ## DISPATCH INTO COMMANDS
385 ## 530 ##
386 531
387 case "$mode" in 532 case "$mode" in
388 build ) 533 build )
389 verbose 1 "BUILDING NEW RPM DATABASE FROM SCRATCH ($dbpath)" 534 verbose 1 "BUILDING NEW RPM DATABASE FROM SCRATCH ($dbpath)"
390 db_remove 535 db_remove
391 db_init 536 db_init
392 db_extend 537 db_fixate
538 db_operate
539 ;;
540
541 migrate )
542 verbose 1 "MIGRATING RPM DATABASE FORMAT ($dbpath)"
543 db_unbreak
544 db_convert
545 db_migrate
393 db_rebuild 546 db_rebuild
394 db_fixate 547 db_fixate
395 db_operate 548 db_operate
396 ;; 549 ;;
397 550
398 rebuild ) 551 rebuild )
399 verbose 1 "REBUILDING NEW FROM OLD RPM DATABASE ($dbpath)" 552 verbose 1 "REBUILDING NEW FROM OLD RPM DATABASE ($dbpath)"
400 db_unbreak 553 db_unbreak
401 db_extend 554 db_convert
402 db_reload 555 db_reload
403 db_rebuild 556 db_rebuild
404 db_fixate 557 db_fixate
405 db_operate 558 db_operate
406 ;; 559 ;;
407 560
408 cleanup ) 561 cleanup )
409 verbose 1 "CLEANING UP EXISTING RPM DATABASE ($dbpath)" 562 verbose 1 "CLEANING UP EXISTING RPM DATABASE ($dbpath)"
410 db_unbreak 563 db_unbreak
411 db_extend 564 db_convert
412 db_rebuild 565 db_rebuild
413 db_fixate 566 db_fixate
414 db_operate 567 db_operate
415 ;; 568 ;;
416 569
417 fixate ) 570 fixate )
418 verbose 1 "FIXATING EXISTING RPM DATABASE ($dbpath)" 571 verbose 1 "FIXATING EXISTING RPM DATABASE ($dbpath)"
419 db_extend
420 db_fixate 572 db_fixate
421 db_operate
422 ;; 573 ;;
423 574
424 list ) 575 list )
425 db_list 576 db_list
426 ;; 577 ;;

mercurial