source: common/func_validate_configs.sh@ 3a27393

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

Updated experimental to current trunk.

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