source: common/func_validate_configs.sh@ 30737ea8

experimental
Last change on this file since 30737ea8 was f28e4bd, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Ported r2889 from trunk

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