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