Make check for GRUB_DISABLE_LINUX_UUID more stable
[grml-debootstrap.git] / grml-debootstrap
index d783f26..035901c 100755 (executable)
@@ -245,12 +245,6 @@ cleanup() {
     einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
   fi
 
-  if [ "$REMOVE_CONFIGS" = "yes" ] ; then
-    einfo "Removing configuration files from installed system as requested via --remove-configs / REMOVE_CONFIGS."
-    rm -rf "${MNTPOINT}"/etc/debootstrap/
-    eend $?
-  fi
-
   # Remove temporary mountpoint again
   if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
     rmdir "$MNTPOINT" 2>/dev/null
@@ -1207,7 +1201,7 @@ fi
 
   case "$RELEASE" in
     lenny|squeeze|wheezy)
-      if grep -q '^GRUB_DISABLE_LINUX_UUID=true' "${MNTPOINT}"/etc/default/grub 2>/dev/null ; then
+      if grep -q '^GRUB_DISABLE_LINUX_UUID=.*true' "${MNTPOINT}"/etc/default/grub 2>/dev/null ; then
         ewarn "GRUB_DISABLE_LINUX_UUID is set to true in /etc/default/grub, not adjusting root= in grub.cfg."
         ewarn "Please note that your system might NOT be able to properly boot."
       else
@@ -1427,7 +1421,7 @@ iface eth0 inet dhcp
 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
 execute_pre_scripts() {
   # make sure hostname is set even before chroot-script get executed
-  echo "$HOSTNAME" > /etc/hostname
+  echo "$HOSTNAME" > "$MNTPOINT"/etc/hostname
 
   # make sure we have $MNTPOINT available for our scripts
   export MNTPOINT
@@ -1449,7 +1443,7 @@ execute_post_scripts() {
   # make sure we have $MNTPOINT available for our scripts
   export MNTPOINT
 
-  if [ -d "$_opt_scripts" ] || [ "$SCRIPTS"  = 'yes'] ; then
+  if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
     # legacy support for /etc/debootstrap/scripts/
     [ -d "$_opt_scripts" ] && post_scripts="$_opt_scripts" || post_scripts="${CONFFILES}/scripts/"
     ewarn "Deprecation NOTE: --scripts/SCRIPTS are deprecated, please switch to --post-scripts/POST_SCRIPTS instead."
@@ -1566,10 +1560,27 @@ fscktool() {
 }
 # }}}
 
+# get rid of grml-debootstrap config files {{{
+remove_configs() {
+  if [ "$REMOVE_CONFIGS" != "yes" ] ; then
+    return 0
+  fi
+
+  if ! mountpoint "${MNTPOINT}" ; then
+    ewarn "Target ${MNTPOINT} doesn't seem to be mounted, can't remove configuration files." ; eend 0
+    return 0
+  fi
+
+  einfo "Removing configuration files from installed system as requested via --remove-configs / REMOVE_CONFIGS."
+  rm -rf "${MNTPOINT}"/etc/debootstrap/
+  eend $?
+}
+# }}}
+
 # now execute all the functions {{{
 for i in prepare_vm mkfs tunefs mount_target debootstrap_system \
          preparechroot execute_pre_scripts chrootscript execute_post_scripts \
-         umount_chroot finalize_vm fscktool ; do
+         remove_configs umount_chroot finalize_vm fscktool ; do
     if stage "${i}" ; then
       if "$i" ; then
         stage "${i}" 'done' && rm -f "${STAGES}/${i}"