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