source: common/libs/func_validate_configs.sh@ 0fa52f2

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

Remove legacy: Remove almost all occurrences of CLFS/clfs

  • Property mode set to 100644
File size: 9.9 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 only as of February 28th, 2022)
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 GENERAL_common="LUSER LGROUP LHOME BUILDDIR CLEAN GETPKG SRC_ARCHIVE \
23 SERVER RETRYSRCDOWNLOAD RETRYDOWNLOADCNT DOWNLOADTIMEOUT \
24 RUNMAKE"
25 local -r BUILD_chroot="TEST BOMB_TEST STRIP"
26 local -r BUILD_common="FSTAB CONFIG TIMEZONE PAGE LANG INSTALL_LOG"
27 local -r ADVANCED_chroot="COMPARE RUN_ICA ITERATIONS OPTIMIZE"
28 local -r ADVANCED_common="REPORT REBUILD_MAKEFILE"
29
30 # BOOK Settings by book
31 local -r LFS_book="$BOOK_common INITSYS BLFS_TOOL"
32
33 # Build Settings by book
34 local -r LFS_build="$BUILD_chroot NCURSES5 DEL_LA_FILES $BUILD_common PKGMNGT FULL_LOCALE WRAP_INSTALL"
35
36 # System Settings by book
37 local -r LFS_system="HOSTNAME INTERFACE IP_ADDR GATEWAY PREFIX BROADCAST DOMAIN DNS1 DNS2 FONT KEYMAP LOCAL LOG_LEVEL"
38
39 # Full list of books settings
40 local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $LFS_system $ADVANCED_chroot N_PARALLEL REALSBU SAVE_CH5 $ADVANCED_common"
41# local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
42
43 # Additional variables
44 local -r blfs_tool_PARAM_LIST="\
45 BLFS_TREE BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
46 DEP_LIBXML DEP_LIBXSLT DEP_DBXML DEP_LYNX DEP_SUDO DEP_WGET \
47 DEP_GIT DEP_GPM"
48 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
49
50 # Internal variables
51 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
52 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
53 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
54
55 local PARAM_LIST=
56 local config_param
57 local validation_str
58 local save_param
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
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
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
125 set +e
126 PARAM_GROUP=${PROGNAME}_PARAM_LIST
127 for config_param in ${!PARAM_GROUP}; do
128 case $config_param in
129 # Envvars that depend on other settings to be displayed
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`" ;;
140 N_PARALLEL) [[ "$OPTIMIZE" -gt "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
141 REALSBU) [[ "$OPTIMIZE" = "2" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
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
151 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
152 validate_dir -z -d
153 else
154 echo -e "`eval echo $PARAM_VALS`"
155 fi
156 ;;
157 # Validate directories, testable states:
158 # fatal -z -d -w,
159 # warning -z+ -w+
160 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
161 # The build directory/partition MUST exist and be writable by the user
162 BUILDDIR) validate_dir -z -d
163 [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
164 LHOME) validate_dir -z -d ;;
165
166 # Validate files, testable states:
167 # fatal -z -e -s -w -x -r,
168 # warning -z+
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
173 # Treatment of LANG parameter
174 LANG ) # See it the locale value has been set
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 ;;
181
182 # Treatment of HOSTNAME
183 HOSTNAME) echo -e "`eval echo $PARAM_VALS`"
184 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
185 ;;
186
187 # Case of PKGMNGT: two files, packageManager.xml and packInstall.sh
188 # must exist in $PKGMNGTDIR if PKGMNGT='y':
189 PKGMNGT) echo -e "`eval echo $PARAM_VALS`"
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
209 fi
210 ;;
211 # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
212 * ) echo -e "`eval echo $PARAM_VALS`" ;;
213
214 esac
215 done
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
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
230 set -e
231 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
232}
Note: See TracBrowser for help on using the repository browser.