2006-03-08 20:16:59 +01:00
# $Id$
2006-03-08 20:20:36 +01:00
2006-04-13 18:20:14 +02:00
#----------------------------#
validate_target( ) { #
#----------------------------#
2006-03-29 03:35:15 +02:00
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
2006-04-05 02:36:38 +02:00
"x86" ) [ [ " ${ TARGET } " = "i486-pc-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "i586-pc-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "i686-pc-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
2006-04-05 02:36:38 +02:00
"ppc" ) [ [ " ${ TARGET } " = "powerpc-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
2006-04-05 02:36:38 +02:00
"mips" ) [ [ " ${ TARGET } " = "mipsel-unknown-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "mips-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
2006-04-05 02:36:38 +02:00
"sparc" ) [ [ " ${ TARGET } " = "sparcv9-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
2006-04-05 02:36:38 +02:00
"x86_64-64" ) [ [ " ${ TARGET } " = "x86_64-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
"mips64-64" ) [ [ " ${ TARGET } " = "mipsel-unknown-linux-gnu" ] ] && return
[ [ " ${ TARGET } " = "mips-unknown-linux-gnu" ] ] && return
; ;
"sparc64-64" ) [ [ " ${ TARGET } " = "sparc64-unknown-linux-gnu" ] ] && return
; ;
"alpha" ) [ [ " ${ TARGET } " = "alpha-unknown-linux-gnu" ] ] && return
; ;
"x86_64" ) [ [ " ${ TARGET } " = "x86_64-unknown-linux-gnu" ] ] &&
[ [ " ${ TARGET32 } " = "i686-pc-linux-gnu" ] ] && return
; ;
"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
; ;
2006-04-05 02:36:38 +02:00
"sparc64" ) [ [ " ${ TARGET } " = "sparc64-unknown-linux-gnu" ] ] &&
[ [ " ${ TARGET32 } " = "sparcv9-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
2006-04-05 02:36:38 +02:00
"ppc64" ) [ [ " ${ TARGET } " = "powerpc64-unknown-linux-gnu" ] ] &&
[ [ " ${ TARGET32 } " = "powerpc-unknown-linux-gnu" ] ] && return
2006-03-29 03:35:15 +02:00
; ;
*) write_error_and_die
2006-03-29 19:15:12 +02:00
; ;
2006-03-29 03:35:15 +02:00
esac
2006-04-05 02:36:38 +02:00
# If you end up here then there was an error SO...
write_error_and_die
2006-03-29 03:35:15 +02:00
}
2006-03-08 02:32:16 +01:00
#----------------------------#
2006-04-13 18:20:14 +02:00
validate_config( ) { # Are the config values sane (within reason)
2006-03-08 02:32:16 +01:00
#----------------------------#
: <<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
2006-05-18 20:44:10 +02:00
PROGNAME ( lfs,clfs,hlfs)
2006-03-08 02:32:16 +01:00
modifies: none
returns: nothing
2006-04-09 12:27:06 +02:00
on error: write text to console and dies
2006-03-08 02:32:16 +01:00
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
2006-05-04 00:03:58 +02:00
local -r hlfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG KEYMAP PAGE TIMEZONE LANG LC_ALL"
local -r clfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD ARCH TARGET TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
local -r lfs_PARAM_LIST = "BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS 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-04-13 21:48:56 +02:00
local save_param
2006-04-26 22:24:58 +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-04-13 18:20:14 +02:00
validate_against_str( ) {
2006-03-29 01:36:52 +02:00
# 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-04-13 18:20:14 +02:00
if [ [ ! " $1 " = ~ " x ${ !config_param } x " ] ] ; then
2006-03-29 01:36:52 +02:00
# parameter value entered is no good
write_error_and_die
fi
}
2006-03-29 19:15:12 +02:00
2006-04-13 18:20:14 +02:00
validate_file( ) {
# For parameters ending with a '+' failure causes a warning message only
echo -n " `eval echo $PARAM_VALS ` "
while test $# -gt 0 ; do
case $1 in
# Failures caused program exit
"-z" ) [ [ -z " ${ !config_param } " ] ] && echo " ${ tab_ } <-- NO file name given " && write_error_and_die ; ;
"-e" ) [ [ ! -e " ${ !config_param } " ] ] && echo " ${ tab_ } <-- file does not exist " && write_error_and_die ; ;
"-s" ) [ [ ! -s " ${ !config_param } " ] ] && echo " ${ tab_ } <-- file has zero bytes " && write_error_and_die ; ;
"-r" ) [ [ ! -r " ${ !config_param } " ] ] && echo " ${ tab_ } <-- no read permission " && write_error_and_die ; ;
"-w" ) [ [ ! -w " ${ !config_param } " ] ] && echo " ${ tab_ } <-- no write permission " && write_error_and_die ; ;
"-x" ) [ [ ! -x " ${ !config_param } " ] ] && echo " ${ tab_ } <-- file cannot be executed " && write_error_and_die ; ;
# Warning messages only
"-z+" ) [ [ -z " ${ !config_param } " ] ] && echo && return ; ;
esac
shift 1
done
echo
}
2006-03-29 01:36:52 +02:00
2006-04-13 18:20:14 +02:00
validate_dir( ) {
# For parameters ending with a '+' failure causes a warning message only
echo -n " `eval echo $PARAM_VALS ` "
while test $# -gt 0 ; do
case $1 in
"-z" ) [ [ -z " ${ !config_param } " ] ] && echo " ${ tab_ } NO directory name given " && write_error_and_die ; ;
"-d" ) [ [ ! -d " ${ !config_param } " ] ] && echo " ${ tab_ } This is NOT a directory " && write_error_and_die ; ;
"-w" ) if [ [ ! -w " ${ !config_param } " ] ] ; then
echo " ${ nl_ } ${ DD_BORDER } "
echo " ${ tab_ } ${ RED } You do not have ${ L_arrow } write ${ R_arrow } ${ RED } access to the directory ${ OFF } "
echo " ${ tab_ } ${ BOLD } ${ !config_param } ${ OFF } "
echo " ${ DD_BORDER } ${ nl_ } "
exit 1
fi ; ;
# Warnings only
"-w+" ) if [ [ ! -w " ${ !config_param } " ] ] ; then
echo " ${ nl_ } ${ DD_BORDER } "
echo " ${ tab_ } WARNING-- You do not have ${ L_arrow } write ${ R_arrow } access to the directory ${ OFF } "
echo " ${ tab_ } -- ${ BOLD } ${ !config_param } ${ OFF } "
echo " ${ DD_BORDER } "
fi ; ;
"-z+" ) [ [ -z " ${ !config_param } " ] ] && echo " ${ tab_ } <-- NO directory name given " && return
esac
shift 1
done
echo
}
2006-03-29 01:36:52 +02:00
2006-04-13 18:20:14 +02:00
set +e
PARAM_GROUP = ${ PROGNAME } _PARAM_LIST
for config_param in ${ !PARAM_GROUP } ; do
# This is a tricky little piece of code.. executes a cmd string.
case $config_param in
2006-04-29 17:11:30 +02:00
TIMEZONE) echo -e " `eval echo $PARAM_VALS ` " ; ;
2006-04-13 18:20:14 +02:00
# Validate general parameters..
2006-05-01 13:10:53 +02:00
GETPKG) validate_against_str "x0x x1x" ; ;
2006-04-13 18:20:14 +02:00
RUNMAKE) validate_against_str "x0x x1x" ; ;
2006-04-26 22:24:58 +02:00
REPORT) validate_against_str "x0x x1x"
2006-04-27 20:09:07 +02:00
if [ [ " ${ !config_param } " = "1" ] ] ; then
if [ [ ` type -p bc` ] ] ; then
continue
else
echo -e " ${ BOLD } The bc binary was not found ${ OFF } "
echo -e " The SBU and disk usage report creation will be skiped"
REPORT = 0
continue
fi
2006-04-26 22:24:58 +02:00
fi ; ;
2006-04-13 18:20:14 +02:00
COMPARE) if [ [ ! " $COMPARE " = "1" ] ] ; then
validate_against_str "x0x x1x"
else
if [ [ ! " ${ RUN_ICA } " = "1" ] ] && [ [ ! " ${ RUN_FARCE } " = "1" ] ] ; then
echo " ${ nl_ } ${ DD_BORDER } "
echo "You have elected to analyse your build but have failed to select a tool." >& 2
echo " Edit /common/config and set ${ L_arrow } ${ BOLD } RUN_ICA ${ R_arrow } and/or ${ L_arrow } ${ BOLD } RUN_FARCE ${ R_arrow } to the required values " >& 2
echo " ${ DD_BORDER } ${ nl_ } "
exit 1
fi
fi ; ;
RUN_ICA) [ [ " $COMPARE " = "1" ] ] && validate_against_str "x0x x1x" ; ;
RUN_FARCE) [ [ " $COMPARE " = "1" ] ] && validate_against_str "x0x x1x" ; ;
ITERATIONS) [ [ " $COMPARE " = "1" ] ] && validate_against_str "x2x x3x x4x x5x" ; ;
TEST) validate_against_str "x0x x1x x2x x3x" ; ;
2006-05-05 19:41:56 +02:00
OPTIMIZE) validate_against_str "x0x x1x x2x" ; ;
2006-04-13 18:20:14 +02:00
STRIP) validate_against_str "x0x x1x" ; ;
VIMLANG) validate_against_str "x0x x1x" ; ;
MODEL) validate_against_str "xglibcx xuclibcx" ; ;
PAGE) validate_against_str "xletterx xA4x" ; ;
METHOD) validate_against_str "xchrootx xbootx" ; ;
2006-04-29 16:26:56 +02:00
ARCH) validate_against_str "xx86x xx86_64x xx86_64-64x xsparcx xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ; ;
2006-04-13 18:20:14 +02:00
TARGET) validate_target ; ;
GRSECURITY_HOST) validate_against_str "x0x x1x" ; ;
2006-04-13 20:30:41 +02:00
# BOOK validation. Very ugly, need be fixed
BOOK) if [ [ " ${ WC } " = "1" ] ] ; then
validate_dir -z -d
else
2006-04-29 17:11:30 +02:00
validate_against_str " x ${ PROGNAME } -developmentx "
fi ; ;
2006-04-13 20:30:41 +02:00
2006-04-13 18:20:14 +02:00
# Validate directories, testable states:
# fatal -z -d -w,
# warning -z+ -w+
SRC_ARCHIVE) validate_dir -z+ -d -w+ ; ;
2006-05-16 20:27:02 +02:00
BUILDDIR) # The build directory/partition MUST exist and be writable by the user
validate_dir -z -d -w
[ [ "xx x/x" = ~ " x ${ !config_param } x " ] ] &&
write_error_and_die
; ;
2006-04-13 18:20:14 +02:00
# Validate files, testable states:
# fatal -z -e -s -w -x -r,
# warning -z+
FSTAB) validate_file -z+ -e -s ; ;
CONFIG) validate_file -z+ -e -s ; ;
BOOT_CONFIG) [ [ " ${ METHOD } " = "boot" ] ] && validate_file -z -e -s ; ;
# Treatment of 'special' parameters
LANG | \
LC_ALL) # See it the locale values exist on this machine
echo -n " `eval echo $PARAM_VALS ` "
[ [ -z " ${ !config_param } " ] ] &&
echo " -- Variable $config_param cannot be empty! " &&
write_error_and_die
echo
; ;
2006-04-29 16:16:06 +02:00
KEYMAP) echo " `eval echo $PARAM_VALS ` "
save_param = ${ KEYMAP }
2006-04-13 21:48:56 +02:00
[ [ ! " ${ !config_param } " = "none" ] ] &&
2006-04-13 18:20:14 +02:00
KEYMAP = " /usr/share/kbd/keymaps/ ${ KEYMAP } " &&
validate_file -z -e -s
2006-04-13 21:48:56 +02:00
KEYMAP = ${ save_param }
2006-04-13 18:20:14 +02:00
; ;
esac
2006-03-08 02:32:16 +01:00
done
set -e
2006-05-03 21:35:01 +02:00
echo " ${ nl_ } *** ${ BOLD } ${ GREEN } ${ PARAM_GROUP %%_*T } config parameters look good ${ OFF } *** ${ nl_ } "
2006-03-08 02:32:16 +01:00
}