#!/bin/ash

# 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:
# Major simplifications (<menu> list of items) by Micha Moskal 
# (suggestion to do it this way come from Micha Stochmiaek).


# this file outputs form presenting current state of installer.conf for dml program

## first argument is config name - inputfile
## second is the name of file containing last error - errorfile
## third is id of the widget (button) that has focus last time
##   (this id is the same that button's res) - active
## fourth is switch validation_enabled (yes/no)
## fifth is a functions filename

inputfile=$1
if test $2; then errorfile=$2; else errorfile=/dev/null; fi
if test $3; then active=$3; else active=0; fi
if test $4; then validation_enabled=$4; else validation_enabled=yes; fi
#if test $5; then  . $6
#else # define fake function to let the script to work somehow  nls () { echo -n "$@"; } fi

. $inputfile


PATH=.:..:$PATH . installer-functions
PATH=.:..:$PATH . ui-functions
PATH=.:..:$PATH . ui-dialogs

# globals
if test "x$validation_enabled" != "xno"; then 
  menu_height=12
else
  menu_height=17
fi

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

# header
nls "General settings of installation process."
echo "<br>"
nls "Press Return (Enter) to change"
cat <<EOF
<meta title="$(nls "Installer settings")">
<meta height=25 width=80 active=menures>
<br>
<br>
<menu height=$menu_height width=76 id=menures res=1 selected=$active>
EOF

separator "$(nls "Source options")"
item source "$(nls "Source of installation")"
item source_device "$(nls "Source device (may be disk device, partition, ftp address)")" 

case "$source" in
disk) 
    item source_filesystem "$(nls "Filesystem type of source of installation")" 
    ;;
esac

if test "x$source" != "xcdrom"; then 
    item source_dir "$(nls "Dirpath to source of installation")" 
fi

case "$source" in
net|nfs) 
    item net_device "$(nls "Net interface name (in most cases single Eternet card eth0)")" 
    item net_device_module "$(nls "Network card type")" 
    item net_device_module_options "$(nls "Options for network card module")" 
    item net_ipaddr "$(nls "IP address of machine")" 
    if test "x$net_ipaddr" != "xdhcp"; then
	item net_prefix "$(nls "Prefix for IP address")" 
	item net_gateway "$(nls "IP address if default router")" 
	item net_dns "$(nls "List of dns servers (IP addresses) (optional)")" 
    fi
    item net_proxy "$(nls "HTTP/FTP proxy")" 
    ;;
esac

separator "$(nls "Other options")"
item scsi_hostadapters "$(nls "SCSI adapters, if you have any")"
item pcmcia_controller "$(nls "PCMCIA controller, if you have any")"

item pkgs_installer "$(nls "Which installer use to install RPM packages")" 
item pkgs_install_docs "$(nls "Whatever to install documentation")" 
item pkgs_install_langs "$(nls "Which languages to install")" 
item pkgs_cpus "$(nls "# of CPUs in installed box")" 
item boot_loader "$(nls "Bootloader")"
item boot_loader_other "$(nls "Other systems on this box")"
item boot_loader_device "$(nls "Device to which install bootloader")"

separator "$(nls "Destination options")"
item dest_devices "$(nls "List of hard disks to install on")" 
item dest_devices_actions "$(nls "What to do with partitions of proper disks?")" 


separator "$(nls "Destination partitions options")"

## now present partitions
id=0
while : ; do
    id=$(($id+1))
    eval "mnt_point=\$dest_part${id}_mnt_point"
    eval "device=\$dest_part${id}_device"
    eval "size=\$dest_part${id}_size"
    eval "filesystem=\$dest_part${id}_filesystem"
    eval "format=\$dest_part${id}_format_partition"
    eval "options=\$dest_part${id}_options"
    eval "format_options=\$dest_part${id}_format_options"
    test -n "$mnt_point" || break

    separator "  $(nls "Partition") $id"

    item dest_part${id}_mnt_point "-------------- $(nls "Partition") $id ---------------"
    item dest_part${id}_device "$(nls "Partition device")"
    item dest_part${id}_size "$(nls "Partition size (in megabytes or percents)")"
    item dest_part${id}_filesystem "$(nls "Partition filesystem")"
    item dest_part${id}_format_partition "$(nls "Format partition?")"
    item dest_part${id}_format_options "$(nls "Extra options to format program (for experts)")"
    item dest_part${id}_options "$(nls "Partition mounting options")"
done



cat <<EOF
<item id=create_new_part>                    _[ `nls "_c_r_e_a_t_e new partition entry"`  _]
<item id=delete_last_part>                    _[ `nls "_d_e_l_e_t_e last partition entry"` _]
<item ghosted=1>
</menu>
EOF

# add switch to disable validation
if test "x$validation_enabled" = "xno"; then
    validation_checked=0
else
    validation_checked=1
fi

echo '<br>'
echo -n "<check id=validation_enabled checked=$validation_checked res=1> "
nls "validation"
echo '                                   '
echo "<button res=2 caption='$(nls "_Finish")'>"
echo "<button res=3 caption='$(nls _Help)'>"
echo '<br>'

if test "x$validation_enabled" = "xyes"; then

if test -f $errorfile; then
    # must be the same string that validator returns
    result_string=$(nls "Validation")

    echo '<br><text width=76 height=3>'
    if grep -q "^$result_string " $errorfile; then 
	echo '<b>'
	grep "^$result_string " $errorfile
	echo '</b><br>'
    else 
	echo '<b>'
	nls "To be corrected"
	echo ':</b><br>'
    fi

    # display "log"
    grep -v "^$result_string " $errorfile | sed 's@^[^:]*:@<i>&</i>@' | sed 's/$/<br>/'
    
    echo "</text>"

fi # have errorfile

fi # of validation_enabled


# vim:ft=sh
# Local Variables:
# mode: shell-script
# End:
