GRMLBASE/98-clean-chroot: execute resolvconf workarounds also for systemd
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 98-clean-chroot
index c5199aa..88cba00 100755 (executable)
@@ -9,7 +9,7 @@
 set -u
 set -e
 
-if ! [ $(ls $target/boot/config-* 2>/dev/null) ] ; then
+if ! ls $target/boot/config-* &>/dev/null ; then
   echo "No kernel config files (/boot/config-*) found. No kernel-image package installed?" >&2
   exit 1
 fi
@@ -17,22 +17,37 @@ fi
 echo "Creating ~/.zshrc"
 touch $target/root/.zshrc
 
+$ROOTCMD rm -f /etc/apt/apt.conf.d/90grml-apt-proxy.conf
+
 if [ -x $target/usr/sbin/localepurge ] ; then
   echo "Running localepurge"
   $ROOTCMD localepurge
 else
-  echo "Warning: localepurg not installed"
+  echo "Warning: localepurge not installed"
+fi
+
+# revert dpkg-divert of hooks/instsoft.GRMLBASE, which is
+# used to work around /etc/kernel/postinst.d/zz-update-grub failing
+# inside openvz environment, see #597084
+if $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/update-grub' ; then
+  echo "Undoing dpkg-divert of update-grub executable"
+  $ROOTCMD rm -f /usr/sbin/update-grub
+  $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-grub
 fi
 
