#!/bin/ash
#
# $Id: ui-main,v 1.84 2002/10/30 17:54:30 ankry Exp $
#
# This file is part of PLD batch-installer
# Copyright (C) 2001 CYBER Service
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# Author: Rafał Kleger-Rudomin
# Contributors: Michał Moskal


# this is main UI for creating installer.conf

#set -x

# temporary for testing
export PATH=.:..:$PATH
. installer-functions
. ui-functions
. ui-dialogs

tmpdir=/tmp
if [ -d $HOME/tmp ] ; then
  tmpdir=$HOME/tmp
fi
errorfile=`mktemp $tmpdir/ui-lasterror-XXXXXX`
logfile=`mktemp $tmpdir/ui-logfile-XXXXXX`
position=1
do_validate=1

custom_text=$(nls "_C_u_s_t_o_m")
auto_text=$(nls "_A_u_t_o")
none_text=$(nls "None")

find_config_paths $@
load_or_create_config

if [ -f $errorfile ]; then rm -f $errorfile; fi
if [ -f $logfile ]; then rm -f $logfile; fi

#if [ -f ../installer-validate ]; then ln -sfn ../installer-validate installer-validate; fi
#if [ -f ../installer-functions ]; then ln -sfn ../installer-functions installer-functions; fi



## ######################## dialogs ###########################
## ui-<varname> dialogs
## to choose value for every variable
## they output to be eval'ed like:
## 'res_menu="net"
##  res_input="nettt"
##  res=1 '
## res value -1 means cancel

ui-source () {
dml <<EOF 
    <br>`nls "Choose the source of installation"`
    <br>
    <meta title="$(nls "Type of installation")">
    <menu id=res_menu res=1>
    <item id=cdrom>_cdrom
    <item id=net>_net: `nls "network server (ftp, http)"`
    <item id=nfs>_nfs: `nls "NFS server"`
    <item id=disk>_disk: `nls "Hard disk partition"`
    </menu> 
    $@
EOF
}

ui-source_device () {
case "$source" in 
    cdrom)
	item1="/dev/hda"
	item2="/dev/hdb"
	item3="/dev/hdc"
	item4="/dev/hdd"
	item5="/dev/scd0"
	item6="/dev/scd1"
	item7="/dev/scd2"
	item8="/dev/scd3"
	item9="/dev/scd4"
	dml <<EOF 
	    <br>`nls "If you have single IDE cdrom, choose auto"`
	    <br>
	    <meta title="CDROM">
	    <menu id=res_menu res=1>
	    <item id=ui_custom>${custom_text}
	    <item id=auto>${auto_text}
	    <item id=$item1>$item1
	    <item id=$item2>$item2
	    <item id=$item3>$item3
	    <item id=$item4>$item4
	    <item id=$item5>$item5
	    <item id=$item6>$item6
	    <item id=$item7>$item7
	    <item id=$item8>$item8
	    <item id=$item9>$item9
	    </menu>
	    $@
EOF
	;;
    nfs)
	item1="192.168.0.1:/home/users/klakier/rpm"
	item2="heaven.net:/pub/all/saints"
	dml <<EOF
	    <br>`nls "NFS device should be given in form machine:/directory."`
	    <br>
	    <meta title="$(nls "NFS server")">
	    <menu id=res_menu res=1>
	    <item id=ui_custom>${custom_text}
	    <item id=$item1>$item1
	    <item id=$item2>$item2
	    </menu> 
	    $@
EOF
	;;
    net) 
	dml <<EOF
	    <br>`nls "Choose server or enter custom one"`
	    <br>
	    <meta title="$(nls "Remote server")">
	    <menu id=res_menu res=1> 
	    <item id=ui_custom>${custom_text}
$(ui-mirror just-dump)
	    </menu>
	    $@
EOF
	;;
    disk)
	dml <<EOF 
	<br>`nls "Choose partition or enter custom one"`
	<br>
	<meta title="$(nls "Disk partition with source")">
	<menu id=res_menu res=1> 
	<item id=ui_custom>${custom_text}
	<item id=/dev/hda1>/dev/hda1
	<item id=/dev/hda2>/dev/hda2
	</menu>
	$@
EOF
	;;
esac
}


ui-source_filesystem () {
case "$source" in 
    disk)
	dml <<EOF 
	<br>`nls "Choose partition or enter custom one"`
	<br>
	<meta title="$(nls "Source filesystem")">
	<menu id=res_menu res=1>
	<item id=ext2>`nls "Linux ext2 filesystem"`
	<item id=reiserfs>`nls "Reiser FS filesystem"`
	<item id=vfat>`nls "FAT or FAT32 filesystem (eg. Windows partition)"`
	</menu> $@
