SW: add f2fs-tools to GRML_SMALL + GRML_FULL
[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 echo -n > "${LOGDIR}"/package_errors.log  # ensure we start with an empty file
13
14 if ! [ -e "${LOGDIR}"/software.log ] ; then
15   echo "Warning: no ${LOGDIR}/software.log found (build/update run?), skipping check for unknown packages."
16 else
17   if grep -q 'These unknown packages' "${LOGDIR}"/software.log ; then
18     echo "Identified unknown packages in ${LOGDIR}/software.log"
19     grep 'These unknown packages' "${LOGDIR}"/software.log | \
20       sed 's/.*These unknown packages.*: //; s/ / not_installable\n/g' >> "${LOGDIR}/package_errors.log"
21   fi
22 fi
23
24 PACKAGE_LIST=/var/log/install_packages.list
25 # shellcheck disable=SC2154
26 if ! [ -r "${target}/${PACKAGE_LIST}" ] ; then
27   echo "No ${target}/${PACKAGE_LIST} found, will not run package validation check."
28 else
29   echo "Validating package list against dpkg state..."
30
31   TMPSTDOUT=$(mktemp)
32   TMPSTDERR=$(mktemp)
33
34   # 1) catch packages that aren't in state 'ii' (marked for installation
35   # and successfully instead) on stdout
36   # 2) catch error messages like 'dpkg-query: no packages found matching $package"
37   # for packages unknown to dpkg on stderr
38   # NOTE: 'grep -v -- '-$' ignores packages in FAI's package list that are
39   # marked for removal
40   # shellcheck disable=SC2046
41   ${ROOTCMD} dpkg --list $(grep -v '^#' "${target}/${PACKAGE_LIST}" | grep -v -- '-$') 2>"${TMPSTDERR}" | \
42     grep -e '^[urph][ncufhWt]' > "${TMPSTDOUT}" || true
43
44   # extract packages from stdout
45   awk '/^un/ {print $2 " not_installable"}' "${TMPSTDOUT}" >> "${LOGDIR}/package_errors.log"
46
47   # extract packages from stderr
48   grep 'packages found matching' "${TMPSTDERR}" | \
49     sed 's/dpkg-query: [Nn]o packages found matching \(.*\)/\1 not_installable/' >> "${LOGDIR}/package_errors.log"
50
51   rm -f "${TMPSTDOUT}" "${TMPSTDERR}"
52 fi
53
54 if [ -s "${LOGDIR}/package_errors.log" ] ; then
55   echo "Warning: failed (there have been errors, find them at ${LOGDIR}/package_errors.log)."
56 else
57   echo "Done - no errors found."
58 fi
59
60 ## END OF FILE #################################################################
61 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2