-echo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
-rm -f $target/var/lib/apt/lists/*Packages \
-      $target/var/lib/apt/lists/*Release \
-      $target/var/lib/apt/lists/*Sources \
-      $target/var/lib/apt/lists/*IndexDiff \
-      $target/var/lib/apt/lists/*.gpg \
-      $target/var/cache/apt-show-versions/* \
-      $target/var/cache/debconf/templates.dat-old \
-      $target/var/cache/apt/*.bin
+# revert dpkg-divert of hooks/instsoft.GRMLBASE, which is
+# used to work around a grub-probe<->openvz bug
+if $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/grub-probe' ; then
+  echo "Undoing dpkg-divert of grub-probe executable"
+  $ROOTCMD rm -f /usr/sbin/grub-probe
+  $ROOTCMD dpkg-divert --rename --remove /usr/sbin/grub-probe
+fi
+
+# revert udev workaround of hooks/updatebase.GRMLBASE
+if grep -q 'updatebase.GRMLBASE' ${target}/etc/udev/kernel-upgrade 2>/dev/null ; then
+  echo "Removing /etc/udev/kernel-upgrade created by updatebase.GRMLBASE"
+  $ROOTCMD rm -f /etc/udev/kernel-upgrade
+fi
 
 echo "Cleaning apt places"
 $ROOTCMD apt-get check 2>/dev/null
@@ -57,6 +72,9 @@ fi
 echo "Removing host ssh-keys"
 rm -f $target/etc/ssh/*key*
 
+echo "Removing dbus machine-id"
+rm -f $target/var/lib/dbus/machine-id
+
 if [ -d $target/var/spool/squid/ ] ; then
   echo "Cleaning /var/spool/squid/0*"
   rm -rf $target/var/spool/squid/0*
@@ -64,10 +82,11 @@ fi
 
 echo "Cleaning and removing some misc files and directories"
 find $target/etc -type f -name *.pre_fcopy -delete
+find $target/etc -type l -name *.pre_fcopy -delete
 rm -rf --one-file-system $target/etc/sysconfig/* \
        $target/etc/motd.dpkg-* $target/etc/auto.master.*dpkg* \
        $target/etc/samba/*.SID $target/etc/samba/*.tdb \
-       $target/var/run $target/var/log/ksymoops/* $target/var/lock/*  \
+       $target/var/log/ksymoops/* \
        $target/var/state/* $target/var/log/nessus/* \
        $target/halt $target/reboot $target/ash.static \
        $target/etc/dhcpc/*.info $target/etc/dhcpc/resolv* \
@@ -75,9 +94,10 @@ rm -rf --one-file-system $target/etc/sysconfig/* \
        $target/etc/*group- $target/var/spool/postfix/maildrop/* \
        $target/etc/*.old $target/etc/*.original \
        $target/etc/lvm/.cache $target/etc/lvm/cache/.cache \
-       $target/etc/lvm/backup/main $target/tmp/* \
+       $target/etc/lvm/backup/* $target/tmp/* \
        $target/var/tmp/* $target/var/backups/* \
-       $target/var/lib/mysql $target/var/log/lilo_log.* $target/core*
+       $target/var/lib/mysql $target/var/log/lilo_log.* $target/core* \
+       $target/etc/blkid.tab
 
 # remove only "temporary" or saved files in the given directories
 nuke(){
@@ -88,18 +108,21 @@ nuke(){
 
 # set all files in the given directories to a length of zero
 zero(){
-  for i in $(find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null); do
+  for i in $(find "$@" -type f -size +0 -not -name \*.ini -not -path '*/fai/*' -not -name install_packages.list 2>/dev/null); do
     :> "$i"
   done
 }
 
 echo "Cleaning log and cache directories"
 nuke ${target}/var/log       ${target}/var/cache
-zero ${target}/var/local     ${target}/var/log \
-     ${target}/var/spool     ${target}/var/lib/games \
-     ${target}/var/cache/man ${target}/var/lib/nfs \
-     ${target}/var/lib/xkb   ${target}/var/mail/grml \
-     ${target}/var/account/pacct
+zero ${target}/var/account/pacct \
+     ${target}/var/cache/man \
+     ${target}/var/lib/games \
+     ${target}/var/lib/nfs   \
+     ${target}/var/lib/xkb   \
+     ${target}/var/local     \
+     ${target}/var/log       \
+     ${target}/var/mail/grml
 
 # on /run we don't have to create it
 if [ -d ${target}/var/run ] ; then
@@ -123,7 +146,7 @@ else
   $ROOTCMD ldconfig
 fi
 
-if [ -x $target/usr/bin/update-menus ] ; then
+if [ -x $target/usr/bin/update-menus ] ; then
   echo "Warning: update-menus not installed"
 else
   echo "Updating windowmanager menus"
@@ -142,7 +165,7 @@ if ! [ -d $target/var/lib/clamav/ ] ; then
   echo "Warning: clamav[-freshclam] not installed"
 else
   echo "Cleaning /var/lib/clamav/"
-  rm -f $target/var/lib/clamav/clamav-*
+  $ROOTCMD rm -rf /var/lib/clamav/clamav-*
 
   echo "Setting up daily.cvd and main.cvd symlinks"
   if [ -f $target/var/lib/clamav/daily.cvd ] ; then
@@ -164,31 +187,42 @@ if ! [ -d $target/etc/resolvconf ] ; then
   echo "Warning: resolvconf not installed"
 else
   echo "Setting up resolvconf"
-  if [ -L $target/etc/resolvconf/run ] ; then # resolvconf with /run
-    # /etc/resolvconf/run symlinks to /run/resolvconf
-    RESOLV_CONF=/run/resolvconf/
-  else # no /run present
-    RESOLV_CONF=/etc/resolvconf/run/
-  fi
-
-  rm -rf   ${target}/${RESOLV_CONF}
-  mkdir -p ${target}/${RESOLV_CONF}
+  if [ ! -L $target/etc/resolvconf/run ] ; then # resolvconf without symlink?!
+    RESOLV_CONF=/etc/resolvconf/run
+    rm -rf   ${target}/${RESOLV_CONF}
+    mkdir -p ${target}/${RESOLV_CONF}
 
-  touch ${target}/${RESOLV_CONF}/enable-updates
-  mkdir ${target}/${RESOLV_CONF}/interface
+    touch ${target}/${RESOLV_CONF}/enable-updates
+    mkdir ${target}/${RESOLV_CONF}/interface
 
-  cat > ${target}/${RESOLV_CONF}/resolv.conf << EOF
+    cat > ${target}/${RESOLV_CONF}/resolv.conf << EOF
 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
 #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
 EOF
+  fi
+  rm -f ${target}/etc/resolvconf/resolv.conf.d/original
+  rm -f ${target}/etc/resolv.conf
+  $ROOTCMD ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
 fi
 
-if ! [ -x $target/usr/bin/updatedb ] ; then
+# make sure we don't leak any mdadm configurations
+# that are present on the build system to the live system
+if [ -f "${target}/etc/mdadm/mdadm.conf" ] ; then
+  echo "Found /etc/mdadm/mdadm.conf, getting rid of any possible enabled ARRAY settings."
+  sed -i '/^ARRAY/d' "${target}/etc/mdadm/mdadm.conf"
+fi
+
+if ! $ROOTCMD test -x /usr/bin/updatedb ; then
   echo "Warning: updatedb not installed"
 else
   echo "Updating locate-database"
   $ROOTCMD updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
 fi
 
+if [ -r "${target}/etc/machine-id" ] ; then
+  echo "Removing /etc/machine-id generated by systemd"
+  rm -f "$target/etc/machine-id"
+fi
+
 ## END OF FILE #################################################################
 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2