EOF
	;;
    *)
	# do not change
	echo "source_filesystem=$source_filesystem"
esac
}

archname () { uname -m | sed 's/i486/i386/'; }

ui-source_dir () {
local extra1 extra2
item1="/$FTP_DIST_DIR/`archname`"
extra1=""
extra2=""
case "$source" in 
disk) 
    extra1="<br>${auto_text} - $(nls "let installer find proper dir")"
    extra2="<item id=auto>${auto_text}"
    ;;
esac
dml <<EOF 
    <br>`nls "Choose directory where PLD source may by found"`:
    <br>(`nls "directories"` PLD/{RPMS,installer})
    $extra
    <br>
    <meta title="Source Directory">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    $extra2
    <item id="$item1">$item1
    <item id="">none
    </menu>
    $@
EOF
}


ui-dest_devices () {
item5="/dev/hda /dev/hdb"
item6="/dev/hda /dev/hdc"
dml <<EOF 
    <br>`nls "Enter or choose set of destination disks"`
    <br>
    <meta title="$(nls "Set of destination disks")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    `ide_disk_items`
    <item id="$item5">$item5: `nls "Example entry for two IDE disks"`
    <item id="$item6">$item6: `nls "Example entry for two IDE disks"`
    </menu>
    $@
EOF
}

ui-boot_loader_other () {
item1="dos:winda:/dev/hda1"
item2="bsd:devil:/dev/hdc1 dos:hell:/dev/hda1"
dml <<EOF 
    <br>`nls "Enter other operating systems"`
    <br>
    <meta title="$(nls "Other systems")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id="">$(nls "No other systems")
    <item id="$item1">$item1: `nls "Windows on 1st partition of 1st IDE drive"`
    <item id="$item2">$item2: `nls "Windows on hda1 & BSD on hdc1"`
    </menu>
    $@
EOF
}

ui-pkgs_cpus () {
dml <<EOF 
    <br>`nls "Enter or choose number of CPUs in this box"`
    <br>
    <meta title="$(nls "# of CPUs")">
    <menu id=res_menu res=1>
    <item id=auto>Autodetect
    <item id=ui_custom>${custom_text}
    <item id=1>$(nls "UniProcessor")
    <item id=2>$(nls "Double-Processor")
    <item id=4>$(nls "Four-Way")
    </menu>
    $@
EOF
}

ui-boot_loader_device () {
dml <<EOF 
    <br>`nls "Enter device to install bootloader on"`
    <br>
    <meta title="$(nls "boot = ?")">
    <menu id=res_menu res=1>
    <item id=auto>Autodetect
    <item id=ui_custom>${custom_text}
    <item id=/dev/hda>/dev/hda
    <item id=/dev/sda>/dev/sda
    <item id=/dev/hda1>/dev/hda1
    </menu>
    $@
EOF
}

ui-net_proxy () {
dml <<EOF 
    <br>`nls "Enter FTP/HTTP proxy"`
    <br>
    <meta title="$(nls "Proxy")">
    <menu id=res_menu res=1>
    <item id=none>$(nls "No proxy")
    <item id=ui_custom>${custom_text}
    <item id="http://squid.example.org:3128/">http://squid.example.org:3128/>
    </menu>
    $@
EOF
}
# support function
actions_menu () {
local actions action desc
echo -n '<br><meta title="'; 
nls 'Actions for destination disks'
echo '">'
nls 'Decide what to do with every destination disk'
echo ':<br>'
nls '1) Delete existing partitions and create new ones'
echo '<br>'
nls '2) Create new partitions trying to utilize unused space (if any)'
echo '<br>'
nls '   at bottom of disk'
echo '<br>'
nls '3) Use existing partitions (the disk must be properly partitioned before'
echo '<br>'
nls '   running installer)'
echo '<br><br>'
nls 'Press Enter to toggle, Ok to confirm'
echo '<br><br>'
echo '<menu id=res_tmp width=74 res=1>'
actions="$dest_devices_actions"
for i in $dest_devices; do
    action=`list_car $actions`
    actions=`list_cdr $actions`
    case "$action" in
    make_new) 
	desc=$(nls "Make _n_e_w (delete all existing ones)") ;;
    use_existing)
	desc=$(nls "Use _e_x_i_s_t_i_n_g") ;;
    *)
	desc=$(nls "Unspecified, press Enter to change") ;;
    esac
    echo "<item id="$i">$i: $desc"
