source: common/func_validate_configs.sh@ 6a14368

experimental
Last change on this file since 6a14368 was 4612459, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Adding farce to config options.

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