Closes #issue209, check for ntfs.ko before loading it
[grml-live.git] / rewrite / grml.prepare
index b2d5000..62e5be1 100644 (file)
@@ -1,10 +1,10 @@
-#!/bin/sh
+#!/bin/bash
 # Filename:      grml.clean
 # Purpose:       clean up grml chroot
 # Authors:       (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is copyright by Michael Prokop
-# Latest change: Sun Apr 15 17:31:51 CEST 2007
+# Latest change: Sun Apr 22 14:15:03 CEST 2007 [mika]
 ################################################################################
 
 # misc stuff
 
 # variables
   grep -q small /etc/grml_version && GRML_SMALL=yes  || GRML_SMALL=''
-  [ -n "$GRML_SMALL" ] && KERNEL='2.6.20-grml-small' || KERNEL='2.6.20-grml'
-  [ -r /lib64 ] && KERNEL='2.6.20-grml64' && GRML_SMALL=''
+  if [ -n "$GRML_SMALL" ] ; then
+     echo -n 'Are you sure you want to run GRML_SMALL stuff? [y|N] '
+     read a
+     if [ "$a" == 'y' ] ; then
+        echo 'Continuing as requested.'
+     else
+        echo 'Exiting as requested.'
+        unset GRML_SMALL
+        exit 1
+     fi
+  fi
+
+# detect kernel version, assume newest kernel version
+  KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
 
 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
   if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
@@ -68,9 +80,13 @@ if [ -z "$GRML_SMALL" ] ; then
   if [ -L /usr/include/linux ] ; then
     einfo "/usr/include/linux is ok" ; eend 0
   else
-    eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
-    eend 1
-    exit 10
+    if [ -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
+    else
+       ewarn "linux-headers-$KERNEL not installed." ; eend 0
+    fi
   fi
 fi
 
@@ -122,7 +138,6 @@ fi
 
 # find /var -name \*.pid
 einfo "Removing pid-files"
-# find /var/run -name \*.pid | xargs rm ; echo "done"
   find /var/run -name \*.pid -exec rm {} \;
 eend $?
 
@@ -138,25 +153,34 @@ einfo "Removing initrd-images"
 eend $?
 
 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
+  # for i in $(find /var/lib/apt/lists -type f \( -name \*Packages -o -name \*Sources \) 2>/dev/null); do  :>"$i"; done
+  # for i in /var/lib/apt/lists/*_{Release,Packages,Sources}; do :>$i; touch -t 198103190000.00 $i; done
+  # sync-available 2>/dev/null
+  # apt-get check
   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/*.gpg
   # :> /var/cache/apt/pkgcache.bin
   # :> /var/cache/apt/srcpkgcache.bin
-  rm -f /var/lib/dpkg/status-old
-  rm -f /var/lib/dpkg/available-old
   rm -f /var/cache/debconf/templates.dat-old
-  # for i in $(find /var/lib/apt/lists -type f \( -name \*Packages -o -name \*Sources \) 2>/dev/null); do  :>"$i"; done
-  # for i in /var/lib/apt/lists/*_{Release,Packages,Sources}; do :>$i; touch -t 198103190000.00 $i; done
-  apt-get check
-  dpkg --clear-avail
   rm -f /var/cache/apt/*.bin
-  apt-cache gencaches
-  sync-available
-  # apt-get check
+  apt-get check 2>/dev/null
+  dpkg --clear-avail
+  apt-cache gencaches 2>/dev/null
+  rm -f /var/lib/dpkg/status-old
+  rm -f /var/lib/dpkg/available-old
 eend $?
 
+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 && \
+   cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status  && \
+   chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
+else
+   ewarn "Warning: /usr/bin/grep-dctrl not available."
+fi
+
 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
   if ! [ -z $GRML_SMALL ] ; then
     cp /etc/runlevel.conf.livecd.small /etc/runlevel.conf
@@ -289,18 +313,27 @@ eend $?
 
 einfo "Setting up /etc/resolv.conf"
   if [ -d /etc/dhcpc ] ; then
-  cat >/etc/dhcpc/resolv.conf <<EOT
+    cat >/etc/dhcpc/resolv.conf <<EOT
 # insert nameservers here
 # nameserver 127.0.0.1
 EOT
-  chmod 644 /etc/dhcpc/resolv.conf
-  fi
-  # is resolvconf available?
-  if [ -r /etc/resolvconf/run/resolv.conf ] ; then
-     ln -sf /etc/resolvconf/run/resolv.conf /etc/
+    chmod 644 /etc/dhcpc/resolv.conf
   else
-     ln -s /etc/dhcpc/resolv.conf /etc/
+    cat >/etc/resolv.conf <<EOT
+# insert nameservers here
+# nameserver 127.0.0.1
+EOT
+    chmod 644 /etc/resolv.conf
   fi
+
+   # is resolvconf available?
+   if ! [ -r /etc/resolv.conf ] ; then
+      if [ -r /etc/resolvconf/run/resolv.conf ] ; then
+         ln -sf /etc/resolvconf/run/resolv.conf /etc/
+      else
+         ln -s /etc/dhcpc/resolv.conf /etc/
+      fi
+   fi
 eend $?
 
 if [ -x /usr/sbin/update-ca-certificates ] ; then
@@ -325,13 +358,13 @@ else
   ewarn "ldconfig not installed" ; eend 0
 fi
 
-if [ -r /lib/modules/$KERNEL/ ] ; then
-  einfo "Searching for modules not compiled against $KERNEL"
-  ( cd /lib/modules/$KERNEL/ && modinfo **/*.ko | grep vermagic | grep -v $KERNEL )
-  eend 0
-else
-  eerror "/lib/modules/$KERNEL/ not found" ; eend 1
-fi
+#if [ -r /lib/modules/$KERNEL/ ] ; then
+#  einfo "Searching for modules not compiled against $KERNEL"
+#  ( cd /lib/modules/$KERNEL/ && modinfo **/*.ko | grep vermagic | grep -v $KERNEL )
+#  eend 0
+#else
+#  eerror "/lib/modules/$KERNEL/ not found" ; eend 1
+#fi
 
 if [ -x /usr/bin/update-menus ] ; then
   einfo "Updating windowmanager menus"