Provide workaround for systemd's systemctl failures on jessie
[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
19   TMPSTDOUT=$(mktemp)
20   TMPSTDERR=$(mktemp)
21
22   # 1) catch packages that aren't in state 'ii' (marked for installation
23   # and successfully instead) on stdout
24   # 2) catch error messages like 'dpkg-query: no packages found matching $package"
25   # for packages unknown to dpkg on stderr
26   # NOTE: 'grep -v -- '-$' ignores packages in FAI's package list that are
27   # marked for removal
28   $ROOTCMD dpkg --list $(grep -v '^#' $target/${PACKAGE_LIST} | grep -v -- '-$') 2>"$TMPSTDERR" | \
29     grep -e '^[urph][ncufhWt]' > "$TMPSTDOUT" || true
30
31   # extract packages from stdout
32   awk '/^un/ {print $2 " not_installable"}' "$TMPSTDOUT" > "$LOGDIR/package_errors.log"
33
34   # extract packages from stderr
35   grep 'packages found matching' "$TMPSTDERR" | \
36     sed 's/dpkg-query: [Nn]o packages found matching \(.*\)/\1 not_installable/' >> "$LOGDIR/package_errors.log"
37
38   if [ -s "$LOGDIR/package_errors.log" ] ; then
39     printf "failed (there have been errors, find them at $LOGDIR/package_errors.log)\n"
40   else
41     printf "done - no errors found\n"
42   fi
43
44   rm -f "$TMPSTDOUT" "$TMPSTDERR"
45 fi
46
47 ## END OF FILE #################################################################
48 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2