Package validation: also detect packages that failed to install
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 01-packages
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/01-packages
3 # Purpose:       check for packages that have been requested but could not be installed
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@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 set -u
10 set -e
11
12 PACKAGE_LIST=/var/log/install_packages.list
13
14 if ! [ -r "$target/${PACKAGE_LIST}" ] ; then
15    echo "No $target/${PACKAGE_LIST} found, will not run package validation check."
16 else
17    printf "Validating package list: "
18    TMPFILE=$(mktemp)
19
20    $ROOTCMD dpkg --list $(grep -v '^#' $target/${PACKAGE_LIST} | grep -v -- '-$') 2>&1 | \
21      grep -e '^un' -e 'No packages' > "$TMPFILE" || true
22
23    awk '/^un/ {print $2 " not_installable"}' "$TMPFILE" > "$LOGDIR/package_errors.log"
24    awk '/^No packages found matching/ {print $5 " not_available"}' "$TMPFILE" | \
25      sed 's/\. / /' >> "$LOGDIR/package_errors.log"
26
27    if [ -s "$TMPFILE" ] ; then
28       printf "failed (there have been errors, find them at $LOGDIR/package_errors.log)\n"
29    else
30       printf "done - no errors found\n"
31    fi
32
33    rm -f "$TMPFILE"
34 fi
35
36 ## END OF FILE #################################################################
37 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2