done
echo "</menu> $@"
}


## this is more complicated
ui-dest_devices_actions () {
local res_tmp actions action new_actions
while : ; do
    eval `actions_menu $@ | dml`

    if test "$res" = "2" -o "$res" = "-1"; then
	# ok pressed
	echo "res_menu=\"$dest_devices_actions\""
	echo "res=$res"
	break
    fi
    # res_tmp returns the disk name for which the action should be changed
    new_actions=""
    actions="$dest_devices_actions"
    for i in $dest_devices; do
	action=`list_car $actions`
	actions=`list_cdr $actions`
	if test "x$i" = "x$res_tmp"; then
	    case "$action" in
	    make_new) action=use_existing ;;
	    *) action=make_new ;;
	    esac
	fi
	new_actions="${new_actions}${new_actions:+ }${action}"
    done
    dest_devices_actions="$new_actions"
done

}


example_mnt_point_items () {
local desc id dir i
for i in swap / /boot /home /home/users /usr /var /var/spool; do
    desc=""
    id=0
    while : ; do
	id=$(($id+1))
	eval "dir=\$dest_part${id}_mnt_point"
	test "$dir" || break
	test "x$i" = "x$dir" || continue
	desc="_(${id}_)"
	break
    done
    echo "<item id="$i">$i $desc"
done
}


ui-dest_part_mnt_point () {
dml <<EOF 
    <br>`nls "Choose the mount point"`
    <br>
    <meta title="$(nls "Mount point")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    `example_mnt_point_items`
    </menu>
    $@
EOF
}

# make items for example partitions for current dest_devices
example_partitions () {
local actions action
actions="$dest_devices_actions"
for i in $dest_devices; do
    action=`list_car $actions`
    actions=`list_cdr $actions`
    case "$action" in
    use_existing)
	# show partitions
	for j in 1 2 3 4 5 6 7 8; do
	    p=$(part $i $j)
	    echo "<item id='$p'>"
	    nls "Place on partition"
	    echo " $p"
	done
	;;
    *)
	# show disk
	echo "<item id=${i}>"; nls "Place on disk"; echo " ${i}"
	;;
    esac
done
}

ui-dest_part_device () {
dml <<EOF 
    <br>`nls "Specify onto what disk you want to put partition"`
    <br>`nls "If you selected to use existing partitions on given disk,"`
    <br>`nls "you must specify this partition"`
    <br>
    <meta title="$(nls "Partition device")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    `example_partitions`
    </menu>
    $@
EOF
}

ui-dest_part_size () {
item1="30"
item2="300"
item3="20% of all"
item4="50% of all"
item5="50% of free"
item6="100% of free"
dml <<EOF 
    <br>`nls "Specify size in megabytes or as a percentage"`
    <br>
    <meta title="$(nls "Partition size")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id="$item1">$item1
    <item id="$item2">$item2
    <item id="$item3">$item3
    <item id="$item4">$item4
    <item id="$item5">$item5
    <item id="$item6">$item6
    </menu>
    $@
EOF
}

ui-dest_part_format_partition () {
if test "x$dest_part_format_partition" = "xyes"; then
    echo 'res_menu="no"'
else 
    echo 'res_menu="yes"'
fi
echo 'res=1'
}

ui-dest_part_filesystem () {
item0="swap"
item1="ext2"
item2="reiserfs"
item3="md"
item4="jfs"
item5="ext3"
item6="xfs"
dml <<EOF 
    <br>`nls "Select filesystem for partition"`
    <br>
    <meta title="$(nls "Partition filesystem")">
    <menu id=res_menu res=1>
    <item id="$item0">$item0: `nls "Linux swap partition"`
    <item id="$item1">$item1: `nls "Standard filesystem for Linux partition"`
    <item id="$item2">$item2: `nls "Reiser FS filesystem"`
    <item id="$item3">$item3: `nls "Partition to build RAID from"`
    <item id="$item4">$item4: `nls "IBM Journaling Filesystem"`
   $(if [ $KERNEL_VERCODE -ge 4 ] ; then
      echo "<item id="$item5">$item5: `nls "Journaling version of ext2 (2.4 only)"`"
      echo "<item id="$item6">$item6: `nls "SGI Journaling Filesystem (2.4 only)"`"
     fi)
    </menu>
    $@
EOF
}

