source: common/libs/func_validate_configs.sh@ 978286a

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

Remove legacy: remove everything about HLFS

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