source: common/func_validate_configs.sh@ d3ce173

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since d3ce173 was c14e4b3, checked in by George Boudreau <georgeb@…>, 18 years ago

Cosmetic changes to displaying of parameter settings

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