source: common/libs/func_validate_configs.sh@ 1870b56

ablfs-more legacy trunk
Last change on this file since 1870b56 was fd4a798, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Remove $Id$ comments, they are useless with git

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