From ab9101c1aa74672b653af1f483552c832a6fa780 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 24 Apr 2012 22:07:24 +0200 Subject: [PATCH] Remove chroot-script after execution Restumbled upon it again during a discussion with Carsten Hey regarding #670106 --- chroot-script | 3 +++ grml-debootstrap | 29 ++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/chroot-script b/chroot-script index 2512b95..7caf4dd 100755 --- a/chroot-script +++ b/chroot-script @@ -5,6 +5,9 @@ # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. ################################################################################ +# GRML_CHROOT_SCRIPT_MARKER - do not remove this line unless you want to keep +# this script as /bin/chroot-script on your new installed system +################################################################################ . /etc/debootstrap/config || exit 1 . /etc/debootstrap/variables || exit 1 diff --git a/grml-debootstrap b/grml-debootstrap index a82aaaf..a9d5f99 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -1203,18 +1203,29 @@ execute_scripts() { # execute chroot-script {{{ chrootscript() { if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then - mount_target + mount_target fi - if [ -x "$MNTPOINT/bin/chroot-script" ] ; then - einfo "Executing chroot-script now" - mount --bind /dev "$MNTPOINT"/dev - chroot "$MNTPOINT" /bin/chroot-script ; RC=$? - umount "$MNTPOINT"/dev - eend $RC + if ! [ -x "$MNTPOINT/bin/chroot-script" ] ; then + eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found." + eend 1 else - eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found." - eend 1 + einfo "Executing chroot-script now" + mount --bind /dev "$MNTPOINT"/dev + chroot "$MNTPOINT" /bin/chroot-script ; RC=$? + umount "$MNTPOINT"/dev + eend $RC + fi + + # finally get rid of chroot-script again, there's no good reason to + # keep it on the installed system + if grep -q GRML_CHROOT_SCRIPT_MARKER "${MNTPOINT}/bin/chroot-script" ; then + einfo "Removing chroot-script again" + rm -f "${MNTPOINT}/bin/chroot-script" + eend $? + else + einfo "Keeping chroot-script as string GRML_CHROOT_SCRIPT_MARKER could not be found" + eend 0 fi } # }}} -- 2.1.4