Permalink
Browse files

grml-live-db: Replace --db option with --database and use --dpkg for …

…handling dpkg file.
  • Loading branch information...
1 parent c7aa2bc commit fc0c329616fc039b242bd06e233c01e652b5703b @mika mika committed Jan 30, 2010
Showing with 59 additions and 39 deletions.
  1. +34 −21 db/dpkg-to-db
  2. +20 −17 docs/grml-live-db.txt
  3. +5 −1 grml-live
View
@@ -18,27 +18,30 @@ use DBI;
use Date::Format;
-my ($db, $logfile, $flavour, $help);
+my ($db, $logfile, $flavour, $help, $dpkgfile);
my $rc = GetOptions (
- 'db|d=s' => \$db,
- 'logfile|l=s' => \$logfile,
- 'flavour|f=s' => \$flavour,
- 'help|h' => \$help,
+ 'database|db=s' => \$db,
+ 'dpkg|d=s' => \$dpkgfile,
+ 'logfile|l=s' => \$logfile,
+ 'flavour|f=s' => \$flavour,
+ 'help|h' => \$help,
);
pod2usage(1) if $help;
-pod2usage(-message => "$0: Need a sqlite database.\n") unless $db;
-pod2usage(-message => "$0: Need a logfile to insert.\n") unless $logfile;
-pod2usage(-message => "$0: Need the flavour information\n") unless $flavour;
+pod2usage(-message => "$0: Need a sqlite database through --database ....\n") unless $db;
+pod2usage(-message => "$0: Need a logfile to insert through --database ...\n") unless $logfile;
+pod2usage(-message => "$0: Need the flavour information through --flavour ...\n") unless $flavour;
+pod2usage(-message => "$0: Need the dpkg file through --dpkg ...\n") unless $dpkgfile;
+
+open (my $fh, '<', $logfile) or die "Could not open $logfile: $!";
+open (my $dpkg_handle, '<', $dpkgfile) or die "Could not open $dpkgfile: $!";
my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","") or die "Could not connect to database: " . $DBI::err;
# We use foreign key - beware this needs sqlite > 3.6.19
$dbh->do("PRAGMA foreign_keys = ON");
-open (my $fh, '<', $logfile) or die "Could not open $logfile: $!";
-
# read content of log file - please do not try this at home :)
my $log = do { local $/; <$fh> };
@@ -90,7 +93,7 @@ die "No id?" unless $id;
$sth = $dbh->prepare("INSERT into packages (package, status, version, build) VALUES (?,?,?,?)")
or die "Could not prepare db statement: " . $dbh->errstr;
-while (my $line = <>) {
+while (my $line = <$dpkg_handle>) {
next unless $line =~ /^[a-z]{2} /;
# remove new lines
my ($status, $package, $version, $desc) = split (/\s+/, $line, 4);
@@ -112,28 +115,38 @@ dpkg-to-db - add grml build information into a sqlite database
=head1 SYNOPSIS
-dpkg-to-db [options]
-
- Options:
- --help brief help message
- --db <database> database file
- --logfile <logfile> logfile which should be added
- --flavour <flavour> which flavour the build is
+dpkg-to-db <options>
=head1 OPTIONS
=over 8
-=item B<-help>
+=item B<--help>
Print a brief help message and exits.
+=item B<--database <database>>
+
+Database file.
+
+=item B<--dpkg <dpkglist>>
+
+`dpkg --list` output file of grml-live build.
+
+=item B<--logfile <logfile>>
+
+Logfile which should be added.
+
+=item B<--flavour <flavour>>
+
+Name of the grml-flavour the build is.
+
=back
=head1 DESCRIPTION
-B<dpkg-to-db> will read the given input file(s) which holds output of
-`dpkg --list' and writes the information to the specified database.
+B<dpkg-to-db> will read the given input file(s) and stores the
+information to the specified database.
=head1 USAGE EXAMPLES
View
@@ -7,7 +7,7 @@ grml-live-db - log package build information of grml-live to database
Synopsis
--------
-dpkg-to-db [ options ] || db-to-fai /path/to/grml-live.db <build-id> |
+dpkg-to-db [ options ] || db-to-fai /path/to/grml-live.db <build-id>
Introduction
------------
@@ -22,9 +22,9 @@ Provided scripts
----------------
/usr/share/grml-live-db/scripts/dpkg-to-db adds grml-live build information
-(output of 'dpkg --list') and (optionally) a logfile into a sqlite3 database.
-This script is used by default if grml-live-db is installed (no configuration
-needed by default).
+(output of 'dpkg --list') and a logfile into a sqlite3 database. This script is
+used by default if grml-live-db is installed (no configuration needed by
+default).
/usr/share/grml-live-db/scripts/db-to-fai converts output of grml-live's sqlite
database for use within FAI. This script is useful if you want to reproduce a
@@ -34,16 +34,21 @@ according Debian mirrors providing all the specific package versions of course.
Options
-------
-dpkg-to-db supports the following options:
+dpkg-to-db supports the following options (and all except for --help
+are mandatory!):
--help
-Brief help message.
+Print help message and exit.
- --db <database>
+ --database <database>
Use specified database file.
+ --dpkg <dpkgfile>
+
+Use specified dpkgfile as `dpkg --list` output file of grml-live build.
+
--logfile <logfile>
Logfile thath should be added to the database entry.
@@ -52,8 +57,8 @@ Logfile thath should be added to the database entry.
Name of the grml-live flavour that was being built.
-db-to-fai does not support any options but needs to be invoked
-with path to the grml-live database and the build id.
+The db-to-fai script does not support any options but needs to be invoked with
+path to the grml-live database and the build id.
Configuration and using custom database wrapper scripts
-------------------------------------------------------
@@ -63,31 +68,29 @@ The following configuration variables are available and can be adjusted:
DPKG_DATABASE=/var/log/grml-live.db
Path to the database file that should be used for storing the build information.
-This database is ysed within dpkg-to-db by default.
+This database is used within dpkg-to-db by default.
DPKG_DBSCRIPT=/usr/share/grml-live-db/scripts/dpkg-to-db
The database wrapper script that's used for storing the build information.
If you do not want to log to the sqlite3 database but instead use your own
abstraction layer just point this variable to your favourite script.
- DPKG_DBOPTIONS="-d $DPKG_DATABASE --logfile $LOGFILE --flavour $GRML_NAME < $DPKG_LIST"
+ DPKG_DBOPTIONS="--database $DPKG_DATABASE --logfile $LOGFILE --flavour $GRML_NAME --dpkg $DPKG_LIST"
If the database script ($DPKG_DBSCRIPT) requires any command line options
-specifiy it through this variable.
+specify it through this variable.
Usage Examples
--------------
How dpkg-to-db is being used inside grml-live:
- /usr/share/grml-live-db/scripts/dpkg-to-db -d /var/log/grml-live.db --logfile /var/log/grml-live.log --flavour $GRML_NAME < /var/log/fai/$HOSTNAME/last/dpkg.list
+ /usr/share/grml-live-db/scripts/dpkg-to-db --database /var/log/grml-live.db --logfile /var/log/grml-live.log --flavour $GRML_NAME --dpkg /var/log/fai/$HOSTNAME/last/dpkg.list
Manually insert data to database:
- # /usr/share/grml-live-db/scripts/dpkg-to-db -d ./grml-live.db --logfile /tmp/logfile --flavour grml-full < ./dpkg.list
-
- # dpkg -l | ./dpkg-to-db --db ./grml-live.db --logfile /tmp/logfile --flavour grml-full
+ # /usr/share/grml-live-db/scripts/dpkg-to-db --database ./grml-live.db --logfile /tmp/logfile --flavour grml-full --dpkg ./dpkg.list
Retrieve build information of a specific build for use within FAI:
@@ -97,7 +100,7 @@ Describe schema of database:
# echo '.schema' | sqlite3 /var/log/grml-live.db
-Query database:
+Database queries:
# echo 'SELECT package,version,status,build.flavour,build.identifier FROM packages, build WHERE build.identifier = "grml-full-20091213012517" AND packages.build = build.id ; ' | sqlite3 /var/log/grml-live.db
View
@@ -1142,9 +1142,10 @@ if [ -d /usr/share/grml-live-db ] ; then
DPKG_LIST="/var/log/fai/$HOSTNAME/last/dpkg.list" # the dpkg --list output of the chroot:
[ -n "$DPKG_DATABASE" ] || DPKG_DATABASE=/var/log/grml-live.db
[ -n "$DPKG_DBSCRIPT" ] || DPKG_DBSCRIPT=/usr/share/grml-live-db/scripts/dpkg-to-db
- [ -n "$DPKG_DBOPTIONS" ] || DPKG_DBOPTIONS="-d $DPKG_DATABASE --logfile $LOGFILE --flavour $GRML_NAME < $DPKG_LIST"
+ [ -n "$DPKG_DBOPTIONS" ] || DPKG_DBOPTIONS="--database $DPKG_DATABASE --logfile $LOGFILE --flavour $GRML_NAME --dpkg $DPKG_LIST"
if ! [ -x "$DPKG_DBSCRIPT" ] ; then
+ log "Error: $DPKG_DBSCRIPT is not executable, can not log dpkg information."
eerror "Error: $DPKG_DBSCRIPT is not executable, can not log dpkg information." ; eend 1
bailout 14
fi
@@ -1156,10 +1157,13 @@ if [ -d /usr/share/grml-live-db ] ; then
#fi
if ! [ -r "$DPKG_LIST" ] ; then
+ log "Error reading $DPKG_LIST - can not provide information to $DPKG_DBSCRIPT"
eerror "Error reading $DPKG_LIST - can not provide information to $DPKG_DBSCRIPT" ; eend 1
bailout 14
else
einfo "Logging $DPKG_LIST to database $DPKG_DATABASE"
+ log "Logging $DPKG_LIST to database $DPKG_DATABASE"
+ log "Executing $DPKG_DBSCRIPT $DPKG_DBOPTIONS"
eindent
if DB_INFO=$("$DPKG_DBSCRIPT" $DPKG_DBOPTIONS 2>&1) ; then

0 comments on commit fc0c329

Please sign in to comment.