#!/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, Micha Moskal
# Contributors: 


# validator finds some simple errors in installer input file
# it finds only some logic errors, e.g dest_dev is /dev/hdX
# and dest_root_partition=/dev/sdY 

# two modes:
# 1) final - this mode does not permit empty values when they cannot empty
# 2) draft - this mode lets you validate installer-conf that is not yet finished (e.g. for ui)
#    this mode is enabled if the file is invoked as installer-validate-unfinished

# returns: error message in the form:  "variable: what is wrong with it" and nonzero status
# or zero status


set -e 
#set -x

script_name=$0
PATH=$PATH:. . installer-functions

# TODO

# w mount options nie moe by spacji
# hmm, czy partycja usr, root nie moe by wykorzystywana gotowa np z rh
# czy nie ma pustych zmiennych jak powinny by wypenione
# czy zmienne, ktre powinny zawiera pojedyncz warto nie maj spacji
# wymuszanie swapa odpowiedniej wielkoci, podanego explicite w M nie % itp


######### globals ##########

# configuration -- TODO need to set them by some options
# whatever to die after first error
bail_on_error=yes
# whatever to die after first warning
bail_on_warning=no
# whatever to exit with non-0 status in case of warnings
warnings_fatal=no

need_net=no
have_root=no
have_swap=no
was_error=no
was_warning=no
draft=""

######### basic functions ##########

error () {
    var=$1
    shift
    echo "$var: $@"
    was_error=yes
    if [ "$bail_on_error" = yes ] ; then
      exit 2
    fi
}

warning () {
    echo "$1: $2"
    was_warning=yes
    if [ "$bail_on_warning" = yes ] ; then
      exit 3
    fi
}

is_not_empty () {
    local val
    eval "val=\$${1}"
    # additionally, the variable cannot contain certain chars (used in ui )
    echo "$val" | grep -q '^[a-zA-Z0-9 _/@~:%+\.\-]*$' || error $1 "`nls "illegal character"`"
    # check epmtiness
    if test "$draft"; then 
	# do not check
	return 0
    else
	test "$val" || error $1 "`nls "must be filled"`"
    fi
}

# check if argument does not contain spaces
is_not_list () {
    local val
    eval "val=\$${1}"
    if echo -n "$val" | grep -q " "; then 
	error $1 "`nls "variable cannot contain spaces"`"
    fi
}

# first argument is varname, second is value
is_equal () {
    local val
    eval "val=\$${1}"
    test "x$val" = "x$2" || error $1 "`nls "must have value"`" "$2"
}

is_not_auto () {
    local val
    eval "val=\$${1}"
    test "x$val" != "xauto" || error $1 "`nls "auto not supported if source=%s" "$source"`"
    
}

# return 'disk', 'part' or 'unknown'
whats_that () {
  case $1 in
    /dev/hd[a-h] | /dev/sd[a-p] | \
    /dev/ida/c[0-2]d[0-9] | /dev/ida/c[0-2]d1[1-5] | \
    /dev/cciss/c[0-2]d[0-9] | /dev/cciss/c[0-2]d1[1-5] | \
    /dev/ataraid/d[0-9] | /dev/ataraid/d1[1-5] | \
    /dev/i2o/hd[a-p] | \
    /dev/rd/c[0-7]d[0-9] | /dev/rd/c[0-7]d[1-3][0-9] )
      echo disk
      ;;
    /dev/hd[a-h][1-9] | /dev/hd[a-h]1[1-6] | \
    /dev/sd[a-p][1-9] | /dev/sd[a-p]1[1-5] | \
    /dev/md[0-9] | /dev/md1[1-5] | \
    /dev/cciss/c[0-2]d[0-9]p[1-9] | /dev/cciss/c[0-2]d1[1-5]p[1-9] | \
    /dev/cciss/c[0-2]d[0-9]p1[1-5] | /dev/cciss/c[0-2]d1[1-5]p1[1-5] | \
    /dev/ataraid/d[0-9]p[1-9] | /dev/ataraid/d1[1-5]p[1-9] | \
    /dev/ataraid/d[0-9]p1[1-5] | /dev/ataraid/d1[1-5]p1[1-5] | \
    /dev/i2o/hd[a-p][1-9] | /dev/i2o/hd[a-p]1[1-6] | \
    /dev/ida/c[0-2]d[0-9]p[1-9] | /dev/ida/c[0-2]d1[1-5]p[1-9] | \
    /dev/ida/c[0-2]d[0-9]p1[1-5] | /dev/ida/c[0-2]d1[1-5]p1[1-5] | \
    /dev/rd/c[0-7]d[0-9]p[1-7] | /dev/rd/c[0-7]d[1-3][0-9]p[1-7] )
      echo part
      ;;
    *)
      echo unknown
      ;;
   esac
}

