+# 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
+fi
+# }}}
+
+# finally make sure at least $TARGET is set [the partition for the new system] {{{
+if [ -n "$TARGET" ] ; then
+ SHORT_TARGET="${TARGET##*/}"
+else
+ eerror "Please adjust /etc/debootstrap/config or..."
+ eerror "... use the interactive version for configuration before running ${0}" ; eend 1
+ exit 1
+fi
+# }}}
+
+# stages setup {{{