1 | declare -r dotSTR=".................."
|
---|
2 |
|
---|
3 |
|
---|
4 | #----------------------------#
|
---|
5 | validate_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,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
|
---|
18 | inline_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 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
|
---|
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"
|
---|
42 |
|
---|
43 | # System Settings by book (only LFS for now)
|
---|
44 | local -r LFS_system="HOSTNAME INTERFACE IP_ADDR GATEWAY PREFIX BROADCAST DOMAIN DNS1 DNS2 FONT KEYMAP LOCAL LOG_LEVEL"
|
---|
45 |
|
---|
46 | # Full list of books settings
|
---|
47 | local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $LFS_system $ADVANCED_chroot N_PARALLEL REALSBU SAVE_CH5 $ADVANCED_common"
|
---|
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"
|
---|
51 | # local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
|
---|
52 |
|
---|
53 | # Additional variables
|
---|
54 | local -r blfs_tool_PARAM_LIST="\
|
---|
55 | BLFS_TREE BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
|
---|
56 | DEP_LIBXML DEP_LIBXSLT DEP_DBXML DEP_LYNX DEP_SUDO DEP_WGET \
|
---|
57 | DEP_GIT DEP_GPM"
|
---|
58 | local -r custom_tool_PARAM_LIST="TRACKING_DIR"
|
---|
59 |
|
---|
60 | # Internal variables
|
---|
61 | local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
|
---|
62 | local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
|
---|
63 | local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
64 |
|
---|
65 | local PARAM_LIST=
|
---|
66 | local config_param
|
---|
67 | local validation_str
|
---|
68 | local save_param
|
---|
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 |
|
---|
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 |
|
---|
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 |
|
---|
135 | set +e
|
---|
136 | PARAM_GROUP=${PROGNAME}_PARAM_LIST
|
---|
137 | for config_param in ${!PARAM_GROUP}; do
|
---|
138 | case $config_param in
|
---|
139 | # Envvars that depend on other settings to be displayed
|
---|
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`" ;;
|
---|
150 | N_PARALLEL) [[ "$OPTIMIZE" -gt "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
151 | REALSBU) [[ "$OPTIMIZE" = "2" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
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
|
---|
161 | BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
|
---|
162 | validate_dir -z -d
|
---|
163 | else
|
---|
164 | echo -e "`eval echo $PARAM_VALS`"
|
---|
165 | fi
|
---|
166 | ;;
|
---|
167 | # Validate directories, testable states:
|
---|
168 | # fatal -z -d -w,
|
---|
169 | # warning -z+ -w+
|
---|
170 | SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
|
---|
171 | # The build directory/partition MUST exist and be writable by the user
|
---|
172 | BUILDDIR) validate_dir -z -d
|
---|
173 | [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
|
---|
174 | LHOME) validate_dir -z -d ;;
|
---|
175 |
|
---|
176 | # Validate files, testable states:
|
---|
177 | # fatal -z -e -s -w -x -r,
|
---|
178 | # warning -z+
|
---|
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 |
|
---|
183 | # Treatment of LANG parameter
|
---|
184 | LANG ) # See it the locale value has been set
|
---|
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 | ;;
|
---|
191 |
|
---|
192 | # Treatment of HOSTNAME
|
---|
193 | HOSTNAME) echo -e "`eval echo $PARAM_VALS`"
|
---|
194 | [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
|
---|
195 | ;;
|
---|
196 |
|
---|
197 | # Case of PKGMNGT: two files, packageManager.xml and packInstall.sh
|
---|
198 | # must exist in $PKGMNGTDIR if PKGMNGT='y':
|
---|
199 | PKGMNGT) echo -e "`eval echo $PARAM_VALS`"
|
---|
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
|
---|
219 | fi
|
---|
220 | ;;
|
---|
221 | # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
|
---|
222 | * ) echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
223 |
|
---|
224 | esac
|
---|
225 | done
|
---|
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 |
|
---|
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 |
|
---|
240 | set -e
|
---|
241 | echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
|
---|
242 | }
|
---|