Drop Latest change lines, add initial support for Debian/squeeze
[grml-live.git] / etc / grml / fai / grml / grml_cleanup_chroot
index e93f175..6b21674 100755 (executable)
@@ -4,7 +4,6 @@
 # Authors:       (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Wed Sep 19 13:38:45 CEST 2007 [mika]
 ################################################################################
 
 # misc stuff
@@ -52,9 +51,27 @@ einfo "Setting up /etc/inittab"
 cp /etc/inittab.grml  /etc/inittab
 eend $?
 
-einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
-( cd /usr/src && make clean && make symlinks )
-eend $?
+if [ "$(dpkg --list | awk '/^rc/ { print $2}')" != '' ] ; then
+   einfo "Purging removed packages"
+   dpkg --purge $(dpkg --list | awk '/^rc/ { print $2}')
+   eend $?
+fi
+
+if [ -x /usr/bin/make -a -r /usr/src/Makefile ] ; then
+   einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
+   ( cd /usr/src
+   VER=$(/bin/ls -d /usr/src/linux-headers-* | head -1)
+   VER=${VER##/usr/src/linux-headers-}
+   if [ -n "$VER" ] ; then
+      VER=$VER make clean && \
+      VER=$VER make symlinks
+   else
+      make clean && \
+      make symlinks
+   fi
+   )
+   eend $?
+fi
 
 if [ -L /usr/include/linux ] ; then
   einfo "/usr/include/linux is ok" ; eend 0
@@ -62,15 +79,14 @@ elif [ -n "$GRML64" ] ; then
     if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
        einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
     else
-       eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
-       exit 10
+       ewarn "Warning: /usr/src/linux-headers-$KERNEL not found, exiting." ; eend 0
     fi
 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
-     eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
-     eend 1
-     exit 10
+     ewarn "Warning: /usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ (possible an error)"
+     ewarn "Common reason: you forgot to install linux-kernel-headers-grml and use linux-libc-dev instead"
+     eend 0
 else
-     ewarn "linux-headers-$KERNEL not installed." ; eend 0
+     ewarn "Warning: linux-headers-$KERNEL not installed." ; eend 0
 fi
 
 einfo "Creating ~/.zshrc"
@@ -123,6 +139,7 @@ einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
   rm -f /var/lib/apt/lists/*Packages
   rm -f /var/lib/apt/lists/*Release
   rm -f /var/lib/apt/lists/*Sources
+  rm -f /var/lib/apt/lists/*IndexDiff
   rm -f /var/lib/apt/lists/*.gpg
   rm -f /var/cache/apt-show-versions/*
   rm -f /var/cache/debconf/templates.dat-old
@@ -134,6 +151,30 @@ einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
   rm -f /var/lib/dpkg/available-old
 eend $?
 
+if ifclass GRML_SMALL ; then
+   einfo "Removing /var/cache/debconf/templates.dat"
+   rm -f /var/cache/debconf/templates.dat
+   eend $?
+
+   einfo "Removing /usr/share/ssh/blacklist.*"
+   rm -f /usr/share/ssh/blacklist.DSA-1024 /usr/share/ssh/blacklist.RSA-2048
+   eend $?
+fi
+
+# get rid of large kernel modules:
+if ifclass GRML_SMALL ; then
+  if [ -r "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko" ] ; then
+    einfo "Removing /lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
+    rm -f "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
+    eend $?
+  fi
+  if [ -r "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko" ] ; then
+    einfo "Removing /lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko"
+    rm -f "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko"
+    eend $?
+  fi
+fi
+
 if [ -x /usr/bin/grep-dctrl ] ; then
    einfo "Cleaning up /var/lib/dpkg/status"
    grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
@@ -156,6 +197,10 @@ einfo "Removing ssh-keys"
   rm -f /etc/ssh/*key*
 eend $?
 
+einfo "Removing unused/backup files"
+  find / -name *~ -print0 | xargs -0 rm -f
+eend $?
+
 # 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
@@ -225,7 +270,6 @@ einfo "Cleaning and removing some misc files and directories"
          /var/lib/games /var/cache/man      \
          /var/lib/nfs   /var/lib/xkb        \
          /var/mail/grml /var/account/pacct
-  mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
   # Recreate empty utmp and wtmp
   :>/var/run/utmp
   :>/var/run/wtmp
@@ -286,6 +330,12 @@ else
   ewarn "clamav[-freshclam] not installed" ; eend 0
 fi
 
+if [ -f /etc/default/snort.dpkg-dist -a -f /etc/default/snort ] ; then
+   einfo "Fixxing /etc/default/snort"
+   mv /etc/default/snort.dpkg-dist /etc/default/snort
+   eend $?
+fi
+
 if ! [ -r /etc/ld.so.nohwcap ] ; then
    einfo "Creating /etc/ld.so.nohwcap"
    touch /etc/ld.so.nohwcap