source: common/func_validate_configs.sh@ eae0c9d

experimental
Last change on this file since eae0c9d was eae0c9d, checked in by George Boudreau <georgeb@…>, 18 years ago

func_validate_config.sh, added display tests for RUN_ICA and RUN_FARCE

  • Property mode set to 100644
File size: 10.7 KB
RevLine 
[c0aeabe]1# $Id$
[3bbf6d5]2
[3c61617]3validate_target() {
4
5 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'
6 local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
7
8 local -r PARAM_VALS='TARGET: ${L_arrow}${BOLD}${TARGET}${OFF}${R_arrow}'
9 local -r PARAM_VALS2='TARGET32: ${L_arrow}${BOLD}${TARGET32}${OFF}${R_arrow}'
10
11 write_error_and_die() {
12 echo -e "\n${DD_BORDER}"
13 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
14 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
15 echo -e "${DD_BORDER}\n"
16 exit 1
17 }
18
19 if [[ ! "${TARGET32}" = "" ]]; then
[3051f95]20 echo -e "`eval echo $PARAM_VALS2`"
[3c61617]21 fi
[3051f95]22 echo -e "`eval echo $PARAM_VALS`"
[3c61617]23
24 case "${ARCH}" in
[3e0594f]25 "x86") [[ "${TARGET}" = "i486-pc-linux-gnu" ]] && return
26 [[ "${TARGET}" = "i586-pc-linux-gnu" ]] && return
27 [[ "${TARGET}" = "i686-pc-linux-gnu" ]] && return
[3c61617]28 ;;
[3e0594f]29 "ppc") [[ "${TARGET}" = "powerpc-unknown-linux-gnu" ]] && return
[3c61617]30 ;;
[3e0594f]31 "mips") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] && return
32 [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] && return
[3c61617]33 ;;
[3e0594f]34 "sparc") [[ "${TARGET}" = "sparcv9-unknown-linux-gnu" ]] && return
[3c61617]35 ;;
[3e0594f]36 "sparcv8") [[ "${TARGET}" = "sparc-unknown-linux-gnu" ]] && return
[3c61617]37 ;;
[3e0594f]38 "x86_64-64") [[ "${TARGET}" = "x86_64-unknown-linux-gnu" ]] && return
[3c61617]39 ;;
40 "mips64-64") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] && return
41 [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] && return
42 ;;
43 "sparc64-64") [[ "${TARGET}" = "sparc64-unknown-linux-gnu" ]] && return
44 ;;
45 "alpha") [[ "${TARGET}" = "alpha-unknown-linux-gnu" ]] && return
46 ;;
47 "x86_64") [[ "${TARGET}" = "x86_64-unknown-linux-gnu" ]] &&
48 [[ "${TARGET32}" = "i686-pc-linux-gnu" ]] && return
49 ;;
50 "mips64") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] &&
51 [[ "${TARGET32}" = "mipsel-unknown-linux-gnu" ]] && return
[ffd482f]52
[3c61617]53 [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] &&
54 [[ "${TARGET32}" = "mips-unknown-linux-gnu" ]] && return
55 ;;
[3e0594f]56 "sparc64") [[ "${TARGET}" = "sparc64-unknown-linux-gnu" ]] &&
57 [[ "${TARGET32}" = "sparcv9-unknown-linux-gnu" ]] && return
[3c61617]58 ;;
[3e0594f]59 "ppc64") [[ "${TARGET}" = "powerpc64-unknown-linux-gnu" ]] &&
60 [[ "${TARGET32}" = "powerpc-unknown-linux-gnu" ]] && return
[3c61617]61 ;;
62 *) write_error_and_die
[ffd482f]63 ;;
[3c61617]64 esac
[3e0594f]65
66 # If you end up here then there was an error SO...
67 write_error_and_die
[3c61617]68}
69
70
[22670f4]71#----------------------------#
72validate_config() { # Are the config values sane (within reason)
73#----------------------------#
74: <<inline_doc
[3bbf6d5]75 Validates the configuration parameters. The global var PROGNAME selects the
[22670f4]76 parameter list.
[3bbf6d5]77
[3051f95]78 input vars: none
[22670f4]79 externals: color constants
80 PROGNAME (lfs,clfs,hlfs,blfs)
81 modifies: none
82 returns: nothing
[4612459]83 on error: write text to console and dies
[22670f4]84 on success: write text to console and returns
85inline_doc
86
[51a0bb1]87 # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
[2f0a537]88 local -r blfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG DEPEND TEST"
[eae0c9d]89 local -r hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE MODEL GRSECURITY_HOST TEST COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG KEYMAP PAGE TIMEZONE LANG LC_ALL"
90 local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE METHOD ARCH TARGET TEST COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
91 local -r lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG VIMLANG PAGE TIMEZONE LANG"
[22670f4]92
[3c61617]93 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
94 local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
[22670f4]95 local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
96
97 local PARAM_LIST=
98 local config_param
99 local validation_str
[ffd482f]100
[22670f4]101 write_error_and_die() {
102 echo -e "\n${DD_BORDER}"
[3c61617]103 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
104 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
[22670f4]105 echo -e "${DD_BORDER}\n"
106 exit 1
107 }
108
[cc82e37]109 validate_str() {
110 # This is the 'regexp' test available in bash-3.0..
111 # using it as a poor man's test for substring
[3051f95]112 echo -e "`eval echo $PARAM_VALS`"
[cc82e37]113 if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
114 # parameter value entered is no good
115 write_error_and_die
116 fi
117 }
[ffd482f]118
[22670f4]119 set +e
[cc82e37]120 for PARAM_GROUP in ${PROGNAME}_PARAM_LIST; do
[22670f4]121 for config_param in ${!PARAM_GROUP}; do
122 # This is a tricky little piece of code.. executes a cmd string.
123 case $config_param in
124 BUILDDIR) # We cannot have an <empty> or </> root mount point
[3051f95]125 echo -e "`eval echo $PARAM_VALS`"
[22670f4]126 if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
127 write_error_and_die
128 fi
129 continue ;;
[2f0a537]130 TIMEZONE) continue;;
131 MKFILE) continue;;
132 HPKG) validation_str="x0x x1x"; validate_str; continue ;;
133 RUNMAKE) validation_str="x0x x1x"; validate_str; continue ;;
[eae0c9d]134
135 COMPARE) if [[ ! "$COMPARE" = "1" ]]; then
136 validation_str="x0x x1x"; validate_str
137 else
138 if [[ ! "${RUN_ICA}" = "1" ]] && [[ ! "${RUN_FARCE}" = "1" ]]; then
139 echo "${nl_}${DD_BORDER}"
140 echo "You have have elected to analyse the build but have failed to select a tool." >&2
141 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
142 echo "${DD_BORDER}${nl_}"
143 exit 1
144 fi
145 fi
146 continue ;;
147 RUN_ICA) [[ "$COMPARE" = "1" ]] && validation_str="x0x x1x" && validate_str
148 continue ;;
149 RUN_FARCE) [[ "$COMPARE" = "1" ]] && validation_str="x0x x1x" && validate_str
150 continue ;;
151 ITERATIONS) [[ "$COMPARE" = "1" ]] && validation_str="x2x x3x x4x x5x" && validate_str
152 continue ;;
153
[2f0a537]154 TEST) validation_str="x0x x1x x2x x3x"; validate_str; continue ;;
155 STRIP) validation_str="x0x x1x"; validate_str; continue ;;
156 VIMLANG) validation_str="x0x x1x"; validate_str; continue ;;
157 DEPEND) validation_str="x0x x1x x2x"; validate_str; continue ;;
158 MODEL) validation_str="xglibcx xuclibcx"; validate_str; continue ;;
159 PAGE) validation_str="xletterx xA4x"; validate_str; continue ;;
160 GRSECURITY_HOST) validation_str="x0x x1x"; validate_str; continue ;;
161 METHOD) validation_str="xchrootx xbootx"; validate_str; continue ;;
162 ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax"; validate_str; continue ;;
163 TARGET) validate_target; continue ;;
[22670f4]164 esac
165
[cc82e37]166 if [[ "${config_param}" = "LC_ALL" ]]; then
[3051f95]167 echo "`eval echo $PARAM_VALS`"
[cc82e37]168 [[ -z "${!config_param}" ]] && continue
169 # See it the locale values exist on this machine
170 if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then
171 continue
172 else # If you make it this far then there is a problem
173 write_error_and_die
174 fi
175 fi
[dbf2c71]176
[cc82e37]177 if [[ "${config_param}" = "LANG" ]]; then
[3051f95]178 echo "`eval echo $PARAM_VALS`"
[cc82e37]179 [[ -z "${!config_param}" ]] && continue
[dbf2c71]180 # See it the locale values exist on this machine
[cc82e37]181 if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then
182 continue
183 else # If you make it this far then there is a problem
184 write_error_and_die
185 fi
[ffd482f]186 fi
[cc82e37]187
188
189 if [[ "${config_param}" = "KEYMAP" ]]; then
[3051f95]190 echo "`eval echo $PARAM_VALS`"
[cc82e37]191 [[ "${!config_param}" = "none" ]] && continue
[ffd482f]192 if [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] &&
[cc82e37]193 [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]]; then
194 continue
195 else
196 write_error_and_die
197 fi
198 fi
199
200 if [[ "${config_param}" = "SRC_ARCHIVE" ]]; then
[3051f95]201 echo -n "`eval echo $PARAM_VALS`"
[cc82e37]202 if [ ! -z ${SRC_ARCHIVE} ]; then
203 if [ ! -d ${SRC_ARCHIVE} ]; then
204 echo " -- is NOT a directory"
[4612459]205 write_error_and_die
[cc82e37]206 fi
207 if [ ! -w ${SRC_ARCHIVE} ]; then
208 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"
209 fi
[dbf2c71]210 fi
[cc82e37]211 echo
212 continue
[dbf2c71]213 fi
[3bbf6d5]214
[cc82e37]215 if [[ "${config_param}" = "FSTAB" ]]; then
[3051f95]216 echo "`eval echo $PARAM_VALS`"
[cc82e37]217 [[ -z "${!config_param}" ]] && continue
218 if [[ -e "${!config_param}" ]] &&
219 [[ -s "${!config_param}" ]]; then
220 continue
221 else
222 write_error_and_die
223 fi
224 fi
[22670f4]225
[cc82e37]226 if [[ "${config_param}" = "BOOK" ]]; then
[3051f95]227 echo "`eval echo $PARAM_VALS`"
[22670f4]228 [[ ! "${WC}" = 1 ]] && continue
[cc82e37]229 [[ -z "${!config_param}" ]] && continue
[ffd482f]230 if [[ -e "${!config_param}" ]] &&
231 [[ -s "${!config_param}" ]]; then
[cc82e37]232 continue
233 else
234 write_error_and_die
235 fi
[22670f4]236 fi
[cc82e37]237
238 if [[ "${config_param}" = "CONFIG" ]]; then
[3051f95]239 echo "`eval echo $PARAM_VALS`"
[cc82e37]240 [[ -z "${!config_param}" ]] && continue
[ffd482f]241 if [[ -e "${!config_param}" ]] &&
[cc82e37]242 [[ -s "${!config_param}" ]]; then
243 continue
244 else
245 write_error_and_die
246 fi
[6eef5ef]247 fi
[cc82e37]248
249 if [[ "${config_param}" = "BOOT_CONFIG" ]]; then
250 if [[ "${METHOD}" = "boot" ]]; then
[3051f95]251 echo "`eval echo $PARAM_VALS`"
[cc82e37]252 # There must be a config file when the build method is 'boot'
253 [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
254 # If you make it this far then there is a problem
255 write_error_and_die
256 fi
257 fi
[51a0bb1]258 done
[22670f4]259 done
[6eef5ef]260
[22670f4]261 set -e
[cc82e37]262 echo "$tab_***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***"
[22670f4]263}
Note: See TracBrowser for help on using the repository browser.