+echo "Cleaning and removing some misc files and directories"
+find $target/etc -type f -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/log/ksymoops/* \
+ $target/var/state/* $target/var/log/nessus/* \
+ $target/halt $target/reboot $target/ash.static \
+ $target/etc/dhcpc/*.info $target/etc/dhcpc/resolv* \
+ $target/etc/*passwd- $target/etc/*shadow- \
+ $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/var/tmp/* $target/var/backups/* \
+ $target/var/lib/mysql $target/var/log/lilo_log.* $target/core*
+
+# remove only "temporary" or saved files in the given directories
+nuke(){
+ for i in $(find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null); do
+ rm -f --one-file-system "$i"
+ done
+}
+
+# set all files in the given directories to a length of zero
+zero(){
+ 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/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
+ echo "Recreate empty utmp and wtmp"
+ :>${target}/var/run/utmp
+ :>${target}/var/run/wtmp
+fi
+
+if ! [ -x $target/usr/sbin/update-ca-certificates ] ; then
+ echo "Warning: update-ca-certificates not installed"
+else
+ echo "Updating ca-certificates"
+ $ROOTCMD update-ca-certificates
+fi
+
+# regenerate ls.so.cache
+if ! [ -x $target/sbin/ldconfig ] ; then
+ echo "Warning: ldconfig not installed"
+else
+ echo "Updating ld.so.cache"
+ $ROOTCMD ldconfig
+fi
+
+if ! [ -x $target/usr/bin/update-menus ] ; then
+ echo "Warning: update-menus not installed"
+else
+ echo "Updating windowmanager menus"
+ $ROOTCMD update-menus -v
+fi
+
+if ! [ -x $target/usr/bin/mandb ] ; then
+ echo "Warning: mandb not installed"
+else
+ echo "Updating mandb"
+ $ROOTCMD mandb -c
+ $ROOTCMD man doesnotexist >/dev/null 2>&1 || true
+fi
+
+if ! [ -d $target/var/lib/clamav/ ] ; then
+ echo "Warning: clamav[-freshclam] not installed"
+else
+ echo "Cleaning /var/lib/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
+ mkdir -p $target/usr/share/doc/clamav-freshclam/examples/
+ ln -sf /var/lib/clamav/daily.cvd $target/usr/share/doc/clamav-freshclam/examples/
+ ln -sf /var/lib/clamav/main.cvd $target/usr/share/doc/clamav-freshclam/examples/
+ fi
+fi
+
+if ! [ -r $target/etc/ld.so.nohwcap ] ; then
+ echo "Creating /etc/ld.so.nohwcap"
+ touch $target/etc/ld.so.nohwcap
+fi
+
+# installation of resolvconf in chroot *with* /proc
+# is different from an installation without /proc,
+# so make sure it is OK in any case
+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}
+
+ touch ${target}/${RESOLV_CONF}/enable-updates
+ mkdir ${target}/${RESOLV_CONF}/interface
+
+ 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