Generate empty /lib/udev/rules.d/69-lvm-metad.rules instead of removing the file
[grml-live.git] / db / db-to-fai
1 #!/bin/sh
2 # Filename:      db-to-fai
3 # Purpose:       convert output of grml-live's sqlite database for use within FAI
4 # Authors:       grml-team (grml.org)
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 if [ -z "$2" ] ; then
10   echo "Usage: $0 /path/to/grml-live.db <build-id>"
11   exit 1
12 fi
13
14 DB="$1"
15 BUILD_ID="$2"
16
17 if ! [ -r "$DB" ] ; then
18   echo "Error: can not access database ${DB}.">&2
19   bailout 1
20 fi
21
22 TMPFILE=$(mktemp)
23
24 bailout() {
25   rm -f "$TMPFILE"
26   [ -n "$1" ] && exit "$1" || exit 0
27 }
28
29 # get information from db:
30 if ! echo "select package,version FROM packages, build WHERE build.id = $BUILD_ID AND packages.build = build.id and status = 'ii';" | sqlite3 $DB > $TMPFILE ; then
31    echo "Error retrieving values from database ${DB}." >&2
32    bailout 1
33 else
34    # make sure we god some matches:
35    if ! grep -q '^[a-zA-Z]*' "$TMPFILE" ; then
36       echo "No packages retrieved from build id $BUILD_ID - wrong id?" >&2
37       bailout 1
38    fi
39
40    # write fai header and package information to stdout:
41    echo "# package list of build $BUILD_ID from database $DB:"
42    echo "PACKAGES install"
43    awk -F\| '{print $1"="$2}' "$TMPFILE"
44 fi
45
46 # clean exit:
47 bailout
48
49 ## END OF FILE #################################################################