+[ "$_opt_version" ] && {
+ einfo "$PN - version $VERSION"
+ einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
+ eend 0
+ exit 0
+}
+# }}}
+
+# welcome screen {{{
+welcome_dialog()
+{
+ dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
+Do you want to continue installing Debian using this frontend?" 0 0
+}
+# }}}
+
+# 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}'; ls /dev/md*);
+
+ if [ -z "$AVAILABLE_PARTITIONS" ] ; then
+ dialog --title "$PN" --trim \
+ --msgbox "Sorry, no partitions found. Please configure your
+ harddisks (see /proc/partitions) using a tool like fdisk,
+ cfdisk, gpart, gparted,..." 0 0
+ exit 0
+ fi
+
+ 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=:
+
+ if echo $TARGET | grep -q "/dev/md" ; then
+ MBRPART="all disks of Software RAID $TARGET"
+ else
+ MBRPART="MBR of ${TARGET%[0-9]}"
+ fi
+
+ 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 $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)
+ # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
+ if echo $TARGET | grep -q "*md*" ; then
+ BOOT_PARTITION="${TARGET}"
+ else
+ BOOT_PARTITION="${TARGET%[0-9]}"
+ fi
+ ;;
+ partition)
+ BOOT_PARTITION="$TARGET"
+ ;;
+ hda)
+ BOOT_PARTITION="/dev/hda"
+ ;;
+ sda)
+ BOOT_PARTITION="/dev/sda"
+ ;;
+ nowhere)
+ BOOT_PARTITION=''
+ ;;
+ esac
+}
+# }}}
+
+# ask for Debian release {{{
+prompt_for_release()
+{
+ [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
+ RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
+ "Please enter the Debian release you would like to use for installation:" \
+ 0 50 4 \
+ etch Debian/old-stable \
+ lenny Debian/stable \
+ squeeze Debian/testing \
+ sid Debian/unstable)"
+}
+# }}}
+
+# ask for hostname {{{
+prompt_for_hostname()
+{
+ HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
+ "Please enter the hostname you would like to use for installation:" \
+ 0 0 $HOSTNAME)"
+}
+# }}}
+
+# ask for password {{{
+prompt_for_password()
+{
+ ROOTPW1='PW1'
+ ROOTPW2='PW2'
+ while [ "$ROOTPW1" != "$ROOTPW2" ]; do
+ ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
+ "Please enter the password for the root account:" 10 60)
+ ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
+ "Please enter the password for the root account again for \
+ confirmation:" 10 60)
+
+ if [ "$ROOTPW1" != "$ROOTPW2" ]; then
+ $(dialog --stdout --title "${PN}" --ok-label \
+ "Retry" --msgbox "Passwords do not match!" 10 60)
+ fi
+ done
+ ROOTPASSWORD="$ROOTPW1"
+}
+# }}}
+
+# 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 $MIRROR)"
+}
+# }}}
+
+# get grub's syntax for /dev/ice {{{
+# usage example: 'grubdevice /dev/sda2' 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
+
+ # based on code 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%')
+
+ case $1 in
+ /dev/[sh]d[a-z]) # we expect something like 'hd0'
+ echo "$tmp_drive"
+ ;;
+ *) # we expect something like 'hd0,0'
+ echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
+ ;;
+ esac
+}
+# }}}
+
+# software raid setup {{{
+config_swraid_setup()
+{
+TMPFILE=$(mktemp)
+
+# Currently we support only raid1:
+RAIDLEVEL='raid1'
+
+#RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
+# --menu "Which RAID level do you want to use?" 0 0 0 \
+# raid1 "Software RAID level 1" \
+# raid5 "Software RAID level 5")
+#[ $? -eq 0 ] || bailout 20
+
+MD_LIST=$(for i in $(seq 0 9) ; do
+ awk '{print $4}' /proc/partitions | grep -q md$i || \
+ echo "/dev/md$i /dev/md$i"
+ done)
+
+TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
+--menu "Which device do you want to use for ${RAIDLEVEL}?
+
+Notice: activated devices will not be listed for security reasons. Anyway, please make sure the selected device is not in use already!" 0 0 0 \
+$MD_LIST)
+[ $? -eq 0 ] || bailout 20
+
+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]) off"
+ done)
+
+dialog --title "$PN" --separate-output \
+ --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
+ $PARTITION_LIST 2>$TMPFILE
+RETVAL=$?
+SELECTED_PARTITIONS="$(cat $TMPFILE)"