source: common/libs/func_validate_configs.sh@ 1814367

2.4 ablfs-more legacy trunk
Last change on this file since 1814367 was c67990f, checked in by Pierre Labastie <pierre@…>, 8 years ago

Existence of package management files is tested even if PKGMNGT=n. Fix that. Thanks to Michael D.L. for reporting.

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