source: common/libs/func_validate_configs.sh@ e0bbc6e

ablfs-more legacy trunk
Last change on this file since e0bbc6e 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
RevLine 
[c14e4b3]1declare -r dotSTR=".................."
2
[877cc6a]3
4#----------------------------#
[45f82718]5validate_config() { # Are the config values sane (within reason)
[877cc6a]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
[350625a]13 PROGNAME (lfs,hlfs,clfs,clfs2,clfs3,blfs)
[877cc6a]14 modifies: none
15 returns: nothing
[45f82718]16 on error: write text to console and dies
[877cc6a]17 on success: write text to console and returns
18inline_doc
19
[350625a]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 \
[de63126]24 SERVER RETRYSRCDOWNLOAD RETRYDOWNLOADCNT DOWNLOADTIMEOUT \
[3158dfa]25 RUNMAKE"
[350625a]26 local -r BUILD_chroot="TEST BOMB_TEST STRIP"
[f546320]27 local -r BUILD_common="FSTAB CONFIG TIMEZONE PAGE LANG INSTALL_LOG"
[f596dde]28 local -r ADVANCED_chroot="COMPARE RUN_ICA ITERATIONS OPTIMIZE"
[350625a]29 local -r ADVANCED_common="REPORT REBUILD_MAKEFILE"
30
31 # BOOK Settings by book
[878a5a0]32 local -r LFS_book="$BOOK_common INITSYS BLFS_TOOL"
[6d5844c]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=""
[d035526]36 local -r HLFS_book="$BOOK_common BLFS_TOOL MODEL KERNEL GRSECURITY_HOST $HLFS_added"
[350625a]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
[085435e]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"
[350625a]47
[945ccaa]48 # System Settings by book (only LFS for now)
[3b43e17b]49 local -r LFS_system="HOSTNAME INTERFACE IP_ADDR GATEWAY PREFIX BROADCAST DOMAIN DNS1 DNS2 FONT KEYMAP LOCAL LOG_LEVEL"
[945ccaa]50
[350625a]51 # Full list of books settings
[52cced4]52 local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $LFS_system $ADVANCED_chroot N_PARALLEL REALSBU SAVE_CH5 $ADVANCED_common"
[350625a]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"
[854854e]57# local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
[877cc6a]58
[854854e]59 # Additional variables
60 local -r blfs_tool_PARAM_LIST="\
61 BLFS_TREE BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
[f1fcb6b]62 DEP_LIBXML DEP_LIBXSLT DEP_DBXML DEP_LYNX DEP_SUDO DEP_WGET \
[dfab075]63 DEP_GIT DEP_GPM"
[53f291f]64 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
[4965fa8]65
[350625a]66 # Internal variables
[877cc6a]67 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
[4965fa8]68 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
[c14e4b3]69 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
[877cc6a]70
[3e7ceed]71 local PARAM_LIST=
[877cc6a]72 local config_param
73 local validation_str
[45f82718]74 local save_param
[877cc6a]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
[3aa1acd]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
[45f82718]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
[877cc6a]141 set +e
[45f82718]142 PARAM_GROUP=${PROGNAME}_PARAM_LIST
143 for config_param in ${!PARAM_GROUP}; do
144 case $config_param in
[4da2512]145 # Envvars that depend on other settings to be displayed
[de63126]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`" ;;
[52cced4]156 N_PARALLEL) [[ "$OPTIMIZE" -gt "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
[84a3fda]157 REALSBU) [[ "$OPTIMIZE" = "2" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
[4da2512]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
[4965fa8]167 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
[45f82718]168 validate_dir -z -d
169 else
[4da2512]170 echo -e "`eval echo $PARAM_VALS`"
[0210014]171 fi
172 ;;
[4da2512]173 # Validate directories, testable states:
174 # fatal -z -d -w,
175 # warning -z+ -w+
[401f81e]176 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
[4da2512]177 # The build directory/partition MUST exist and be writable by the user
[c7b535b]178 BUILDDIR) validate_dir -z -d
[a96109a]179 [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
[962793a]180 LHOME) validate_dir -z -d ;;
[45f82718]181
[4da2512]182 # Validate files, testable states:
183 # fatal -z -e -s -w -x -r,
184 # warning -z+
[45f82718]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
[5c575e1]189 # Treatment of LANG parameter
190 LANG ) # See it the locale value has been set
[45f82718]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 ;;
[c59f9a0]197
[945ccaa]198 # Treatment of HOSTNAME
199 HOSTNAME) echo -e "`eval echo $PARAM_VALS`"
200 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
201 ;;
202
[3aa1acd]203 # Case of PKGMNGT: two files, packageManager.xml and packInstall.sh
[c67990f]204 # must exist in $PKGMNGTDIR if PKGMNGT='y':
[3aa1acd]205 PKGMNGT) echo -e "`eval echo $PARAM_VALS`"
[c67990f]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
[3aa1acd]225 fi
226 ;;
[350625a]227 # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
228 * ) echo -e "`eval echo $PARAM_VALS`" ;;
229
[45f82718]230 esac
231 done
[4965fa8]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
[53f291f]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
[877cc6a]246 set -e
[21f0a91]247 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
[877cc6a]248}
Note: See TracBrowser for help on using the repository browser.