source: common/func_validate_configs.sh@ 466b5cc

experimental
Last change on this file since 466b5cc was 3051f95, checked in by George Boudreau <georgeb@…>, 19 years ago

common/func_validate_configs.sh,. removed display trace option, always display config values

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