# first argument is string to check, second is varname
is_disk () {
  case `whats_that $1` in
    disk)
      : ok
      ;;
    * ) 
      error $2 "`nls "%s is not valid disk name"`"
      ;;
  esac
}

# first argument is string to check, second is varname
is_part () {
  case `whats_that $1` in
    part)
      : ok
      ;;
    * ) 
      error $2 "`nls "%s is not valid partition name"`"
      ;;
  esac
}

# first argument is string to check, second is varname
is_disk_or_part () {
  case `whats_that $1` in
    part | disk)
      : ok
      ;;
    * ) 
      error $2 "`nls "%s is not valid partition or disk name"`"
      ;;
  esac
}

######### functions ##########

# check if the dirname is not weird
# if second parameter is used, use this as a value
is_dirname () {
    local val
    # the ':' is required
    if test "$2"; then val=$2; else : ; eval "val=\$${1}"; fi
    is_not_empty $1
    is_not_list $1
    if echo "$val" | grep -q "^[a-zA-Z0-9_/\.\-]*$"; then
	: is ok
    else
	error $1 "`nls "weird dirname %s. Allowed chars: letters, digits %s" "$val" ", /_-."`"
    fi
}

is_absolute_dirname () {
    local val
    # the ':' is required
    if test "$2"; then val=$2; else : ; eval "val=\$${1}"; fi
    is_dirname $1 $val
    echo "$val" | grep -q "^/" || error $1 "`nls "must be absolute dirname, starting with '/'"`"
}

is_nfs_dirname () {
    local val source_device_hostname source_device_dirname 
    eval "val=\$${1}"
    if echo "$val" | grep -q "^[^:][^:]*:/"; then
    	: is ok
    else
	error $1 "`nls "must be valid nfs address of the form hostname:/path"`"
    fi

    source_device_hostname=`echo $val | sed -e 's/:.*$//' || :`
    is_hostname $1 "$source_device_hostname"

    source_device_dirname=`echo $val | sed -e 's/^.*://' || :`
    is_dirname $1 "$source_device_dirname"
}


# check if given variable (list) contains numerical IPv{4,6}
is_ip () {
    local val i
    # the ':' is required
    if test "$2"; then val=$2; else : ; eval "val=\$${1}"; fi
    for i in $val; do
	if echo $i | grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$' ; then
	    case "$i" in
	      127.* )
	        error $1 "`nls "%s seems to be loopback address" "$i"`"
		;;
	      0.* )
	        error $1 "`nls "%s seems to be NUL address" "$i"`"
		;;
	      255.* )
	        error $1 "`nls "%s seems to be netmask" "$i"`"
		;;
	      * )
	        : ok
		;;
	    esac
	elif echo $i | grep -q ':' && echo $i | grep -q '^[A-Fa-f0-9:]\+$' ; then
	    : ok
	else
	    error $1 "`nls "%s does not contain valid numerical IP" "$i"`"
	fi
    done
}

# check if given hostname is valid.
# if second parameter is used, use this as a value
is_hostname () {
    local val
    # the ':' is required
    if test "$2"; then val=$2; else : ; eval "val=\$${1}"; fi
    is_not_empty $1
    is_not_list $1
    if test -z "$net_dns" -a "$net_ipaddr" != "dhcp"; then
	# use ip numbers if no dns given
	is_ip $1 "$val"
    else
	echo "$val" | grep -q '^[A-Za-z0-9._-]*' || error $1 "`nls "%s is not a valid hostname" "$val"`"
    fi
}


