source: common/libs/func_validate_configs.sh@ eb8667a

new_features
Last change on this file since eb8667a was e042e91, checked in by Pierre Labastie <pierre@…>, 8 years ago

Remove completely all references to tidy as a BLfs tool.

  • Property mode set to 100644
File size: 9.5 KB
Line 
1# $Id$
2
3declare -r dotSTR=".................."
4
5
6#----------------------------#
7validate_config() { # Are the config values sane (within reason)
8#----------------------------#
9: <<inline_doc
10 Validates the configuration parameters. The global var PROGNAME selects the
11 parameter list.
12
13 input vars: none
14 externals: color constants
15 PROGNAME (lfs,hlfs,clfs,clfs2,clfs3,blfs)
16 modifies: none
17 returns: nothing
18 on error: write text to console and dies
19 on success: write text to console and returns
20inline_doc
21
22 # Common settings by Config.in sections and books family
23 local -r BOOK_common="BOOK CUSTOM_TOOLS"
24 local -r BOOK_clfsX="ARCH TARGET"
25 local -r GENERAL_common="LUSER LGROUP LHOME BUILDDIR CLEAN GETPKG SRC_ARCHIVE \
26 SERVER RETRYSRCDOWNLOAD RETRYDOWNLOADCNT DOWNLOADTIMEOUT \
27 RUNMAKE"
28 local -r BUILD_chroot="TEST BOMB_TEST STRIP"
29 local -r BUILD_common="FSTAB CONFIG TIMEZONE PAGE LANG INSTALL_LOG"
30 local -r ADVANCED_chroot="COMPARE RUN_ICA RUN_FARCE ITERATIONS OPTIMIZE"
31 local -r ADVANCED_common="REPORT REBUILD_MAKEFILE"
32
33 # BOOK Settings by book
34 local -r LFS_book="$BOOK_common INITSYS BLFS_TOOL"
35 #local -r HLFS_added="SET_SSP SET_ASLR SET_PAX SET_HARDENED_TMP SET_WARNINGS \
36 # SET_MISC SET_BLOWFISH"
37 local -r HLFS_added=""
38 local -r HLFS_book="$BOOK_common BLFS_TOOL MODEL KERNEL GRSECURITY_HOST $HLFS_added"
39 local -r CLFS_book="$BOOK_common BLFS_TOOL METHOD $BOOK_clfsX TARGET32 BOOT_CONFIG"
40 local -r CLFS2_book="$BOOK_common BLFS_TOOL $BOOK_clfsX"
41 local -r CLFS3_book="$BOOK_common $BOOK_clfsX PLATFORM MIPS_LEVEL"
42
43 # Build Settings by book
44 local -r LFS_build="$BUILD_chroot VIMLANG $BUILD_common PKGMNGT FULL_LOCALE WRAP_INSTALL"
45 local -r HLFS_build="$BUILD_chroot $BUILD_common"
46 local -r CLFS_build="$BUILD_chroot VIMLANG $BUILD_common"
47 local -r CLFS2_build="STRIP VIMLANG $BUILD_common"
48 local -r CLFS3_build=" $BUILD_common"
49
50 # System Settings by book (only LFS for now)
51 local -r LFS_system="HOSTNAME INTERFACE IP_ADDR GATEWAY PREFIX BROADCAST DOMAIN DNS1 DNS2 FONT CONSOLE_MAP UNICODE KEYMAP"
52
53 # Full list of books settings
54 local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $LFS_system $ADVANCED_chroot $ADVANCED_common"
55 local -r hlfs_PARAM_LIST="$HLFS_book $GENERAL_common $HLFS_build $ADVANCED_chroot $ADVANCED_common"
56 local -r clfs_PARAM_LIST="$CLFS_book $GENERAL_common $CLFS_build $ADVANCED_chroot $ADVANCED_common"
57 local -r clfs2_PARAM_LIST="$CLFS2_book $GENERAL_common $CLFS2_build $ADVANCED_common"
58 local -r clfs3_PARAM_LIST="$CLFS3_book $GENERAL_common $CLFS3_build $ADVANCED_common"
59# local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
60
61 # Additional variables
62 local -r blfs_tool_PARAM_LIST="\
63 BLFS_TREE BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
64 DEP_LIBXML DEP_LIBXSLT DEP_DBXML DEP_LYNX DEP_SUDO DEP_WGET \
65 DEP_SVN DEP_GPM DEP_OPENSSL DEP_PYTHON"
66 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
67
68 # Internal variables
69 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
70 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
71 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
72
73 local PARAM_LIST=
74 local config_param
75 local validation_str
76 local save_param
77
78 write_error_and_die() {
79 echo -e "\n${DD_BORDER}"
80 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
81 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
82 echo -e "${DD_BORDER}\n"
83 exit 1
84 }
85
86 validate_file() {
87 # For parameters ending with a '+' failure causes a warning message only
88 echo -n "`eval echo $PARAM_VALS`"
89 while test $# -gt 0 ; do
90 case $1 in
91 # Failures caused program exit
92 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
93 "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
94 "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
95 "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
96 "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
97 "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
98 # Warning messages only
99 "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
100 esac
101 shift 1
102 done
103 echo
104 }
105
106 validate_dir() {
107 # For parameters ending with a '+' failure causes a warning message only
108 echo -n "`eval echo $PARAM_VALS`"
109 while test $# -gt 0 ; do
110 case $1 in
111 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
112 "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
113 "-w") if [[ ! -w "${!config_param}" ]]; then
114 echo "${nl_}${DD_BORDER}"
115 echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
116 echo "${tab_}${BOLD}${!config_param}${OFF}"
117 echo "${DD_BORDER}${nl_}"
118 exit 1
119 fi ;;
120 # Warnings only
121 "-w+") if [[ ! -w "${!config_param}" ]]; then
122 echo "${nl_}${DD_BORDER}"
123 echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
124 echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
125 echo "${DD_BORDER}"
126 fi ;;
127 "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
128 esac
129 shift 1
130 done
131 echo
132 }
133
134 set +e
135 PARAM_GROUP=${PROGNAME}_PARAM_LIST
136 for config_param in ${!PARAM_GROUP}; do
137 case $config_param in
138 # Envvars that depend on other settings to be displayed
139 COMPARE) [[ ! "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
140 RUN_ICA) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
141 RUN_FARCE) [[ "$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
151 # Envars that requires some validation
152 LUSER) echo -e "`eval echo $PARAM_VALS`"
153 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
154 ;;
155 LGROUP) echo -e "`eval echo $PARAM_VALS`"
156 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
157 ;;
158 # BOOK validation. Very ugly, need be fixed
159 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
160 validate_dir -z -d
161 else
162 echo -e "`eval echo $PARAM_VALS`"
163 fi
164 ;;
165 # Validate directories, testable states:
166 # fatal -z -d -w,
167 # warning -z+ -w+
168 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
169 # The build directory/partition MUST exist and be writable by the user
170 BUILDDIR) validate_dir -z -d -w
171 [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
172 LHOME) validate_dir -z -d ;;
173
174 # Validate files, testable states:
175 # fatal -z -e -s -w -x -r,
176 # warning -z+
177 FSTAB) validate_file -z+ -e -s ;;
178 CONFIG) validate_file -z+ -e -s ;;
179 BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
180
181 # Treatment of LANG parameter
182 LANG ) # See it the locale value has been set
183 echo -n "`eval echo $PARAM_VALS`"
184 [[ -z "${!config_param}" ]] &&
185 echo " -- Variable $config_param cannot be empty!" &&
186 write_error_and_die
187 echo
188 ;;
189
190 # Treatment of HOSTNAME
191 HOSTNAME) echo -e "`eval echo $PARAM_VALS`"
192 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
193 ;;
194
195 # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
196 * ) echo -e "`eval echo $PARAM_VALS`" ;;
197
198 esac
199 done
200
201 if [[ "${BLFS_TOOL}" = "y" ]] ; then
202 echo "${nl_} ${BLUE}blfs-tool settings${OFF}"
203 for config_param in ${blfs_tool_PARAM_LIST}; do
204 echo -e "`eval echo $PARAM_VALS`"
205 done
206 fi
207
208 if [[ "${CUSTOM_TOOLS}" = "y" ]] && [[ "${BLFS_TOOL}" = "n" ]] ; then
209 for config_param in ${custom_tool_PARAM_LIST}; do
210 echo -e "`eval echo $PARAM_VALS`"
211 done
212 fi
213
214 set -e
215 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
216}
Note: See TracBrowser for help on using the repository browser.