+ if [ -n "$CONFIGFILE" ] ; then
+ if ! . "$CONFIGFILE" ; then
+ eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
+ fi
+ else
+ . /etc/debootstrap/config
+ fi
+fi
+# }}}
+
+# cmdline handling {{{
+
+while [ "$#" -gt "0" ] ; do
+ case $1 in
+ -c|--config)
+ shift
+ CONFIGFILE=$1
+ ;;
+ --grub)
+ shift
+ GRUB=$1
+ ;;
+ --groot)
+ shift
+ GROOT=$1
+ ;;
+ -h|--help)
+ usage ; eend 0
+ eend 0
+ exit 0
+ ;;
+ --interactive)
+ INTERACTIVE=1
+ ;;
+ -i|--iso)
+ shift
+ [ -n "$MIRROR" ] && unset MIRROR
+ ISO=$1
+ ;;
+ -m|--mirror)
+ shift
+ MIRROR=$1
+ CHROOTMIRROR=$1
+ ;;
+ -p|--mntpoint)
+ shift
+ MNTPOINT=$1
+ ;;
+ --password)
+ shift
+ ROOTPASSWORD=$1
+ ;;
+ -r|--release)
+ shift
+ RELEASE=$1
+ ;;
+ -t|--target)
+ shift
+ TARGET=$1
+ ;;
+ -v|--version)
+ einfo "$PN - version $VERSION"
+ einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
+ eend 0
+ exit 0
+ ;;
+ *)
+ eerror "Syntax error."
+ usage ; eend 1
+ exit 1
+ ;;
+ esac
+ shift
+done
+# }}}
+
+# ask for target {{{
+prompt_for_target()
+{
+ AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
+ sed 's/*//' | \
+ grep -v 'Extended$' | \
+ gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
+
+ [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
+ PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
+ echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
+ done)
+
+ TARGET=$(dialog --title "$PN" --single-quoted --stdout \
+ --menu "Please select the target partition:" 0 0 0 \
+ $PARTITION_LIST)
+}
+# }}}
+
+# ask for bootmanager {{{
+prompt_for_bootmanager()
+{
+ ADDITIONAL_PARAMS=""
+ for device in sda hda; do
+ if [ /dev/$device != ${TARGET%[0-9]} ]; then
+ grep -q $device /proc/partitions && \
+ ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
+ fi
+ done
+ ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
+
+ OIFS="$IFS"; IFS=:
+
+ [[ $TARGET == *md* ]] && MBRPART=$TARGET || MBRPART="${TARGET%[0-9]}"
+
+ GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
+ --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
+ mbr "install bootmanager into MBR of $MBRPART" \
+ partition "install bootmanager into partition $TARGET" \
+ nowhere "do NOT install bootmanager at all" \
+ ${ADDITIONAL_PARAMS})
+ [ $? -eq 0 ] || bailout 3
+ IFS="$OIFS"
+
+ case "$GETMBR" in
+ mbr)
+ USE_MBR=1
+ # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
+ if [[ $TARGET == *md* ]] ; then
+ BOOT_PARTITION=${TARGET}
+ else
+ BOOT_PARTITION=${TARGET%[0-9]}
+ fi
+ ;;
+ partition)
+ BOOT_PARTITION="$TARGET"
+ ;;
+ hda)
+ USE_MBR=1
+ BOOT_PARTITION="/dev/hda"
+ ;;
+ sda)
+ USE_MBR=1
+ BOOT_PARTITION="/dev/sda"
+ ;;
+ none)
+ BOOT_PARTITION=''
+ ;;
+ *)
+ BOOT_PARTITION="$GETMBR"
+ ;;
+ esac
+}
+# }}}
+
+# ask for Debian mirror {{{
+prompt_for_mirror()
+{
+ MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
+ "Please enter Debian mirror you would like to use for installing packages." \
+ 0 0 http://ftp.de.debian.org/debian)"
+}
+# }}}
+
+# get grub's syntax for /dev/ice
+# usage example: 'grubdevice /dev/hda2' returns '(hd0,1)'
+grubdevice() {
+ if [ -z "$1" ] ; then
+ echo "Usage: grubdevice <device>">&2
+ return 1
+ fi
+
+ device="$1"
+ device_map=/boot/grub/device.map
+
+ # create device.map
+ if ! [ -f "$device_map" ] ; then
+ echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
+ fi
+
+ # taken from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
+ tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
+ -e 's%\(fd[0-9]*\)$%\1%' \
+ -e 's%/part[0-9]*$%/disc%' \
+ -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
+ tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
+ -e 's%.*/fd[0-9]*$%%' \
+ -e 's%.*/floppy/[0-9]*$%%' \
+ -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
+ -e 's%.*c[0-7]d[0-9]*p*%%'`
+ tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
+ GRUB="$(echo "$tmp_drive")"
+
+ case $1 in
+ /dev/[sh]d[a-z]) # we expect something like 'hd0'
+ GROOT="$(echo "$tmp_drive")"
+ ;;
+ *) # we expect something like 'hd0,0'
+ # make sure we don't install into MBR if $USE_MBR is not set
+ if [ -z "$USE_MBR" ] ; then
+ GROOT="$(echo "$tmp_drive" | sed "s%)$%,`expr $tmp_part - 1`)%")"
+ else
+ GROOT="$(echo "$tmp_drive" | sed "s%,[0-9]%%")"
+ fi
+ ;;
+ esac
+}
+
+# interactive mode {{{
+interactive_mode()
+{
+ prompt_for_target
+ prompt_for_bootmanager
+ prompt_for_mirror
+ grubdevice $TARGET
+
+ # FIXME
+ echo "debug: BOOT_PARTITION=$BOOT_PARTITION"
+ echo "debug: TARGET=$TARGET"
+ echo "debug: MIRROR=$MIRROR"
+ echo "debug: GROOT=$GROOT"
+ # ask for raid
+ # ask for lvm
+}
+
+# run interactive mode if we didn't get the according configuration yet
+if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
+ interactive_mode