1 | # $Id$
|
---|
2 |
|
---|
3 | #----------------------------#
|
---|
4 | validate_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 | "sparcv8") [[ "${TARGET}" = "sparc-unknown-linux-gnu" ]] && return
|
---|
38 | ;;
|
---|
39 | "x86_64-64") [[ "${TARGET}" = "x86_64-unknown-linux-gnu" ]] && return
|
---|
40 | ;;
|
---|
41 | "mips64-64") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] && return
|
---|
42 | [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] && return
|
---|
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 | ;;
|
---|
51 | "mips64") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] &&
|
---|
52 | [[ "${TARGET32}" = "mipsel-unknown-linux-gnu" ]] && return
|
---|
53 |
|
---|
54 | [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] &&
|
---|
55 | [[ "${TARGET32}" = "mips-unknown-linux-gnu" ]] && return
|
---|
56 | ;;
|
---|
57 | "sparc64") [[ "${TARGET}" = "sparc64-unknown-linux-gnu" ]] &&
|
---|
58 | [[ "${TARGET32}" = "sparcv9-unknown-linux-gnu" ]] && return
|
---|
59 | ;;
|
---|
60 | "ppc64") [[ "${TARGET}" = "powerpc64-unknown-linux-gnu" ]] &&
|
---|
61 | [[ "${TARGET32}" = "powerpc-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 | #----------------------------#
|
---|
73 | validate_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,blfs)
|
---|
82 | modifies: none
|
---|
83 | returns: nothing
|
---|
84 | on error: write text to console and dies
|
---|
85 | on success: write text to console and returns
|
---|
86 | inline_doc
|
---|
87 |
|
---|
88 | # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
|
---|
89 | local -r blfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG DEPEND TEST"
|
---|
90 | local -r hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE MODEL GRSECURITY_HOST TEST COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG KEYMAP PAGE TIMEZONE LANG LC_ALL"
|
---|
91 | local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE METHOD ARCH TARGET TEST COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
|
---|
92 | local -r lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG VIMLANG PAGE TIMEZONE LANG"
|
---|
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 |
|
---|
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_against_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 [[ ! "$1" =~ "x${!config_param}x" ]] ; then
|
---|
115 | # parameter value entered is no good
|
---|
116 | write_error_and_die
|
---|
117 | fi
|
---|
118 | }
|
---|
119 |
|
---|
120 | validate_file() {
|
---|
121 | # For parameters ending with a '+' failure causes a warning message only
|
---|
122 | echo -n "`eval echo $PARAM_VALS`"
|
---|
123 | while test $# -gt 0 ; do
|
---|
124 | case $1 in
|
---|
125 | # Failures caused program exit
|
---|
126 | "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
|
---|
127 | "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
|
---|
128 | "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
|
---|
129 | "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
|
---|
130 | "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
|
---|
131 | "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
|
---|
132 | # Warning messages only
|
---|
133 | "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
|
---|
134 | esac
|
---|
135 | shift 1
|
---|
136 | done
|
---|
137 | echo
|
---|
138 | }
|
---|
139 |
|
---|
140 | validate_dir() {
|
---|
141 | # For parameters ending with a '+' failure causes a warning message only
|
---|
142 | echo -n "`eval echo $PARAM_VALS`"
|
---|
143 | while test $# -gt 0 ; do
|
---|
144 | case $1 in
|
---|
145 | "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
|
---|
146 | "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
|
---|
147 | "-w") if [[ ! -w "${!config_param}" ]]; then
|
---|
148 | echo "${nl_}${DD_BORDER}"
|
---|
149 | echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
|
---|
150 | echo "${tab_}${BOLD}${!config_param}${OFF}"
|
---|
151 | echo "${DD_BORDER}${nl_}"
|
---|
152 | exit 1
|
---|
153 | fi ;;
|
---|
154 | # Warnings only
|
---|
155 | "-w+") if [[ ! -w "${!config_param}" ]]; then
|
---|
156 | echo "${nl_}${DD_BORDER}"
|
---|
157 | echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
|
---|
158 | echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
|
---|
159 | echo "${DD_BORDER}"
|
---|
160 | fi ;;
|
---|
161 | "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
|
---|
162 | esac
|
---|
163 | shift 1
|
---|
164 | done
|
---|
165 | echo
|
---|
166 | }
|
---|
167 |
|
---|
168 | set +e
|
---|
169 | PARAM_GROUP=${PROGNAME}_PARAM_LIST
|
---|
170 | for config_param in ${!PARAM_GROUP}; do
|
---|
171 | # This is a tricky little piece of code.. executes a cmd string.
|
---|
172 | case $config_param in
|
---|
173 | BUILDDIR) # We cannot have an <empty> or </> root mount point
|
---|
174 | echo -e "`eval echo $PARAM_VALS`"
|
---|
175 | [[ "xx x/x" =~ "x${!config_param}x" ]] &&
|
---|
176 | write_error_and_die
|
---|
177 | ;;
|
---|
178 | TIMEZONE) ;;
|
---|
179 |
|
---|
180 | # Validate general parameters..
|
---|
181 | HPKG) validate_against_str "x0x x1x" ;;
|
---|
182 | RUNMAKE) validate_against_str "x0x x1x" ;;
|
---|
183 | COMPARE) if [[ ! "$COMPARE" = "1" ]]; then
|
---|
184 | validate_against_str "x0x x1x"
|
---|
185 | else
|
---|
186 | if [[ ! "${RUN_ICA}" = "1" ]] && [[ ! "${RUN_FARCE}" = "1" ]]; then
|
---|
187 | echo "${nl_}${DD_BORDER}"
|
---|
188 | echo "You have elected to analyse your build but have failed to select a tool." >&2
|
---|
189 | 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
|
---|
190 | echo "${DD_BORDER}${nl_}"
|
---|
191 | exit 1
|
---|
192 | fi
|
---|
193 | fi ;;
|
---|
194 | RUN_ICA) [[ "$COMPARE" = "1" ]] && validate_against_str "x0x x1x" ;;
|
---|
195 | RUN_FARCE) [[ "$COMPARE" = "1" ]] && validate_against_str "x0x x1x" ;;
|
---|
196 | ITERATIONS) [[ "$COMPARE" = "1" ]] && validate_against_str "x2x x3x x4x x5x" ;;
|
---|
197 | TEST) validate_against_str "x0x x1x x2x x3x" ;;
|
---|
198 | STRIP) validate_against_str "x0x x1x" ;;
|
---|
199 | VIMLANG) validate_against_str "x0x x1x" ;;
|
---|
200 | DEPEND) validate_against_str "x0x x1x x2x" ;;
|
---|
201 | MODEL) validate_against_str "xglibcx xuclibcx" ;;
|
---|
202 | PAGE) validate_against_str "xletterx xA4x" ;;
|
---|
203 | METHOD) validate_against_str "xchrootx xbootx" ;;
|
---|
204 | ARCH) validate_against_str "xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ;;
|
---|
205 | TARGET) validate_target ;;
|
---|
206 | GRSECURITY_HOST) validate_against_str "x0x x1x" ;;
|
---|
207 |
|
---|
208 | # Validate directories, testable states:
|
---|
209 | # fatal -z -d -w,
|
---|
210 | # warning -z+ -w+
|
---|
211 | SRC_ARCHIVE) validate_dir -z+ -d -w+ ;;
|
---|
212 |
|
---|
213 | # Validate files, testable states:
|
---|
214 | # fatal -z -e -s -w -x -r,
|
---|
215 | # warning -z+
|
---|
216 | FSTAB) validate_file -z+ -e -s ;;
|
---|
217 | CONFIG) validate_file -z+ -e -s ;;
|
---|
218 | BOOK) [[ "${WC}" = 1 ]] && validate_file -z -e -s ;;
|
---|
219 | BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
|
---|
220 |
|
---|
221 | # Treatment of 'special' parameters
|
---|
222 | LANG | \
|
---|
223 | LC_ALL) # See it the locale values exist on this machine
|
---|
224 | echo -n "`eval echo $PARAM_VALS`"
|
---|
225 | [[ -z "${!config_param}" ]] &&
|
---|
226 | echo " -- Variable $config_param cannot be empty!" &&
|
---|
227 | write_error_and_die
|
---|
228 | [[ ! "`locale -a | grep -c ${!config_param}`" > 0 ]] &&
|
---|
229 | write_error_and_die
|
---|
230 | echo
|
---|
231 | ;;
|
---|
232 | KEYMAP) [[ ! "${!config_param}" = "none" ]] &&
|
---|
233 | KEYMAP="/usr/share/kbd/keymaps/${KEYMAP}" &&
|
---|
234 | validate_file -z -e -s
|
---|
235 | ;;
|
---|
236 | esac
|
---|
237 | done
|
---|
238 | set -e
|
---|
239 | echo "$tab_***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***"
|
---|
240 | }
|
---|