check_url_hostname () {
  local val proto rest port host
  eval "val=\$${1}"
  val=`echo $val | sed -e 's|/*$||' || :`
  proto=ftp	# default
  rest=$val
  if echo $val | grep -q ':/' ; then
    proto=`echo $val | sed -e 's/^\([a-zA-Z]\+\):\/.*/\1/' || :`
    rest=`echo $val | sed -e 's/^[a-zA-Z]\+:\/\+\(.*\)/\1/' || :`
  fi
  case $proto in
  ftp | http | rsync )
  	;;
  *)
  	error $1 "`nls "unsupported or invalid protocol '%s'" "$proto"`"
  esac
  port=31337
  host=$(echo $rest | sed -e 's|/.*||')
  dir=$(echo $rest | sed -e 's|[^/]*||')
  if test "$dir" ; then
    is_dirname $1 "$dir"
  fi
  
  case $host in
    *@* )
      host=$(echo $host | sed -e 's/.*@//')
  esac
  case $host in
    *:* )
      port=$(echo $host | sed -e 's/.*://')
      host=$(echo $host | sed -e 's/:[^:]*//')
  esac
  
  echo $port | grep -q '^[0-9]\+$' || error $1 "`nls "invalid port number: '%s'" "$port"`"
  
  is_hostname $1 $host
}

############## source ################

check_source() {
  is_not_empty source
  is_not_list source
  is_not_empty source_device
  is_not_list source_device

  is_not_empty source_filesystem
  is_not_list source_filesystem

  if test "$source_dir"; then is_dirname source_dir; fi

  case "$source" in
    nfs)
	is_equal source_filesystem nfs
	is_nfs_dirname source_device
	host=`echo $source_device | sed -e 's/:.*//' || :`
	is_hostname source_device $host
	need_net=yes
	;;
    net)
	is_equal source_filesystem net
	is_not_auto source_device
	check_url_hostname source_device
	is_not_auto source_dir
	need_net=yes
	;;
    cdrom)
    	# if one need other filesystem, notice me :)
    	is_equal source_filesystem iso9660
	case "$source_device" in 
	/dev/[hs]d[a-h] | /dev/scd[0-9] | auto )
		: ok
		;;
	*)
	  	error source_device "`nls "invalid cdrom device %s" "$source_device"`"
	esac
	;;
	
    disk)
	case "$source_device" in 
	/dev/[hs]d[a-h][0-9] | /dev/[hs]d[a-h][0-9][0-9] )
	    : ;;
	*)
	    error source_device "`nls "invalid partition device %s" "$source_device"`" ;;
	esac

	case "$source_filesystem" in 
	    ext2) : ;;
	    reiserfs) : ;;
	    vfat) : ;;
	    *) error source_filesystem "`nls "must be ext2, reiserfs or vfat if source=disk"`" ;;
	esac
    	;;
    *)
	error source "`nls "%s not supported" "$source"`"
	;;
  esac
}

check_net () {
  local dev i max_prefix
  have_net=no

  if [ "x$need_net" = xyes ] ; then
  
    is_not_empty net_device
    dev=`echo $net_device | sed -e 's/[0-9]*$//' || :`
    case $dev in
	eth | ppp | plip | arc | tr | sl | le )
	    : ok
	    ;;
	*)
	error net_device "`nls "unsupported device %s" "$dev"`"
    esac

    unset dev

    is_not_empty net_device
    is_not_list net_device

    is_not_empty net_device_module
    is_not_list net_device_module

    # TODO: _options

    is_not_list net_ipaddr
    is_not_empty net_ipaddr

    if test "$net_ipaddr" = "dhcp"; then
	test -z "$net_prefix" || error net_prefix "`nls "must be empty if net_ipaddr=dhcp"`"
	test -z "$net_gateway" || error net_gateway "`nls "must be empty if net_ipaddr=dhcp"`"
	test -z "$net_dns" || error net_dns "`nls "must be empty if net_ipaddr=dhcp"`"
    else
	is_ip net_ipaddr
	is_not_empty net_prefix
	if test "x$net_prefix" = "xauto"; then
	    case "$net_ipaddr" in
	    192.168.*) net_prefix=24 ;;
	    *) error net_prefix "`nls "cannot compute prefix for this address, must specify"`" ;;
	    esac
	else
	    if test yes = "$net_v6" ; then
	      max_prefix=128
	    else
	      max_prefix=32
	    fi
	    
	    if echo $net_prefix | grep -q '^[0-9]*$' && \
	       test "$net_prefix" -le $max_prefix ; then
		: ok
	    else
		error net_prefix "`nls "must be number %s or 'auto'" "0-32"`"
	    fi
	fi
  
	# net_gateway optional
	if test "$net_gateway" ; then 
	    is_not_list net_gateway  
	    is_ip net_gateway
	else
	    warning net_gateway "`nls "not set"`"
	fi
	if test "$net_dns"; then is_ip net_dns; fi
    fi
    have_net=yes
  fi

  if test "$net_proxy" -a "$net_proxy" != none ; then
    check_url_hostname net_proxy
    case $net_proxy in
      http://* )
        : ok
	;;
      * )
        error net_proxy "$(nls "should be http:// URL")"
	;;
    esac
  fi
}

