source: common/libs/func_validate_configs.sh@ f546320

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

Ported INSTALL_LOG support to all books.

  • Property mode set to 100644
File size: 9.0 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,hlfs,clfs,clfs2,clfs3,blfs)
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 # Common settings by Config.in sections and books family
23 local -r BOOK_common="BOOK CUSTOM_TOOLS"
24 local -r BOOK_clfsX="ARCH TARGET"
25 local -r GENERAL_common="LUSER LGROUP LHOME BUILDDIR CLEAN GETPKG SRC_ARCHIVE \
26 SERVER GETKERNEL RUNMAKE"
27 local -r BUILD_chroot="TEST BOMB_TEST STRIP"
28 local -r BUILD_common="FSTAB CONFIG TIMEZONE PAGE LANG INSTALL_LOG"
29 local -r ADVANCED_chroot="COMPARE RUN_ICA RUN_FARCE ITERATIONS OPTIMIZE"
30 local -r ADVANCED_common="REPORT REBUILD_MAKEFILE"
31
32 # BOOK Settings by book
33 local -r LFS_book="$BOOK_common BLFS_TOOL"
34 local -r HLFS_book="$BOOK_common BLFS_TOOL MODEL GRSECURITY_HOST"
35 local -r CLFS_book="$BOOK_common BLFS_TOOL METHOD $BOOK_clfsX TARGET32 BOOT_CONFIG"
36 local -r CLFS2_book="$BOOK_common BLFS_TOOL $BOOK_clfsX"
37 local -r CLFS3_book="$BOOK_common $BOOK_clfsX PLATFORM MIPS_LEVEL"
38
39 # Build Settings by book
40 local -r LFS_build="$BUILD_chroot VIMLANG $BUILD_common"
41 local -r HLFS_build="$BUILD_chroot $BUILD_common LC_ALL"
42 local -r CLFS_build="$BUILD_chroot VIMLANG $BUILD_common"
43 local -r CLFS2_build="STRIP VIMLANG $BUILD_common"
44 local -r CLFS3_build=" $BUILD_common"
45
46 # Full list of books settings
47 local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $ADVANCED_chroot $ADVANCED_common"
48 local -r hlfs_PARAM_LIST="$HLFS_book $GENERAL_common $HLFS_build $ADVANCED_chroot $ADVANCED_common"
49 local -r clfs_PARAM_LIST="$CLFS_book $GENERAL_common $CLFS_build $ADVANCED_chroot $ADVANCED_common"
50 local -r clfs2_PARAM_LIST="$CLFS2_book $GENERAL_common $CLFS2_build $ADVANCED_common"
51 local -r clfs3_PARAM_LIST="$CLFS3_book $GENERAL_common $CLFS3_build $ADVANCED_common"
52 local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
53
54 # Additional variables
55 local -r blfs_tool_PARAM_LIST="BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
56 DEP_LIBXML DEP_LIBXSLT DEP_TIDY DEP_UNZIP \
57 DEP_DBXML DEP_DBXSL DEP_LINKS DEP_SUDO DEP_WGET \
58 DEP_SVN DEP_GPM"
59 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
60
61 # Internal variables
62 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
63 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
64 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
65
66 local PARAM_LIST=
67 local config_param
68 local validation_str
69 local save_param
70
71 write_error_and_die() {
72 echo -e "\n${DD_BORDER}"
73 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
74 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
75 echo -e "${DD_BORDER}\n"
76 exit 1
77 }
78
79 validate_file() {
80 # For parameters ending with a '+' failure causes a warning message only
81 echo -n "`eval echo $PARAM_VALS`"
82 while test $# -gt 0 ; do
83 case $1 in
84 # Failures caused program exit
85 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
86 "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
87 "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
88 "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
89 "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
90 "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
91 # Warning messages only
92 "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
93 esac
94 shift 1
95 done
96 echo
97 }
98
99 validate_dir() {
100 # For parameters ending with a '+' failure causes a warning message only
101 echo -n "`eval echo $PARAM_VALS`"
102 while test $# -gt 0 ; do
103 case $1 in
104 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
105 "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
106 "-w") if [[ ! -w "${!config_param}" ]]; then
107 echo "${nl_}${DD_BORDER}"
108 echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
109 echo "${tab_}${BOLD}${!config_param}${OFF}"
110 echo "${DD_BORDER}${nl_}"
111 exit 1
112 fi ;;
113 # Warnings only
114 "-w+") if [[ ! -w "${!config_param}" ]]; then
115 echo "${nl_}${DD_BORDER}"
116 echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
117 echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
118 echo "${DD_BORDER}"
119 fi ;;
120 "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
121 esac
122 shift 1
123 done
124 echo
125 }
126
127 set +e
128 PARAM_GROUP=${PROGNAME}_PARAM_LIST
129 for config_param in ${!PARAM_GROUP}; do
130 case $config_param in
131 # Envvars that depend on other settings to be displayed
132 GETKERNEL ) if [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] ; then
133 [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`"
134 fi ;;
135 COMPARE) [[ ! "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
136 RUN_ICA) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
137 RUN_FARCE) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
138 ITERATIONS) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
139 BOMB_TEST) [[ ! "$TEST" = "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
140 TARGET32) [[ -n "${TARGET32}" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
141 MIPS_LEVEL) [[ "${ARCH}" = "mips" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
142 SERVER) [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
143
144 # Envars that requires some validation
145 LUSER) echo -e "`eval echo $PARAM_VALS`"
146 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
147 ;;
148 LGROUP) echo -e "`eval echo $PARAM_VALS`"
149 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
150 ;;
151 # BOOK validation. Very ugly, need be fixed
152 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
153 validate_dir -z -d
154 else
155 echo -e "`eval echo $PARAM_VALS`"
156 fi
157 ;;
158 # Validate directories, testable states:
159 # fatal -z -d -w,
160 # warning -z+ -w+
161 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
162 # The build directory/partition MUST exist and be writable by the user
163 BUILDDIR) validate_dir -z -d -w
164 [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
165 LHOME) validate_dir -z -d ;;
166
167 # Validate files, testable states:
168 # fatal -z -e -s -w -x -r,
169 # warning -z+
170 FSTAB) validate_file -z+ -e -s ;;
171 CONFIG) validate_file -z+ -e -s ;;
172 BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
173
174 # Treatment of 'special' parameters
175 LANG | \
176 LC_ALL) # See it the locale values exist on this machine
177 echo -n "`eval echo $PARAM_VALS`"
178 [[ -z "${!config_param}" ]] &&
179 echo " -- Variable $config_param cannot be empty!" &&
180 write_error_and_die
181 echo
182 ;;
183
184 # BLFS params.
185 BRANCH_ID | BLFS_ROOT | BLFS_XML ) echo "`eval echo $PARAM_VALS`" ;;
186 TRACKING_DIR ) validate_dir -z -d -w ;;
187
188 # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
189 * ) echo -e "`eval echo $PARAM_VALS`" ;;
190
191 esac
192 done
193
194 if [[ "${BLFS_TOOL}" = "y" ]] ; then
195 echo "${nl_} ${BLUE}blfs-tool settings${OFF}"
196 for config_param in ${blfs_tool_PARAM_LIST}; do
197 echo -e "`eval echo $PARAM_VALS`"
198 done
199 fi
200
201 if [[ "${CUSTOM_TOOLS}" = "y" ]] && [[ "${BLFS_TOOL}" = "n" ]] ; then
202 for config_param in ${custom_tool_PARAM_LIST}; do
203 echo -e "`eval echo $PARAM_VALS`"
204 done
205 fi
206
207 set -e
208 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
209}
Note: See TracBrowser for help on using the repository browser.