source: common/libs/func_validate_configs.sh@ 9f89fae

ablfs-more trunk
Last change on this file since 9f89fae was 0fa52f2, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Remove legacy: Remove almost all occurrences of CLFS/clfs

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