# arg1=var_name arg2=string-to-check
check_raid_dev () {
  local drive name val var x raid_lev

  var=$1
  x=$2
  
  echo $x | grep -q "^/dev/md[0-9][0-9]*:raid[0145l]," || \
  	error $var "`nls "bad RAID header"`"
  raid_lev=`echo $x | sed -e 's|/dev/md[0-9]*:raid\([0-9l]\).*|\1|'`
  
  for drive in `echo $x | \
  		sed -e 's|/dev/md[0-9]*:raid[0-9l],||' | \
		sed -e 's/,/ /g'` ; do
    if echo $drive | grep -q = ; then
      name=`echo $drive | sed -e 's/=.*//'`
      val=`echo $drive | sed -e 's/.*=//'`
      case $name in
        chunk_size )
	  echo $val | grep -q '^[0-9][0-9]*$' || \
	  	error $var "`nls "chunk_size has to be numerical"`"
	  ;;
	just_start | persistent_superblock )
	  if [ $val != 0 ] && [ $val != 1 ] ; then
	     error $var "`nls "bad %s value '%s'" "$name" "$val"`"
	  fi
	  ;;
        parity_algorithm )
	  if [ "$raid_lev" != 5 ] ; then
	    error $var "`nls "parity_algorithm only allowed with raid5"`"
	  fi
	  echo $val | grep -q "\(left\|right\)-\(\|a\)symmetric" || \
	    error $var "`nls "bad parity type %s" "$val"`"
	  ;;
	* )
	  error $var "`nls "bad raid option or value: %s" "$name"`"
	  ;;
      esac	  
    else
      if echo $drive | grep -q ':spare' ; then
        if [ $raid_lev = 0 ] || [ $raid_lev = l ] ; then
	  error $var "`nls "cannot have spare disk for raid0 or linear"`"
	fi
	drive=`echo $drive | sed -e 's/:spare//'`
      fi
      is_disk_or_part $drive $var
      #is_part $drive $var # allow only raid over partitions, not whole disks...
    fi
  done
}

