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