Write hostname to installed system (fix for bedb4090)
[grml-debootstrap.git] / grml-debootstrap
index 104f454..b013ec2 100755 (executable)
@@ -157,6 +157,7 @@ Configuration options:
       --chroot-scripts <d> Execute chroot scripts from specified directory.
       --pre-scripts <dir>  Execute scripts from specified directory (before chroot-scripts).
       --scripts <dir>      Execute scripts from specified directory (after chroot-scripts).
+      --remove-configs     Delete grml-debootstrap configuration files from installed system.
 
 Other options:
 
@@ -244,6 +245,12 @@ 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
@@ -405,6 +412,7 @@ fi
 [ "$_opt_force" ]               && FORCE=$_opt_force
 [ "$_opt_verbose" ]             && VERBOSE="-v"
 [ "$_opt_debug" ]               && DEBUG="true"
+[ "$_opt_remove_configs" ]      && REMOVE_CONFIGS="yes"
 
 # make sure main is always included
 [ -z "$COMPONENTS" ]            && COMPONENTS="main"
@@ -1158,6 +1166,12 @@ finalize_vm() {
 # chroot-script skips installation for unset ${GRUB}
 if [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | fgrep -q GRUB; then
   einfo "Installing Grub as bootloader."
+
+  if ! chroot "${MNTPOINT}" dpkg --list grub-pc 2>/dev/null | grep -q '^ii' ; then
+    echo "Notice: grub-pc package not present yet, installing it therefore."
+    DEBIAN_FRONTEND=$DEBIAN_FRONTEND chroot "$MNTPOINT" apt-get -y install $DPKG_OPTIONS grub-pc
+  fi
+
   mkdir -p "${MNTPOINT}/boot/grub"
   if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then
      eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." ; eend 1
@@ -1193,8 +1207,13 @@ fi
 
   case "$RELEASE" in
     lenny|squeeze|wheezy)
-      einfo "Adjusting grub.cfg for successful boot sequence."
-      sed -i "s;root=[^ ]\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg
+      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
+        einfo "Adjusting grub.cfg for successful boot sequence."
+        sed -i "s;root=[^ ]\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg
+      fi
       ;;
   esac
 
@@ -1408,7 +1427,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
@@ -1430,7 +1449,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."