1 |
|
---|
2 | # $Id$
|
---|
3 |
|
---|
4 | #----------------------------#
|
---|
5 | validate_config() { # Are the config values sane (within reason)
|
---|
6 | #----------------------------#
|
---|
7 | : <<inline_doc
|
---|
8 | Validates the configuration parameters. The global var PROGNAME selects the
|
---|
9 | parameter list.
|
---|
10 |
|
---|
11 | input vars: $1 0/1 0=quiet, 1=verbose output
|
---|
12 | externals: color constants
|
---|
13 | PROGNAME (lfs,clfs,hlfs,blfs)
|
---|
14 | modifies: none
|
---|
15 | returns: nothing
|
---|
16 | on error: write text to console and dies
|
---|
17 | on success: write text to console and returns
|
---|
18 | inline_doc
|
---|
19 |
|
---|
20 | local svn_tracking='$Id$'
|
---|
21 | local -r lfs_PARAM_LIST="BUILDDIR HPKG TEST TOOLCHAINTEST STRIP VIMLANG PAGE RUNMAKE"
|
---|
22 | local -r blfs_PARAM_LIST="BUILDDIR TEST DEPEND"
|
---|
23 | local -r hlfs_PARAM_LIST="BUILDDIR HPKG MODEL TEST TOOLCHAINTEST STRIP VIMLANG PAGE GRSECURITY_HOST RUNMAKE TIMEZONE"
|
---|
24 | local -r clfs_PARAM_LIST="ARCH BOOTMINIMAL RUNMAKE MKFILE"
|
---|
25 | local -r global_PARAM_LIST="BUILDDIR HPKG RUNMAKE TEST TOOLCHAINTEST STRIP PAGE TIMEZONE VIMLANG"
|
---|
26 |
|
---|
27 | 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}'
|
---|
28 | local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
29 |
|
---|
30 | local PARAM_LIST=
|
---|
31 |
|
---|
32 | local config_param
|
---|
33 | local validation_str
|
---|
34 |
|
---|
35 | write_error_and_die() {
|
---|
36 | echo -e "\n${DD_BORDER}"
|
---|
37 | echo -e "`eval echo ${ERROR_MSG}`" >&2
|
---|
38 | echo -e "${DD_BORDER}\n"
|
---|
39 | exit 1
|
---|
40 | }
|
---|
41 |
|
---|
42 | set +e
|
---|
43 | for PARAM_GROUP in global_PARAM_LIST ${PROGNAME}_PARAM_LIST; do
|
---|
44 | for config_param in ${!PARAM_GROUP}; do
|
---|
45 | # This is a tricky little piece of code.. executes a cmd string.
|
---|
46 | [[ $1 = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
|
---|
47 | case $config_param in
|
---|
48 | BUILDDIR) # We cannot have an <empty> or </> root mount point
|
---|
49 | if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
|
---|
50 | write_error_and_die
|
---|
51 | fi
|
---|
52 | continue ;;
|
---|
53 | TIMEZONE) continue;;
|
---|
54 | MKFILE) continue;;
|
---|
55 | HPKG) validation_str="x0x x1x" ;;
|
---|
56 | RUNMAKE) validation_str="x0x x1x" ;;
|
---|
57 | TEST) validation_str="x0x x1x" ;;
|
---|
58 | STRIP) validation_str="x0x x1x" ;;
|
---|
59 | VIMLANG) validation_str="x0x x1x" ;;
|
---|
60 | DEPEND) validation_str="x0x x1x x2x" ;;
|
---|
61 | MODEL) validation_str="xglibcx xuclibcx" ;;
|
---|
62 | PAGE) validation_str="xletterx xA4x" ;;
|
---|
63 | ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xalphax" ;;
|
---|
64 | TOOLCHAINTEST) validation_str="x0x x1x" ;;
|
---|
65 | GRSECURITY_HOST) validation_str="x0x x1x" ;;
|
---|
66 | BOOTMINIMAL) validation_str="x0x x1x";;
|
---|
67 | *)
|
---|
68 | echo "WHAT PARAMETER IS THIS.. <<${config_param}>>"
|
---|
69 | exit
|
---|
70 | ;;
|
---|
71 | esac
|
---|
72 | #
|
---|
73 | # This is the 'regexp' test available in bash-3.0..
|
---|
74 | # using it as a poor man's test for substring
|
---|
75 | if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
|
---|
76 | # parameter value entered is no good
|
---|
77 | write_error_and_die
|
---|
78 | fi
|
---|
79 | done # for loop
|
---|
80 |
|
---|
81 | # Not further tests needed on globals
|
---|
82 | if [[ "$PARAM_GROUP" = "global_PARAM_LIST" ]]; then
|
---|
83 | echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} parameters are valid${OFF}"
|
---|
84 | continue
|
---|
85 | fi
|
---|
86 |
|
---|
87 | for config_param in LC_ALL LANG; do
|
---|
88 | [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
89 | [[ -z "${!config_param}" ]] && continue
|
---|
90 | # See it the locale values exist on this machine
|
---|
91 | [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue
|
---|
92 |
|
---|
93 | # If you make it this far then there is a problem
|
---|
94 | write_error_and_die
|
---|
95 | done
|
---|
96 |
|
---|
97 | for config_param in FSTAB CONFIG KEYMAP BOOK; do
|
---|
98 | [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
99 | if [[ $config_param = BOOK ]]; then
|
---|
100 | [[ ! "${WC}" = 1 ]] && continue
|
---|
101 | fi
|
---|
102 | [[ -z "${!config_param}" ]] && continue
|
---|
103 | [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
|
---|
104 |
|
---|
105 | # If you make it this far then there is a problem
|
---|
106 | write_error_and_die
|
---|
107 | done
|
---|
108 | echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} parameters are valid${OFF}"
|
---|
109 | done
|
---|
110 | set -e
|
---|
111 | echo "$tab_***${BOLD}${GREEN}Config parameters look good${OFF}***"
|
---|
112 | }
|
---|