check_parts () {
  local id dest_part_device dest_part_size dest_part_filesystem \
	dest_part_format_partition dest_part_mnt_point \
  	dest_part_options dest_part_format_options have_root dev action actions \
	action_for_this
	
  have_root=no
  have_swap=no
  id=0
  all_mnt_points=""
  all_devices=""
  percent_of_free=0
  percent_of_all=0
  while true ; do
    id=`expr $id + 1 || :`
    test "$id" || die "$0: Fatal: cannot count part number"

    eval_partition_info $id

    test "$dest_part_device" || break

    test "$dest_part_mnt_point" = "swap" || \
    test "$dest_part_mnt_point" = "md" || \
    is_absolute_dirname dest_part${id}_mnt_point

    # check if mnt_points and devices are unique
    if test "$dest_part_mnt_point" != "swap" && test "$dest_part_mnt_point" != "md" ; then
      for i in $all_mnt_points; do
	if test "$dest_part_mnt_point" = $i; then error dest_part${id}_mnt_point "`nls "there is a %s partition already" "$dest_part_mnt_point"`" ; fi
      done
    fi
    # TODO: only if action=use_existing
    #for i in $all_devices; do
	#if test "$dest_part_device" = $i; then error dest_part${id}_device "partition device $dest_part_device already used" ; fi
    #done
    all_mnt_points="$all_mnt_points $dest_part_mnt_point"
    all_devices="$all_devices $dest_part_device "
   
    if echo $dest_part_device | grep -q 'raid[0-9l]' ; then
      check_raid_dev dest_part${id}_device $dest_part_device
      # little cheat... we don't need to specify size here...
      dest_part_size=1
      eval dest_part${id}_size=1
    else
      if echo $dest_part_device | grep -q '/dev/\(ida\|rd\|cciss\)/' ; then
      	dev=`echo $dest_part_device | sed -e 's@\(/dev/\(ida\|rd\|cciss\)/c[0-9]d[0-9][0-9]*\).*@\1@' || :`
      elif echo $dest_part_device | grep -q '/dev/ataraid/' ; then
	dev=`echo $dest_part_device | sed -e 's@\(/dev/ataraid/d[0-9][0-9]*\).*@\1@' || :`
      else
        dev=`echo $dest_part_device | sed -e 's/[0-9]*$//' || :`
      fi
      action_for_this=
      actions="$dest_devices_actions"
      for i in $dest_devices ; do
        action=`list_car $actions`
        actions=`list_cdr $actions`
  
        if [ "X$dev" = "X$i" ] ; then
          action_for_this=$action
          break
        fi
      done
  
      if test -z "$action_for_this"; then
        error dest_part${id}_device "`nls "missing disk for partition %s - no %s in dest_sevices" "$dest_part_device" "$dev"`"
      fi

      # we can allow empty size in this case...
      if [ $action_for_this = use_existing ] && [ "$dest_part_size" = "" ] ; then
        dest_part_size=1
	eval dest_part${id}_size=1
      fi
    fi

    is_not_list dest_part${id}_options
    
    is_not_empty dest_part${id}_size
    echo $dest_part_size | grep -q '^[0-9]\+$' || \
    echo $dest_part_size | grep -q '^[0-9]\+% of all$' || \
    echo $dest_part_size | grep -q '^[0-9]\+% of free$' || \
    echo $dest_part_size | grep -q '^[0-9]\+%[af]' || {
      error dest_part${id}_size "$(nls "bad size")"
    }
   
    if echo $dest_part_size | grep -q '%f'; then 
	percent=`echo $dest_part_size | sed 's/%.*//'`
	test $percent -le 100 || error dest_part${id}_size "`nls "cannot specify more than 100%"`"
	percent_of_free=`expr $percent_of_free + $percent`
	test $percent_of_free -le 100 || error dest_part${id}_size "`nls "more than 100% free disk space requested"`"
    elif echo $dest_part_size | grep -q '%a'; then 
	percent=`echo $dest_part_size | sed 's/%.*//'`
	test $percent -le 100 || error dest_part${id}_size "`nls "cannot specify more than 100%"`"
	percent_of_all=`expr $percent_of_all + $percent`
	test $percent_of_all -le 100 || error dest_part${id}_size "`nls "more than 100% all disk space requested"`"
    fi

    [ "x$dest_part_format_partition" = "xyes" ] || \
    [ "x$dest_part_format_partition" = "xno" ] || {
      error dest_part${id}_format_partition "`nls "shall be yes or no"`"
    }

    case $dest_part_filesystem in 
    ext2 | reiserfs | jfs | ext3 | xfs)
      : ok
      ;;
    swap )
      if [ "$dest_part_mnt_point" != "swap" ] ; then
        error dest_part${id}_mnt_point "`nls "has to be 'swap', for swap partition"`"
      fi
      ;;
    md )
      if [ "$dest_part_mnt_point" != "md" ] ; then
        error dest_part${id}_mnt_point "`nls "has to be 'md', for md partition"`"
      fi
      ;;
    vfat | msdos )
      if [ "x$dest_part_format_partition" = "xyes" ] ; then
        error dest_part${id}_format_partition "$(nls "can't format fat partitions")"
      fi
      ;;
    *)
      error dest_part${id}_filesystem "`nls "unsupported filesystem %s" "'$dest_part_filesystem'"`"
    esac

    [ "$dest_part_mnt_point" != "/" ] || have_root=yes || :
    [ "$dest_part_mnt_point" != "swap" ] || have_swap=yes || :
  done
    
  # this doesn't apply to any variable..
  [ "$have_root" != no ] || error dest_devices "`nls "you don't have / partition set"`"
  [ "$have_swap" != no ] || warning dest_devices "`nls "you should have swap partition set"`"
}

