+# }}}
+
+# cmdline handling {{{
+usage() {
+ einfo "$0 - version $VERSION"
+ echo " A wrapper around debootstrap for installing plain Debian via grml"
+ echo
+ einfo "Usage: $0 [options]"
+ echo " Adjust /etc/debootstrap/config and invoke $0 afterwards or use the cmdline option:"
+ echo
+ einfo "Valid options:"
+ echo "
+ -h|--help Print this usage information and exit.
+ -v|--version Show summary of options and exit.
+
+ -t|--target <target> Target partition (/dev/...) or directory.
+ -r|--release <release> Specify release of new Debian system. Supported relases: sarge, etch, lenny and sid.
+ -m|--mirror <URL> Specify mirror which should be used for apt-get/aptitude.
+ -i|--iso <mnt> Specify mountpoint where Debian ISO is mounted to (instead of using mirror)
+ -p|--mntpoint <mnt> Specify mountpoint that should be used for mounting the target system.
+ --groot <device> Specify root device for usage in grub (corresponds with \$TARGET).
+ --grub <device> Where do you want to install grub to? Use grub syntax for specifying.
+ --password <pwd> Use specified password as password for user root. Use with caution.
+ --boot_append <appendline> Add specified appendline to kernel whilst booting
+
+"
+}
+
+while [ "$#" -gt "0" ] ; do
+ case $1 in
+ -v|--version)
+ einfo "$0 - version $VERSION"
+ einfo "Send bug reports to Michael Prokop <mika@grml.org>."
+ eend 0
+ exit 0
+ ;;
+ -t|--target)
+ shift
+ TARGET=$1
+ ;;
+ --grub)
+ shift
+ GRUB=$1
+ ;;
+ --groot)
+ shift
+ GROOT=$1
+ ;;
+ --release)
+ shift
+ RELEASE=$1
+ ;;
+ -p|--mntpoint)
+ shift
+ MNTPOINT=$1
+ ;;
+ --password)
+ shift
+ ROOTPASSWORD=$1
+ ;;
+ -m|--mirror)
+ shift
+ MIRROR=$1
+ CHROOTMIRROR=$1
+ ;;
+ -i|--iso)
+ shift
+ [ -n "$MIRROR" ] && unset MIRROR
+ ISO=$1
+ ;;
+ -h|--help)
+ usage ; eend 0
+ eend 0
+ exit 0
+ ;;
+ *)
+ eerror "Syntax error."
+ usage ; eend 1
+ exit 1
+ ;;
+ esac
+ shift
+done
+# }}}
+
+# set/check variables {{{
+
+# inside the chroot system the locales might not be available, so use minimum:
+export LANG=C
+export LC_ALL=C
+
+if [ -z "$STAGES" ] ; then
+ STAGES='/etc/debootstrap/stages'
+ [ -d "$STAGES" ] || mkdir -p "$STAGES"
+fi
+
+if [ -r $STAGES/grml-debootstrap ] ; then
+ if grep -q done $STAGES/grml-debootstrap ; then
+ eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
+ eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
+ fi
+fi
+
+PARTITION=''
+DIRECTORY=''
+
+case $TARGET in
+ /dev/*)
+ PARTITION=1
+ ;;
+ *)
+ # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
+ DIRECTORY=1
+ MNTPOINT="$TARGET"
+ MKFS=''
+ TUNE2FS=''
+ FSCK=''
+ GRUB=''
+ GROOT=''
+ ;;
+esac
+
+if [ -n "$ARCH" ] ; then
+ ARCHCMD="--arch $ARCH"
+ ARCHINFO=" (${ARCH})"
+else
+ ARCH="$(dpkg --print-architecture)"
+ ARCHCMD="--arch $ARCH"
+ ARCHINFO=" (${ARCH})"
+fi
+
+# make sure we have the right syntax when using an iso image
+case $ISO in
+ file*) # do nothing
+ ;;
+ *)
+ ISO=file:$1
+ ;;
+esac
+ISODIR=${ISO##file:}
+ISODIR=${ISODIR%%/}
+
+# provide variables to chroot system
+touch /etc/debootstrap/variables
+chmod 600 /etc/debootstrap/variables # make sure nobody except root can read it
+[ -n "$ARCH" ] && echo "ARCH=$ARCH" > /etc/debootstrap/variables
+[ -n "$GRUB" ] && echo "GRUB=$GRUB" >> /etc/debootstrap/variables
+[ -n "$GROOT" ] && echo "GROOT=$GROOT" >> /etc/debootstrap/variables
+[ -n "$TARGET" ] && echo "TARGET=$TARGET" >> /etc/debootstrap/variables
+[ -n "$ISO" ] && echo "ISO=$ISO" >> /etc/debootstrap/variables
+[ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> /etc/debootstrap/variables
+[ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> /etc/debootstrap/variables
+[ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> /etc/debootstrap/variables
+[ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> /etc/debootstrap/variables