-# provide variables to chroot system {{{
-CHROOT_VARIABLES="/etc/debootstrap/variables_${SHORT_TARGET}"
-touch $CHROOT_VARIABLES
-chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
-[ -n "$ARCH" ] && echo "ARCH=$ARCH" > $CHROOT_VARIABLES
-[ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
-[ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
-[ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
-[ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
-[ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
-[ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
-[ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> $CHROOT_VARIABLES
-[ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
-# }}}
-
-# helper functions {{{
-# we want to exit smoothly and clean:
-bailout(){
- # make sure $TARGET is not mounted when exiting grml-debootstrap
- if [ -n "$MNTPOINT" ] ; then
- if grep -q $MNTPOINT /proc/mounts ; then
- # make sure nothing is left inside chroot so we can unmount it
- [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
- [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
- # ugly, but make sure we really don't leav anything
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
- [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
- [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
- einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
-
- # remove directory only if we used the default with process id inside the name
- if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
- einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
- fi
- fi
- fi
-
- [ -n "$1" ] && EXIT="$1" || EXIT="1"
- [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
-
- exit "$EXIT"
-}
-trap bailout HUP INT QUIT TERM
-
-# we want to execute all the functions only once, simple check for it:
-stage() {
- if [ -n "$2" ] ; then
- echo "$2" > "${STAGES}/${1}"
- return 0
- elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
- ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
- eindent
- ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
- eoutdent
- return 1
- fi
-}
-# }}}
-
-# user should recheck his configuration {{{
-# support full automatic installation:
-checkforrun() {
- dialog --timeout 10 --title "$PN" \
- --yesno "Do you want to stop at this stage?
-
-Notice: you are running grml-debootstrap in non-interactive mode.
-grml-debootstrap will install Debian ${RELEASE} on ${TARGET}.
-Last chance to quit. Timeout of 10 seconds running....
-
-Do you want to stop now?" 0 0 2>/dev/null
-}
-
-if [ -n "$AUTOINSTALL" ] ; then
- if checkforrun ; then
- eerror "Exiting as requested" ; eend 0
- exit 1
- fi
-else # if not running automatic installation display configuration and prompt for execution:
- einfo "$PN - Please recheck configuration before execution:"
- echo
- echo " Target: $TARGET"
- case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
- [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
- [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
- [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
- [ -n "$ISO" ] && echo " Using iso: $ISO"
- case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
- echo
- einfon "Is this ok for you? [y/N] "
- read a
- if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
- eerror "Exiting as requested." ; eend 1
- exit 1
- fi
-fi
-# }}}
-