1 | # $Id$
|
---|
2 |
|
---|
3 | #----------------------------#
|
---|
4 | validate_config() { # Are the config values sane (within reason)
|
---|
5 | #----------------------------#
|
---|
6 | : <<inline_doc
|
---|
7 | Validates the configuration parameters. The global var PROGNAME selects the
|
---|
8 | parameter list.
|
---|
9 |
|
---|
10 | input vars: $1 0/1 0=quiet, 1=verbose output
|
---|
11 | externals: color constants
|
---|
12 | PROGNAME (lfs,clfs,hlfs,blfs)
|
---|
13 | modifies: none
|
---|
14 | returns: nothing
|
---|
15 | on error: write text to console and dies
|
---|
16 | on success: write text to console and returns
|
---|
17 | inline_doc
|
---|
18 |
|
---|
19 | local -r lfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP FSTAB CONFIG"
|
---|
20 | local -r blfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE TEST LANG DEPEND"
|
---|
21 | local -r hlfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP FSTAB CONFIG MODEL GRSECURITY_HOST"
|
---|
22 | local -r clfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP ARCH FSTAB CONFIG BOOT_CONFIG METHOD"
|
---|
23 |
|
---|
24 | 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}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
|
---|
25 | local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
26 |
|
---|
27 | local PARAM_LIST=
|
---|
28 |
|
---|
29 | local config_param
|
---|
30 | local validation_str
|
---|
31 | local verbose=$1
|
---|
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 | validate_str() {
|
---|
41 | # This is the 'regexp' test available in bash-3.0..
|
---|
42 | # using it as a poor man's test for substring
|
---|
43 | [[ $verbose = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
|
---|
44 | if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
|
---|
45 | # parameter value entered is no good
|
---|
46 | write_error_and_die
|
---|
47 | fi
|
---|
48 | }
|
---|
49 |
|
---|
50 | set +e
|
---|
51 | for PARAM_GROUP in ${PROGNAME}_PARAM_LIST; do
|
---|
52 | for config_param in ${!PARAM_GROUP}; do
|
---|
53 | # This is a tricky little piece of code.. executes a cmd string.
|
---|
54 | case $config_param in
|
---|
55 | BUILDDIR) # We cannot have an <empty> or </> root mount point
|
---|
56 | [[ $verbose = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
|
---|
57 | if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
|
---|
58 | write_error_and_die
|
---|
59 | fi
|
---|
60 | continue ;;
|
---|
61 | TIMEZONE) continue;;
|
---|
62 | MKFILE) continue;;
|
---|
63 | HPKG) validation_str="x0x x1x"; validate_str; continue ;;
|
---|
64 | RUNMAKE) validation_str="x0x x1x"; validate_str; continue ;;
|
---|
65 | TEST) validation_str="x0x x1x x2x x3x"; validate_str; continue ;;
|
---|
66 | STRIP) validation_str="x0x x1x"; validate_str; continue ;;
|
---|
67 | VIMLANG) validation_str="x0x x1x"; validate_str; continue ;;
|
---|
68 | DEPEND) validation_str="x0x x1x x2x"; validate_str; continue ;;
|
---|
69 | MODEL) validation_str="xglibcx xuclibcx"; validate_str; continue ;;
|
---|
70 | PAGE) validation_str="xletterx xA4x"; validate_str; continue ;;
|
---|
71 | GRSECURITY_HOST) validation_str="x0x x1x"; validate_str; continue ;;
|
---|
72 | METHOD) validation_str="xchrootx xbootx"; validate_str; continue ;;
|
---|
73 | ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax"; validate_str; continue ;;
|
---|
74 | esac
|
---|
75 |
|
---|
76 |
|
---|
77 | if [[ "${config_param}" = "LC_ALL" ]]; then
|
---|
78 | [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
79 | [[ -z "${!config_param}" ]] && continue
|
---|
80 | # See it the locale values exist on this machine
|
---|
81 | if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then
|
---|
82 | continue
|
---|
83 | else # If you make it this far then there is a problem
|
---|
84 | write_error_and_die
|
---|
85 | fi
|
---|
86 | fi
|
---|
87 |
|
---|
88 | if [[ "${config_param}" = "LANG" ]]; then
|
---|
89 | [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
90 | [[ -z "${!config_param}" ]] && continue
|
---|
91 | # See it the locale values exist on this machine
|
---|
92 | if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then
|
---|
93 | continue
|
---|
94 | else # If you make it this far then there is a problem
|
---|
95 | write_error_and_die
|
---|
96 | fi
|
---|
97 | fi
|
---|
98 |
|
---|
99 |
|
---|
100 | if [[ "${config_param}" = "KEYMAP" ]]; then
|
---|
101 | [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
102 | [[ "${!config_param}" = "none" ]] && continue
|
---|
103 | if [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] &&
|
---|
104 | [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]]; then
|
---|
105 | continue
|
---|
106 | else
|
---|
107 | write_error_and_die
|
---|
108 | fi
|
---|
109 | fi
|
---|
110 |
|
---|
111 | if [[ "${config_param}" = "SRC_ARCHIVE" ]]; then
|
---|
112 | [[ $verbose = "1" ]] && echo -n "`eval echo $PARAM_VALS`"
|
---|
113 | if [ ! -z ${SRC_ARCHIVE} ]; then
|
---|
114 | if [ ! -d ${SRC_ARCHIVE} ]; then
|
---|
115 | echo " -- is NOT a directory"
|
---|
116 | write_error_and_die
|
---|
117 | fi
|
---|
118 | if [ ! -w ${SRC_ARCHIVE} ]; then
|
---|
119 | 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"
|
---|
120 | fi
|
---|
121 | fi
|
---|
122 | echo
|
---|
123 | continue
|
---|
124 | fi
|
---|
125 |
|
---|
126 | if [[ "${config_param}" = "FSTAB" ]]; then
|
---|
127 | [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
128 | [[ -z "${!config_param}" ]] && continue
|
---|
129 | if [[ -e "${!config_param}" ]] &&
|
---|
130 | [[ -s "${!config_param}" ]]; then
|
---|
131 | continue
|
---|
132 | else
|
---|
133 | write_error_and_die
|
---|
134 | fi
|
---|
135 | fi
|
---|
136 |
|
---|
137 | if [[ "${config_param}" = "BOOK" ]]; then
|
---|
138 | [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
139 | [[ ! "${WC}" = 1 ]] && continue
|
---|
140 | [[ -z "${!config_param}" ]] && continue
|
---|
141 | if [[ -e "${!config_param}" ]] &&
|
---|
142 | [[ -s "${!config_param}" ]]; then
|
---|
143 | continue
|
---|
144 | else
|
---|
145 | write_error_and_die
|
---|
146 | fi
|
---|
147 | fi
|
---|
148 |
|
---|
149 | if [[ "${config_param}" = "CONFIG" ]]; then
|
---|
150 | [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
151 | [[ -z "${!config_param}" ]] && continue
|
---|
152 | if [[ -e "${!config_param}" ]] &&
|
---|
153 | [[ -s "${!config_param}" ]]; then
|
---|
154 | continue
|
---|
155 | else
|
---|
156 | write_error_and_die
|
---|
157 | fi
|
---|
158 | fi
|
---|
159 |
|
---|
160 | if [[ "${config_param}" = "BOOT_CONFIG" ]]; then
|
---|
161 | if [[ "${METHOD}" = "boot" ]]; then
|
---|
162 | [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
|
---|
163 | # There must be a config file when the build method is 'boot'
|
---|
164 | [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
|
---|
165 | # If you make it this far then there is a problem
|
---|
166 | write_error_and_die
|
---|
167 | fi
|
---|
168 | fi
|
---|
169 | done
|
---|
170 | done
|
---|
171 |
|
---|
172 | set -e
|
---|
173 | echo "$tab_***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***"
|
---|
174 | }
|
---|