2006-03-08 20:20:36 +01:00
2006-03-08 20:16:59 +01:00
# $Id$
2006-03-08 20:20:36 +01:00
2006-03-08 02:32:16 +01:00
#----------------------------#
validate_config( ) { # Are the config values sane (within reason)
#----------------------------#
: <<inlin e_doc
2006-03-08 20:20:36 +01:00
Validates the configuration parameters. The global var PROGNAME selects the
2006-03-08 02:32:16 +01:00
parameter list.
2006-03-08 20:20:36 +01:00
2006-03-09 04:38:59 +01:00
input vars: $1 0/1 0 = quiet, 1 = verbose output
2006-03-08 02:32:16 +01:00
externals: color constants
PROGNAME ( lfs,clfs,hlfs,blfs)
modifies: none
returns: nothing
on error: write text to console and dies
on success: write text to console and returns
inline_doc
2006-03-17 21:05:38 +01:00
local -r lfs_PARAM_LIST = "VIMLANG"
2006-03-16 15:48:18 +01:00
local -r blfs_PARAM_LIST = "TEST DEPEND"
2006-03-10 15:27:12 +01:00
local -r hlfs_PARAM_LIST = "MODEL GRSECURITY_HOST"
2006-03-17 21:05:38 +01:00
local -r clfs_PARAM_LIST = "ARCH BOOTMINIMAL VIMLANG"
local -r global_PARAM_LIST = "BUILDDIR HPKG RUNMAKE TEST STRIP PAGE TIMEZONE"
2006-03-08 02:32:16 +01:00
local -r ERROR_MSG = 'The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid, ${nl_}check the config file ${BOLD}${GREEN}\<$PROGNAME.conf\>${OFF}'
local -r PARAM_VALS = '${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
local PARAM_LIST =
local config_param
local validation_str
2006-03-08 20:20:36 +01:00
2006-03-08 02:32:16 +01:00
write_error_and_die( ) {
echo -e " \n ${ DD_BORDER } "
echo -e " `eval echo ${ ERROR_MSG } ` " >& 2
echo -e " ${ DD_BORDER } \n "
exit 1
}
set +e
for PARAM_GROUP in global_PARAM_LIST ${ PROGNAME } _PARAM_LIST; do
for config_param in ${ !PARAM_GROUP } ; do
# This is a tricky little piece of code.. executes a cmd string.
[ [ $1 = "1" ] ] && echo -e " `eval echo $PARAM_VALS ` "
case $config_param in
BUILDDIR) # We cannot have an <empty> or </> root mount point
if [ [ "xx x/x" = ~ " x ${ !config_param } x " ] ] ; then
write_error_and_die
fi
continue ; ;
TIMEZONE) continue ; ;
MKFILE) continue ; ;
HPKG) validation_str = "x0x x1x" ; ;
RUNMAKE) validation_str = "x0x x1x" ; ;
2006-03-10 02:44:55 +01:00
TEST) validation_str = "x0x x1x x2x x3x" ; ;
2006-03-08 02:32:16 +01:00
STRIP) validation_str = "x0x x1x" ; ;
VIMLANG) validation_str = "x0x x1x" ; ;
DEPEND) validation_str = "x0x x1x x2x" ; ;
MODEL) validation_str = "xglibcx xuclibcx" ; ;
PAGE) validation_str = "xletterx xA4x" ; ;
ARCH) validation_str = "xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xalphax" ; ;
GRSECURITY_HOST) validation_str = "x0x x1x" ; ;
BOOTMINIMAL) validation_str = "x0x x1x" ; ;
*)
echo " WHAT PARAMETER IS THIS.. << ${ config_param } >> "
exit
; ;
esac
#
# This is the 'regexp' test available in bash-3.0..
# using it as a poor man's test for substring
if [ [ ! " ${ validation_str } " = ~ " x ${ !config_param } x " ] ] ; then
# parameter value entered is no good
write_error_and_die
fi
done # for loop
2006-03-17 21:05:38 +01:00
2006-03-16 15:48:18 +01:00
# No further tests needed on globals
2006-03-08 02:32:16 +01:00
if [ [ " $PARAM_GROUP " = "global_PARAM_LIST" ] ] ; then
2006-03-16 15:48:18 +01:00
for config_param in LC_ALL LANG; do
[ [ $1 = "1" ] ] && echo " `eval echo $PARAM_VALS ` "
[ [ -z " ${ !config_param } " ] ] && continue
# See it the locale values exist on this machine
[ [ " `locale -a | grep -c ${ !config_param } ` " > 0 ] ] && continue
# If you make it this far then there is a problem
write_error_and_die
done
2006-03-17 21:05:38 +01:00
2006-03-16 15:48:18 +01:00
for config_param in KEYMAP; do
[ [ $1 = "1" ] ] && echo " `eval echo $PARAM_VALS ` "
2006-03-18 12:42:56 +01:00
[ [ " ${ !config_param } " = "none" ] ] && continue
[ [ -e " /usr/share/kbd/keymaps/ ${ !config_param } " ] ] && [ [ -s " /usr/share/kbd/keymaps/ ${ !config_param } " ] ] && continue
2006-03-16 15:48:18 +01:00
# If you make it this far then there is a problem
write_error_and_die
done
2006-03-17 21:05:38 +01:00
# Check out the global param SRC_ARCHIVE
2006-03-16 15:48:18 +01:00
config_param = SRC_ARCHIVE
[ [ $1 = "1" ] ] && echo -n " `eval echo $PARAM_VALS ` "
if [ ! -z ${ SRC_ARCHIVE } ] ; then
if [ ! -d ${ SRC_ARCHIVE } ] ; then
echo " -- is NOT a directory"
write_error_and_die
fi
if [ ! -w ${ SRC_ARCHIVE } ] ; then
echo -n " ${ nl_ } [ ${ BOLD } ${ YELLOW } WARN $OFF ] You do not have <write> access to this directory, ${ nl_ } ${ tab_ } downloaded files can not be saved in this archive "
fi
fi
echo " ${ nl_ } ${ BOLD } ${ GREEN } global parameters are valid ${ OFF } ${ nl_ } "
2006-03-08 02:32:16 +01:00
continue
fi
2006-03-08 20:20:36 +01:00
2006-03-08 02:32:16 +01:00
2006-03-16 15:48:18 +01:00
for config_param in FSTAB CONFIG BOOK; do
2006-03-08 02:32:16 +01:00
[ [ $1 = "1" ] ] && echo " `eval echo $PARAM_VALS ` "
if [ [ $config_param = BOOK ] ] ; then
[ [ ! " ${ WC } " = 1 ] ] && continue
fi
[ [ -z " ${ !config_param } " ] ] && continue
[ [ -e " ${ !config_param } " ] ] && [ [ -s " ${ !config_param } " ] ] && continue
2006-03-08 20:20:36 +01:00
2006-03-08 02:32:16 +01:00
# If you make it this far then there is a problem
write_error_and_die
done
2006-03-16 15:48:18 +01:00
echo " ${ BOLD } ${ GREEN } ${ PARAM_GROUP %%_*T } specific parameters are valid ${ OFF } "
2006-03-08 02:32:16 +01:00
done
set -e
echo " $tab_ *** ${ BOLD } ${ GREEN } Config parameters look good ${ OFF } *** "
}