source: common/func_validate_configs.sh@ 7b6ecc5

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 7b6ecc5 was 53f291f, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Using TRACKING_DIR for CUSTOM_TOOLS.

  • Property mode set to 100644
File size: 8.9 KB
Line 
1# $Id$
2
3declare -r dotSTR=".................."
4
5
6#----------------------------#
7validate_config() { # Are the config values sane (within reason)
8#----------------------------#
9: <<inline_doc
10 Validates the configuration parameters. The global var PROGNAME selects the
11 parameter list.
12
13 input vars: none
14 externals: color constants
15 PROGNAME (lfs,clfs,hlfs)
16 modifies: none
17 returns: nothing
18 on error: write text to console and dies
19 on success: write text to console and returns
20inline_doc
21
22 # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
23 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 PAGE TIMEZONE LANG LC_ALL LUSER LGROUP BLFS_TOOL"
24 local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD ARCH TARGET TARGET32 TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG GETKERNEL VIMLANG PAGE TIMEZONE LANG LUSER LGROUP BLFS_TOOL"
25 local -r clfs2_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE ARCH TARGET OPTIMIZE REPORT STRIP FSTAB CONFIG GETKERNEL VIMLANG PAGE TIMEZONE LANG LUSER LGROUP BLFS_TOOL"
26 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 BLFS_TOOL CUSTOM_TOOLS"
27 local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
28
29 local -r blfs_tool_PARAM_LIST="BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR DEP_LIBXML DEP_LIBXSLT DEP_TIDY DEP_UNZIP DEP_DBXML DEP_DBXSL DEP_LINKS DEP_SUDO DEP_WGET DEP_SVN DEP_GPM"
30 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
31
32 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
33 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
34 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
35
36 local PARAM_LIST=
37 local config_param
38 local validation_str
39 local save_param
40
41 write_error_and_die() {
42 echo -e "\n${DD_BORDER}"
43 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
44 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
45 echo -e "${DD_BORDER}\n"
46 exit 1
47 }
48
49 validate_file() {
50 # For parameters ending with a '+' failure causes a warning message only
51 echo -n "`eval echo $PARAM_VALS`"
52 while test $# -gt 0 ; do
53 case $1 in
54 # Failures caused program exit
55 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
56 "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
57 "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
58 "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
59 "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
60 "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
61 # Warning messages only
62 "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
63 esac
64 shift 1
65 done
66 echo
67 }
68
69 validate_dir() {
70 # For parameters ending with a '+' failure causes a warning message only
71 echo -n "`eval echo $PARAM_VALS`"
72 while test $# -gt 0 ; do
73 case $1 in
74 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
75 "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
76 "-w") if [[ ! -w "${!config_param}" ]]; then
77 echo "${nl_}${DD_BORDER}"
78 echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
79 echo "${tab_}${BOLD}${!config_param}${OFF}"
80 echo "${DD_BORDER}${nl_}"
81 exit 1
82 fi ;;
83 # Warnings only
84 "-w+") if [[ ! -w "${!config_param}" ]]; then
85 echo "${nl_}${DD_BORDER}"
86 echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
87 echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
88 echo "${DD_BORDER}"
89 fi ;;
90 "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
91 esac
92 shift 1
93 done
94 echo
95 }
96
97 set +e
98 PARAM_GROUP=${PROGNAME}_PARAM_LIST
99 for config_param in ${!PARAM_GROUP}; do
100 case $config_param in
101 # Allways display this, if found in ${PROGNAME}_PARAM_LIST
102 GETPKG | \
103 RUNMAKE | \
104 TEST | \
105 OPTIMIZE | \
106 STRIP | \
107 VIMLANG | \
108 MODEL | \
109 METHOD | \
110 ARCH | \
111 TARGET | \
112 GRSECURITY_HOST | \
113 BLFS_TOOL | \
114 CUSTOM_TOOLS | \
115 TIMEZONE | \
116 PAGE) echo -e "`eval echo $PARAM_VALS`" ;;
117
118 # Envvars that depend on other settings to be displayed
119 GETKERNEL ) if [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] ; then
120 [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`"
121 fi ;;
122 COMPARE) [[ ! "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
123 RUN_ICA) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
124 RUN_FARCE) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
125 ITERATIONS) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
126 BOMB_TEST) [[ ! "$TEST" = "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
127 TARGET32) [[ -n "${TARGET32}" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
128
129 # Envars that requires some validation
130 LUSER) echo -e "`eval echo $PARAM_VALS`"
131 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
132 ;;
133 LGROUP) echo -e "`eval echo $PARAM_VALS`"
134 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
135 ;;
136 REPORT) echo -e "`eval echo $PARAM_VALS`"
137 if [[ "${!config_param}" = "y" ]]; then
138 if [[ `type -p bc` ]]; then
139 continue
140 else
141 echo -e " ${BOLD}The bc binary was not found${OFF}"
142 echo -e " The SBU and disk usage report creation will be skiped"
143 REPORT=n
144 continue
145 fi
146 fi ;;
147
148 # BOOK validation. Very ugly, need be fixed
149 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
150 validate_dir -z -d
151 else
152 echo -e "`eval echo $PARAM_VALS`"
153 fi ;;
154
155 # Validate directories, testable states:
156 # fatal -z -d -w,
157 # warning -z+ -w+
158 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
159 # The build directory/partition MUST exist and be writable by the user
160 BUILDDIR) validate_dir -z -d -w
161 [[ "xx x/x" =~ "x${!config_param}x" ]] && write_error_and_die ;;
162
163 # Validate files, testable states:
164 # fatal -z -e -s -w -x -r,
165 # warning -z+
166 FSTAB) validate_file -z+ -e -s ;;
167 CONFIG) validate_file -z+ -e -s ;;
168 BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
169
170 # Treatment of 'special' parameters
171 LANG | \
172 LC_ALL) # See it the locale values exist on this machine
173 echo -n "`eval echo $PARAM_VALS`"
174 [[ -z "${!config_param}" ]] &&
175 echo " -- Variable $config_param cannot be empty!" &&
176 write_error_and_die
177 echo
178 ;;
179
180 # BLFS params.
181 BRANCH_ID | BLFS_ROOT | BLFS_XML ) echo "`eval echo $PARAM_VALS`" ;;
182 TRACKING_DIR ) validate_dir -z -d -w ;;
183
184 esac
185 done
186
187 if [[ "${BLFS_TOOL}" = "y" ]] ; then
188 echo "${nl_} ${BLUE}blfs-tool settings${OFF}"
189 for config_param in ${blfs_tool_PARAM_LIST}; do
190 echo -e "`eval echo $PARAM_VALS`"
191 done
192 fi
193
194 if [[ "${CUSTOM_TOOLS}" = "y" ]] && [[ "${BLFS_TOOL}" = "n" ]] ; then
195 for config_param in ${custom_tool_PARAM_LIST}; do
196 echo -e "`eval echo $PARAM_VALS`"
197 done
198 fi
199
200 set -e
201 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
202}
Note: See TracBrowser for help on using the repository browser.