DEBORPHAN/10-whitelist: rework fix for broken keep file handling of deborphan
authorMichael Prokop <mika@grml.org>
Wed, 20 May 2020 14:10:29 +0000 (16:10 +0200)
committerMichael Prokop <mika@grml.org>
Wed, 20 May 2020 14:19:42 +0000 (16:19 +0200)
An empty file doesn't help either, so we need at least a file
with a newline. Given that we're already touching the file
based on its hard-coded filename, let's just append the package
in question and avoid invoking deborphan at all. Especially
as deborphan returns with failure when a package is already
listed:

| deborphan: dnsutils: duplicate entry.

We need to handle this anyway, if grml-live is re-executed on
an existing system (which isn't unusual).

etc/grml/fai/config/scripts/DEBORPHAN/10-whitelist

index 0c145f7..a689fec 100755 (executable)
@@ -14,8 +14,13 @@ set -e
 if [[ -r "${target}/usr/share/doc/dnsutils" ]] && [ -x "${target}/usr/bin/deborphan" ] ; then
   echo "Adding dnsutils to deborphan whitelist"
   # workaround for https://bugs.debian.org/929273 ("fseek on /var/lib/deborphan/keep: Invalid argument")
-  $ROOTCMD touch /var/lib/deborphan/keep
-  $ROOTCMD deborphan --add-keep dnsutils
+  if ! [ -f "${target}"/var/lib/deborphan/keep ] ; then
+    printf 'dnsutils\n' > "${target}"/var/lib/deborphan/keep
+  elif grep -q '^dnsutils$' "${target}"/var/lib/deborphan/keep ; then
+    : # entry already present, avoid duplicates
+  else
+    printf 'dnsutils\n' >> "${target}"/var/lib/deborphan/keep
+  fi
 fi
 
 ## END OF FILE #################################################################