ui-dest_part_format_options () {
dml <<EOF 
    <br>`nls "If you need to pass any extra options to formatting program,"`
    <br>`nls "put them here"`
    <br>
    <meta title="$(nls "Partition format options")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id="-m 1">-m 1 -- $(nls "reserve just 1% of disk for r00t.")
    <item id="-L foo">-L foo -- $(nls "name partition 'foo'")
    </menu>
    $@
EOF
}

ui-dest_part_options () {
item1="defaults"
item2="nosuid,nodev"
dml <<EOF 
    <br>`nls "If you need to set special mount options for partition,"`
    <br>`nls "put them here"`
    <br>
    <meta title="Partition mount options">
    `nls "Selected disks"`: $dest_devices
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id="$item1">$item1
    <item id="$item2">$item2
    </menu>
    $@
EOF
}

ui-pkgs_install_docs () {
if test "x$pkgs_install_docs" = "xyes"; then
    echo 'res_menu="no"'
else 
    echo 'res_menu="yes"'
fi
echo 'res=1'
}

ui-pkgs_install_langs () {
dml <<EOF 
    <br>$(nls "Install languages:")
    <br>
    <meta title="$(nls "%_install_langs")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id="all">all
    <item id="af">Affrikaans   (af)
    <item id="az">Azerbbaijani (af)
    <item id="be">Belarusian   (be)
    <item id="bg">Bulgarian    (bg)
    <item id="zh:zh_CN:zh_TW:zh_CN.GBK:zh_CN.gbk:zh_CN.gb2312:zh_HK">Chinese      (zh:zh__*)
    <item id="ca">Catalan      (ca)
    <item id="hr">Croatian     (hr)
    <item id="cs">Czech        (cs)
    <item id="da">Danish       (da)
    <item id="nl">Dutch        (nl)
    <item id="fi">Finnish      (fi)
    <item id="fr">French       (fr)
    <item id="en:en_GB:en_CA">English non-US (en:en__*)
    <item id="de:de_DE:de_AT:de_LU">German       (de:de__*)
    <item id="el">Greek        (el)
    <item id="hu">Hungarian    (hu)
    <item id="id">Indonesian   (id)
    <item id="is">Icelandic    (is)
    <item id="it">Italian      (it)
    <item id="ja:ja_JP.SJIS">Japanese     (ja:ja__JP.SJIS)
    <item id="ko:ko_KR:ko_KR.UTF-8:ko_KR.utf8">Korean       (ko:ko__KR.UTF-8)
    <item id="no:nn">Norwegian    (nn:no)
    <item id="pl">Polish       (pl)
    <item id="pt:pt_BR">Portuguese   (pt:pt__BR)
    <item id="ro">Romanian     (ro)
    <item id="ru">Russian      (ru)
    <item id="sr">Serbian      (sr)
    <item id="sk">Slovak       (sk)
    <item id="sl">Slovenian    (sl)
    <item id="es:es_ES">Spanish      (es:es__ES)
    <item id="sv">Swedish      (sv)
    <item id="th">Thai         (th)
    <item id="tr">Turkish      (tr)
    <item id="uk:uk_UA">Ukrainian    (uk)
    <item id="am:bn:br:cy:eo:et:eu:ga:he:hi:hy:ka:lo:lv:mi:ms:mt:sp:sq:sr:ta:ur:vi:wa:xh:yi">Others
    </menu>
    $@
EOF

#   <item id="zh:zh_CN:zh_CN.gb2312">Chinese [GB2312](zh:zh__CN)
#   <item id="zh_CN.GBK:zh.GBK:zh_CN.gbk">Chinese [GBK]   (zh:zh__CN.GBK)
#   <item id="zh_TW:zh_TW.BIG5:zh_TW.big5">Chinese [BIG5]  (zh__TW)

#   <item id="ko">Korean [EUCKR] (ko)
#   <item id="ko_KR.UTF-8:ko_KR.utf8">Korean [UTF-8] (ko__KR.UTF-8)

#    <item id="am">Amharic
#    <item id="bn">Bengali
#    <item id="br">Breton
#    <item id="cy">Cymraeg
#    <item id="eo">Esperanto
#    <item id="et">Estonian
#    <item id="eu">Basque
#    <item id="ga">Irish
#    <item id="he">Hebrew
#    <item id="hi">Hindoo
#    <item id="hy">Armenian
#    <item id="ka">Georgian
#    <item id="lo">Laotian
#    <item id="lv">Latvian
#    <item id="mi">Maori
#    <item id="ms">Malay
#    <item id="mt">Maltese
#    <item id="sp:sp_YU">???
#    <item id="sq">Albanian
#    <item id="sr">Serbian
#    <item id="ta">Tamil
#    <item id="ur">Urdu
#    <item id="vi">Vietnamese
#    <item id="wa">Waloon
#    <item id="xh">Xhosa
#    <item id="yi">Yidish

}


