source: common/func_validate_configs.sh@ 249a487

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 249a487 was 249a487, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Fixing a test.

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