+
+ 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 # CHROOT_VARIABLES == 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
+}
+# }}}
+
+# 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)"
+
+NUM_PARTITIONS=0
+for i in $(cat $TMPFILE) ; do
+ NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
+done
+
+ERRORFILE=$(mktemp)
+set +e
+# TODO: better error handling?
+yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
+ --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
+RC=$?
+set -e
+
+if [ "$RC" = 0 ] ; then
+ dialog --title "$PN" --msgbox \
+ "Creating $TARGET was successful." 0 0
+ rm -f "$TMPFILE" "$ERRORFILE"
+else
+ dialog --title "$PN" --msgbox \
+ "There was an error setting up $TARGET:
+
+$(cat $ERRORFILE)
+
+Exiting." 0 0
+ rm -f "$TMPFILE" "$ERRORFILE"
+ exit 1
+fi
+
+}
+
+prompt_for_swraid()
+{
+if dialog --stdout --title "$PN" \
+ --defaultno --yesno "Do you want to configure Software RAID?
+
+Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
+ config_swraid_setup
+fi
+}
+# }}}
+
+# user should recheck his configuration {{{
+# support full automatic installation:
+checkforrun() {
+ dialog --timeout 10 --title "$PN" \
+ --yesno "Do you want to stop at this stage?
+
+Notice: you are running ${PN} in non-interactive mode.
+${PN} will install Debian ${RELEASE} on ${TARGET}.
+Last chance to quit. Timeout of 10 seconds running....
+
+Do you want to stop now?" 0 0 2>/dev/null