# create scsi items
scsi_hostadapter_items () {
local automods=`detect-scsi-devices -m || :`
local text=$(nls "_*_d_e_t_e_c_t_e_d_*")
grep -vs '^~' /etc/scsi-low.list.in | while read line; do
    dev=`echo $line | sed 's/\.o|.*//'`
    for i in $automods; do 
	if test "x$i" = "x$dev"; then
	    auto="(${text})"
	    break
	else
	    auto=""
	fi
    done
    dev2=`echo $dev | sed 's/_/__/g'`
    desc=`echo $line | sed 's/[^|]*|//' | sed 's/|.*//'`
    echo "<item id=\"$dev\">$dev2: _$desc $auto"
done
}


ui-scsi_hostadapters () {
dml <<EOF
    <br>`nls "Put the name of low-level module(s) for your SCSI adapter"`
    <br>`nls "If you have only one adapter, you may select appropriate from the list"`
    <br>`nls "Alternatively, you may choose %s to scan for adapters (PCI only)" "${auto_text}"`
    <br>
    <br>`nls "If you don't have any, leave it blank or set to %s" "${auto_text}"`
    <br>
    <meta title="$(nls "SCSI low-level modules")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id=auto>${auto_text}
    `scsi_hostadapter_items`
    </menu>
    $@
EOF
}

ui-pcmcia_controller () {
item1=tcic
item2=i82365
dml <<EOF
    <br>`nls "Put the name of low-level module for your PCMCIA controller"`
    <br>
    <br>`nls "If you don't have any, leave it blank or set to %s" "${auto_text}"`
    <br>
    <meta title="$(nls "PCMCIA controller")">
    <menu id=res_menu res=1>
    <item id=ui_custom>${custom_text}
    <item id=auto>${auto_text}
    <item id=$item1>$item1
    <item id=$item2>$item2
    <item id="">`nls "_N_o_n_e"`
    </menu>
    $@
EOF
}



ui-pkgs_installer () {
dml <<EOF 
    <br>`nls "Choose installer for RPM software packages"`
    <br>
    <meta title="$(nls "RPM installer")">
    <menu id=res_menu res=1>
    <item id=poldek>poldek: _`nls "Non-interactive installer (default)"`
    <item id=wuch  >wuch:   _`nls "Interactive installer that lets you fine-tune set of packages"`
    </menu>
    $@
EOF
}

ui-boot_loader () {
dml <<EOF 
    <br>`nls "Choose bootloader"`
    <br>
    <meta title="$(nls "Bootloader")">
    <menu id=res_menu res=1>
    <item id=rc-boot>rc-boot: anything (select lilo or grub package)
    <item id=lilo>lilo: straight lilo (no rc-boot)
    <item id=none>`nls "_N_o_n_e"`
    </menu>
    $@
EOF
}



# return the number of partitions to create
new_partition_number () {
id=0
while true
do
    id=$(($id+1))
    eval "dest_part_device=\$dest_part${id}_device"
    test "$dest_part_device" || { echo $id; return 0; }
done
}




# display help for given option.
# syntax of helpfile:
# # comment
# %variable_name
# description...
# blah...
# %next_var
# ...

help () {
  local line
  
  if test -r $helpfile ; then
    (
      echo "<meta title=$(nls Help) active=ok>"
      echo "<text width=70 height=18>"
      print=0
      did=0
      while read line ; do
        case $line in
	%* )
	  print=0
	  if test "%$1" = "$line" ; then
	    print=1
	  fi
	  ;;
	\#* )
	  ;;
	* )
	  if test $print = 1 ; then
	    if test "$line" ; then
	      echo "$line"
	    else
	      echo "<br><br>"
	    fi
	    did=1
	  fi
	  ;;
	esac
      done < $helpfile 
      if test $did = 0 ; then
        nls "Sorry, no help for: <i>%s</i> :(" "$1"
      fi
      echo "</text><button id=ok>"
    ) | dml > /dev/null
  else
    dml "$(nls "Sorry, cannot find %s" "$helpfile").<br><button>" > /dev/null
  fi
}

######################## main ############################

. $conffile