check_dest () {
  local dev actions action

  is_not_empty dest_devices

  actions="$dest_devices_actions"
  for dev in $dest_devices ; do
    action=`list_car $actions`
    actions=`list_cdr $actions`

    case $action in
    make_new | use_existing)
    	: ok
	;;
    "") 
	error dest_devices_actions "`nls "every device in dest_devices list must have it's action"`"
	;;
    *)
    	error dest_devices_actions "`nls "bad action %s for %s" "'$action'" "$dev"`"
    esac
   
    is_disk $dev dest_devices
    case $dev in 
    /dev/sd[a-h] )
	is_not_empty scsi_hostadapters
	;;
    esac
  done
  
  if test "$actions"; then error dest_devices_actions "`nls "too many actions"`"; fi
  
  check_parts
}

check_pkgs () {
  case "$pkgs_installer" in 
    poldek) : ;;
    wuch) error pkgs_installer "$(nls "wuch not implemented, sorry!")" ;;
    *) error pkgs_installer "$(nls "only poldek supported now")" ;;
  esac

  case "$pkgs_install_docs" in
    yes | no )
      : ok
      ;;
    * )
      error pkgs_install_docs "$(nls 'should be yes or no')"
      ;;
  esac

  case "$pkgs_cpus" in
    [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | auto )
      : ok
      ;;
    * )
      error pkgs_cpus "$(nls 'should be number or auto')"
      ;;
  esac

  if echo "$pkgs_install_langs" | \
     grep -q '^\(\(all\)\|\(\([a-z][a-z]\(_[A-Z][A-Z]\)\?:\)*[a-z][a-z]\(_[A-Z][A-Z]\)\?\)\)$' ; then
    : ok
  else
    error pkgs_install_langs \
    	"$(nls 'should be colon separated list of locales (like "%s") or "%s"' \
		"pl:pl_PL:en:en_US" "all")"
  fi
}

check_boot () {
  case "$boot_loader" in
    yaboot )
      if [ "$arch" != ppc ] ; then
        error boot_loader "$(nls "yaboot supported only on powerpc")"
      fi 
      ;;
    lilo )
      if [ "$arch" != ia32 ] ; then
        error boot_loader "$(nls "lilo supported only on ia32")"
      fi 
      ;;
    # rc-boot is also only supported on ia32, but this might change soon
    rc-boot | none | "" ) : ;;
    grub) error boot_loader "$(nls "select rc-boot to use grub")";;
    *) error boot_loader "`nls "can be %s or empty" "'lilo', 'rc-boot', 'none'"`" ;;
  esac

  case "$boot_loader_device" in
    auto )
      : ok
      ;;
    * )
      is_disk_or_part "$boot_loader_device" boot_loader_device
      ;;
  esac

  for entry in $boot_loader_other ; do
    eval $(parse_boot_loader_entry $entry)
    case $img_os in
      linux | bsd | dos )
        : ok
        ;;
      * )
        error boot_loader_other "$(nls "evil os")"
    esac
    is_disk_or_part "$img_root" boot_loader_other
    if test "$img_kernel" ; then
      is_dirname boot_loader_other "$img_kernel"
    fi
    if test "$img_initrd" ; then
      is_dirname boot_loader_other "$img_initrd"
    fi
    if echo $img_label | grep -q '^[A-Za-z_][A-Za-z0-9_-]*$' ; then
      : ok
    else
      error boot_loader_other "$(nls "evil label: '%s'" "$img_label")"
    fi
  done
}

check_pcmcia () {
    is_not_list pcmcia_controller
}

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

find_config_paths $@
load_config

if test "x`basename $0 || :`" = "xinstaller-validate-draft"; then 
  draft=1
elif test "x`basename $0 || :`" = "xinstaller-validate-nonstop"; then
  bail_on_error=no
elif test "x`basename $0 || :`" = "xinstaller-validate-source"; then
  # validate source (and net) parts only
  source_only=yes
fi

check_pcmcia
# net has to be after source
check_source
check_net
if test "$source_only" != "yes"; then
    check_dest
    check_pkgs
    check_boot
fi

if [ "$was_error" = yes ] ; then
    nls "Validation"
    echo -n ' '
    nls "finished with errors"
    echo
    exit 2
elif [ "$was_warning" = yes ] ; then
    nls "Validation"
    echo -n ' '
    nls "complete, config is OK, except some warnings"
    echo
    if [ "$warnings_fatal" = yes ] ; then
        exit 3
    else
        exit 0
    fi
else 
    nls "Validation"
    echo -n ' '
    nls "complete, config is OK"
    echo
    exit 0
fi

# vim:ft=sh
