2006-03-08 20:16:59 +01:00
# $Id$
2006-03-08 20:20:36 +01:00
2006-03-29 03:35:15 +02:00
validate_target( ) {
local -r ERROR_MSG_pt1 = 'The variable \"${L_arrow}TARGET${R_arrow}\" value ${L_arrow}${BOLD}${TARGET}${R_arrow} is invalid for the ${L_arrow}${BOLD}${ARCH}${R_arrow} architecture'
local -r ERROR_MSG_pt2 = ' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
local -r PARAM_VALS = 'TARGET: ${L_arrow}${BOLD}${TARGET}${OFF}${R_arrow}'
local -r PARAM_VALS2 = 'TARGET32: ${L_arrow}${BOLD}${TARGET32}${OFF}${R_arrow}'
write_error_and_die( ) {
echo -e " \n ${ DD_BORDER } "
echo -e " `eval echo ${ ERROR_MSG_pt1 } ` " >& 2
echo -e " `eval echo ${ ERROR_MSG_pt2 } ` " >& 2
echo -e " ${ DD_BORDER } \n "
exit 1
}
if [ [ ! " ${ TARGET32 } " = "" ] ] ; then
2006-03-29 21:47:45 +02:00
echo -e " `eval echo $PARAM_VALS2 ` "
2006-03-29 03:35:15 +02:00
fi
2006-03-29 21:47:45 +02:00
echo -e " `eval echo $PARAM_VALS ` "
2006-03-29 03:35:15 +02:00
case " ${ ARCH } " in
"x86" ) [ [ " ${ TARGET } " = "i486-pc-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "i586-pc-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "i686-pc-linux-gnu" ] ] && return
write_error_and_die
; ;
"ppc" ) [ [ " ${ TARGET } " = "powerpc-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"mips" ) [ [ " ${ TARGET } " = "mipsel-unknown-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "mips-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"sparc" ) [ [ " ${ TARGET } " = "sparcv9-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"sparcv8" ) [ [ " ${ TARGET } " = "sparc-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"x86_64-64" ) [ [ " ${ TARGET } " = "x86_64-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"mips64-64" ) [ [ " ${ TARGET } " = "mipsel-unknown-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "mips-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"sparc64-64" ) [ [ " ${ TARGET } " = "sparc64-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"alpha" ) [ [ " ${ TARGET } " = "alpha-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"x86_64" ) [ [ " ${ TARGET } " = "x86_64-unknown-linux-gnu" ] ] &&
[ [ " ${ TARGET32 } " = "i686-pc-linux-gnu" ] ] && return
write_error_and_die
; ;
"mips64" ) [ [ " ${ TARGET } " = "mipsel-unknown-linux-gnu" ] ] &&
[ [ " ${ TARGET32 } " = "mipsel-unknown-linux-gnu" ] ] && return
2006-03-29 19:15:12 +02:00
2006-03-29 03:35:15 +02:00
[ [ " ${ TARGET } " = "mips-unknown-linux-gnu" ] ] &&
[ [ " ${ TARGET32 } " = "mips-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
2006-03-29 19:15:12 +02:00
"sparc64" ) [ [ " ${ TARGET } " = "sparc64-unknown-linux-gnu" ] ] &&
2006-03-29 03:35:15 +02:00
[ [ " ${ TARGET32 } " = "sparcv9-unknown-linux-gnu" ] ] && return
write_error_and_die
; ;
"ppc64" ) [ [ " ${ TARGET } " = "powerpc64-unknown-linux-gnu" ] ] &&
2006-03-29 19:15:12 +02:00
[ [ " ${ TARGET32 } " = "powerpc-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
write_error_and_die
; ;
*) write_error_and_die
2006-03-29 19:15:12 +02:00
; ;
2006-03-29 03:35:15 +02:00
esac
}
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-29 21:47:45 +02:00
input vars: none
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-29 19:57:30 +02:00
# First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
local -r blfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE HPKG DEPEND TEST"
2006-03-29 20:01:12 +02:00
local -r hlfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE MODEL GRSECURITY_HOST TEST STRIP FSTAB CONFIG KEYMAP PAGE TIMEZONE LANG LC_ALL"
2006-03-29 19:57:30 +02:00
local -r clfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE METHOD ARCH TARGET TEST STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
2006-03-29 20:01:12 +02:00
local -r lfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP FSTAB CONFIG VIMLANG PAGE TIMEZONE LANG"
2006-03-08 02:32:16 +01:00
2006-03-29 03:35:15 +02:00
local -r ERROR_MSG_pt1 = 'The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
local -r ERROR_MSG_pt2 = ' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
2006-03-08 02:32:16 +01:00
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-29 19:15:12 +02:00
2006-03-08 02:32:16 +01:00
write_error_and_die( ) {
echo -e " \n ${ DD_BORDER } "
2006-03-29 03:35:15 +02:00
echo -e " `eval echo ${ ERROR_MSG_pt1 } ` " >& 2
echo -e " `eval echo ${ ERROR_MSG_pt2 } ` " >& 2
2006-03-08 02:32:16 +01:00
echo -e " ${ DD_BORDER } \n "
exit 1
}
2006-03-29 01:36:52 +02:00
validate_str( ) {
# This is the 'regexp' test available in bash-3.0..
# using it as a poor man's test for substring
2006-03-29 21:47:45 +02:00
echo -e " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
if [ [ ! " ${ validation_str } " = ~ " x ${ !config_param } x " ] ] ; then
# parameter value entered is no good
write_error_and_die
fi
}
2006-03-29 19:15:12 +02:00
2006-03-08 02:32:16 +01:00
set +e
2006-03-29 01:36:52 +02:00
for PARAM_GROUP in ${ PROGNAME } _PARAM_LIST; do
2006-03-08 02:32:16 +01:00
for config_param in ${ !PARAM_GROUP } ; do
# This is a tricky little piece of code.. executes a cmd string.
case $config_param in
BUILDDIR) # We cannot have an <empty> or </> root mount point
2006-03-29 21:47:45 +02:00
echo -e " `eval echo $PARAM_VALS ` "
2006-03-08 02:32:16 +01:00
if [ [ "xx x/x" = ~ " x ${ !config_param } x " ] ] ; then
write_error_and_die
fi
continue ; ;
TIMEZONE) continue ; ;
2006-03-29 01:36:52 +02:00
MKFILE) continue ; ;
HPKG) validation_str = "x0x x1x" ; validate_str; continue ; ;
RUNMAKE) validation_str = "x0x x1x" ; validate_str; continue ; ;
TEST) validation_str = "x0x x1x x2x x3x" ; validate_str; continue ; ;
STRIP) validation_str = "x0x x1x" ; validate_str; continue ; ;
VIMLANG) validation_str = "x0x x1x" ; validate_str; continue ; ;
DEPEND) validation_str = "x0x x1x x2x" ; validate_str; continue ; ;
MODEL) validation_str = "xglibcx xuclibcx" ; validate_str; continue ; ;
PAGE) validation_str = "xletterx xA4x" ; validate_str; continue ; ;
GRSECURITY_HOST) validation_str = "x0x x1x" ; validate_str; continue ; ;
METHOD) validation_str = "xchrootx xbootx" ; validate_str; continue ; ;
ARCH) validation_str = "xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ; validate_str; continue ; ;
2006-03-29 03:35:15 +02:00
TARGET) validate_target; continue ; ;
2006-03-08 02:32:16 +01:00
esac
2006-03-17 21:05:38 +01:00
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "LC_ALL" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
[ [ -z " ${ !config_param } " ] ] && continue
# See it the locale values exist on this machine
if [ [ " `locale -a | grep -c ${ !config_param } ` " > 0 ] ] ; then
continue
else # If you make it this far then there is a problem
write_error_and_die
fi
fi
2006-03-16 15:48:18 +01:00
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "LANG" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
[ [ -z " ${ !config_param } " ] ] && continue
2006-03-16 15:48:18 +01:00
# See it the locale values exist on this machine
2006-03-29 01:36:52 +02:00
if [ [ " `locale -a | grep -c ${ !config_param } ` " > 0 ] ] ; then
continue
else # If you make it this far then there is a problem
write_error_and_die
fi
2006-03-29 19:15:12 +02:00
fi
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "KEYMAP" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
[ [ " ${ !config_param } " = "none" ] ] && continue
2006-03-29 19:15:12 +02:00
if [ [ -e " /usr/share/kbd/keymaps/ ${ !config_param } " ] ] &&
2006-03-29 01:36:52 +02:00
[ [ -s " /usr/share/kbd/keymaps/ ${ !config_param } " ] ] ; then
continue
else
write_error_and_die
fi
fi
if [ [ " ${ config_param } " = "SRC_ARCHIVE" ] ] ; then
2006-03-29 21:47:45 +02:00
echo -n " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
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
2006-03-16 15:48:18 +01:00
fi
2006-03-29 01:36:52 +02:00
echo
continue
2006-03-16 15:48:18 +01:00
fi
2006-03-08 20:20:36 +01:00
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "FSTAB" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
[ [ -z " ${ !config_param } " ] ] && continue
if [ [ -e " ${ !config_param } " ] ] &&
[ [ -s " ${ !config_param } " ] ] ; then
continue
else
write_error_and_die
fi
fi
2006-03-08 02:32:16 +01:00
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "BOOK" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-08 02:32:16 +01:00
[ [ ! " ${ WC } " = 1 ] ] && continue
2006-03-29 01:36:52 +02:00
[ [ -z " ${ !config_param } " ] ] && continue
2006-03-29 19:15:12 +02:00
if [ [ -e " ${ !config_param } " ] ] &&
[ [ -s " ${ !config_param } " ] ] ; then
2006-03-29 01:36:52 +02:00
continue
else
write_error_and_die
fi
2006-03-08 02:32:16 +01:00
fi
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "CONFIG" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
[ [ -z " ${ !config_param } " ] ] && continue
2006-03-29 19:15:12 +02:00
if [ [ -e " ${ !config_param } " ] ] &&
2006-03-29 01:36:52 +02:00
[ [ -s " ${ !config_param } " ] ] ; then
continue
else
write_error_and_die
fi
2006-03-22 00:25:40 +01:00
fi
2006-03-29 01:36:52 +02:00
if [ [ " ${ config_param } " = "BOOT_CONFIG" ] ] ; then
if [ [ " ${ METHOD } " = "boot" ] ] ; then
2006-03-29 21:47:45 +02:00
echo " `eval echo $PARAM_VALS ` "
2006-03-29 01:36:52 +02:00
# There must be a config file when the build method is 'boot'
[ [ -e " ${ !config_param } " ] ] && [ [ -s " ${ !config_param } " ] ] && continue
# If you make it this far then there is a problem
write_error_and_die
fi
fi
2006-03-29 19:57:30 +02:00
done
2006-03-08 02:32:16 +01:00
done
2006-03-22 00:25:40 +01:00
2006-03-08 02:32:16 +01:00
set -e
2006-03-29 01:36:52 +02:00
echo " $tab_ *** ${ BOLD } ${ GREEN } ${ PARAM_GROUP %%_*T } config parameters look good ${ OFF } *** "
2006-03-08 02:32:16 +01:00
}