validation_enabled=yes
result=0
while : ; do

    if test "$do_validate" -a "x$validation_enabled" = "xyes"; then 
	nls "Please wait while validating...\n"
	# todo check if validator exists
	echo -n >$errorfile
	installer-validate -C $conffile >>$errorfile
	#if test $? != 0; then echo 'Fatal validation error' >>$errorfile; fi
    fi

    # create form, run it and get the result
    eval "`ui-makeform $conffile $errorfile $result $validation_enabled | dml`"
  
    # all dialogs returns res, change to 'result' to not confuse program
    if test $res = 1 ; then
      result=$menures
    elif test $res = 3 ; then
      result="help_`echo $menures | sed -e 's/dest_part[0-9]*/dest_part/'`"
    else
      result=$res
    fi
 
    do_validate=1
    echo "result = $result" >>$logfile
    case "$result" in
	source)
	    ask source
	    case "$source" in 
		cdrom) source_filesystem=iso9660; source_dir="" ;;
		nfs) source_filesystem=nfs ;;
		net) source_filesystem=net; source_dir="";;
	    esac
	    ;;
	net_ipaddr)
	    ask net_ipaddr 
	    if test "x$net_ipaddr" = "xdhcp"; then
		net_prefix=""
		net_gateway=""
		net_dns=""
	    fi
	    ;;

	dest_devices) 
	    tmp="$dest_devices"
	    ask dest_devices 
	    # if changed, reset actions
	    if test "x$dest_devices" != "x$tmp"; then dest_devices_actions=""; fi
	    ;;

	dest_part*)
	    # partitioning support
	    action=$(echo $result | sed -e 's/dest_part[0-9]*_//')
	    id=$(echo $result | sed -e 's/dest_part\([0-9]*\).*/\1/')
	    test "$id" || die "Fatal: cannot get partition number"

	    eval_partition_info $id

	    case "$action" in 
	    mnt_point) 
	        ask dest_part_mnt_point
		if test "x$dest_part_mnt_point" = "xswap"; then dest_part_filesystem=swap; fi
		;;
	    *)
	        ask dest_part_$action
		;;
	    esac

	    eval "dest_part${id}_mnt_point=\"$dest_part_mnt_point\""
	    eval "dest_part${id}_device=\"$dest_part_device\""
	    eval "dest_part${id}_size=\"$dest_part_size\""
	    eval "dest_part${id}_filesystem=\"$dest_part_filesystem\""
	    eval "dest_part${id}_format_partition=\"$dest_part_format_partition\""
	    eval "dest_part${id}_format_options=\"$dest_part_format_options\""
	    eval "dest_part${id}_options=\"$dest_part_options\""
	    ;;

	delete_last_part)
	    new_number=`new_partition_number`
	    last_partition_number=`expr $new_number - 1 || :`
	    eval "dest_part${last_partition_number}_device="
	    eval "dest_part${last_partition_number}_mnt_point="
	    position=`expr $position - 7`
	    ;;
	    
	create_new_part)
	    # add new partition
	    ask dest_part_mnt_point
	    nr=`new_partition_number`
	    echo new_partition_number=$nr >>$logfile
	    eval "dest_part${nr}_mnt_point=$dest_part_mnt_point"
	    eval "dest_part${nr}_format_partition=yes"
	    eval "dest_part${nr}_filesystem=$(
	    	if test $dest_part_mnt_point = swap ; then 
		  echo swap 
		else 
		  echo ext2
		fi)"
	    eval "dest_part${nr}_device=/dev/hda"
	    # if we have only one disk, choose it
	    if echo "$dest_devices" | grep -q " "; then
		:
	    else
		if test "x$dest_devices_actions" != "xuse_existing"; then
		    eval "dest_part${nr}_device=$dest_devices"
		fi
	    fi
	    ;;

	2)
	    nls "Validating once again...\n"
	    installer-validate -C $conffile >$errorfile
	    if test $? != 0; then
		dml > /dev/null <<EOF
		    <meta title="$(nls "Warning!")">
		    <br>`nls "Config is not valid."`
		    <br>`nls "Installation process will fail if you run it now."`
		    <br><br>
		    <button res=1 caption="$(nls "Oh no! I'll correct this, I promise... let me out now")">
		    <br>
EOF
	    fi
	    break
	    ;;
	
	help_* )
	    result=`echo $result | sed -e 's/^help_//'`
	    help $result 
	    ;;
	*)
	    ask "$result"
	    ;;

    esac

    save_config
done

# vim:ft=sh
