+[ "$_opt_help" ] && {
+ usage ; eend 0
+ eend 0
+ exit 0
+}
+
+[ "$_opt_version" ] && {
+ einfo "$PN - version $VERSION"
+ einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
+ eend 0
+ exit 0
+}
+# }}}
+
+# source specified configuration file {{{
+if [ -n "$CONFIGFILE" ] ; then
+ einfo "Reading specified config file $CONFIGFILE."
+ if ! . "$CONFIGFILE" ; then
+ eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
+ fi
+fi
+# }}}
+
+# backwards compability checks {{{
+if [ -n "$GROOT" ] ; then
+ echo "Error: you seem to have \$GROOT configured." >&2
+ echo "This variable is no longer supported, please visit the" >&2
+ echo "grml-debootstrap documentation for details." >&2
+ exit 1
+fi
+
+if echo "$GRUB" | grep -q '^hd' ; then
+ echo "Error: this syntax for the grub configuration variable is no longer supported." >&2
+ echo "Please do not use hd... any longer but /dev/sdX instead." >&2
+ exit 1
+fi
+# }}}
+
+# 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* 2>/dev/null || true);
+
+ 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 $(blkid -s TYPE -o value $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=""
+
+ if echo "$TARGET" | grep -q "/dev/md" ; then
+ MBRPART="all disks of Software RAID $TARGET"
+ else
+ # figure out whole disk device
+ found=
+ for device in /dev/disk/by-id/*
+ do
+ [ $(readlink -f $device) = ${TARGET} ] || continue
+ found=1
+ break
+ done
+ [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
+ if [ -e "$MBRDISK" ]; then
+ MBRDISK=$(readlink -f $MBRDISK)
+ else
+ # fall back to old behaviour
+ MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$//')
+ fi
+
+ MBRPART="MBR of $MBRDISK"
+ fi
+
+ for device in cciss/c0d0 sda hda; do
+ if [ /dev/$device != ${MBRDISK} ]; then
+ grep -q $device /proc/partitions && \
+ ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
+ fi
+ done
+ ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
+
+ OIFS="$IFS"; IFS=:
+
+ 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" \
+ 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 "/dev/md" ; then
+ # using sw-raid:
+ if [ -n "$SELECTED_PARTITIONS" ] ; then
+ GRUB=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
+ else
+ GRUB="$TARGET"
+ fi
+ else
+ GRUB="$MBRDISK"
+ fi
+ ;;
+ hda)
+ GRUB="/dev/hda"
+ ;;
+ sda)
+ GRUB="/dev/sda"
+ ;;
+ nowhere)
+ GRUB=''
+ ;;
+ 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 3 \
+ 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()
+{
+ [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
+
+ CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
+ --menu "Where do you want to install from?" 0 0 0 \
+ net "install via network (downloading from mirror)" \
+ local "install from local directory/mirror"
+ )
+
+ if [ "$CHOOSE_MIRROR" = 'net' ] ; then
+ [ -n "$MIRROR" ] || MIRROR='http://cdn.debian.net/debian'
+ MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
+ "Please enter Debian mirror you would like to use for installing packages." \
+ 0 0 $MIRROR)"
+ else # CHOOSE_MIRROR == local
+ [ -n "$ISO" ] || ISO='/mnt/mirror'
+ ISO="$(dialog --stdout --title "${PN}" --inputbox \
+ "Please enter directory name you would like to use for installing packages." \
+ 0 0 $ISO)"
+ fi