source: common/libs/func_validate_configs.sh@ b97ed5b

2.4 ablfs-more legacy new_features trunk
Last change on this file since b97ed5b was 854854e, checked in by Pierre Labastie <pierre@…>, 11 years ago
  • Make the number of parallel jobs configurable in the menuconfig interface
  • Allow choosing a working copy of the blfs book
  • Property mode set to 100644
File size: 9.2 KB
RevLine 
[877cc6a]1# $Id$
2
[c14e4b3]3declare -r dotSTR=".................."
4
[877cc6a]5
6#----------------------------#
[45f82718]7validate_config() { # Are the config values sane (within reason)
[877cc6a]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
[350625a]15 PROGNAME (lfs,hlfs,clfs,clfs2,clfs3,blfs)
[877cc6a]16 modifies: none
17 returns: nothing
[45f82718]18 on error: write text to console and dies
[877cc6a]19 on success: write text to console and returns
20inline_doc
21
[350625a]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 \
[de63126]26 SERVER RETRYSRCDOWNLOAD RETRYDOWNLOADCNT DOWNLOADTIMEOUT \
[3158dfa]27 RUNMAKE"
[350625a]28 local -r BUILD_chroot="TEST BOMB_TEST STRIP"
[f546320]29 local -r BUILD_common="FSTAB CONFIG TIMEZONE PAGE LANG INSTALL_LOG"
[350625a]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 BLFS_TOOL"
[6d5844c]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=""
[d035526]38 local -r HLFS_book="$BOOK_common BLFS_TOOL MODEL KERNEL GRSECURITY_HOST $HLFS_added"
[350625a]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
[b339c94]44 local -r LFS_build="$BUILD_chroot VIMLANG $BUILD_common PKGMNGT FULL_LOCALE"
[05760bc]45 local -r HLFS_build="$BUILD_chroot $BUILD_common"
[f546320]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"
[350625a]49
50 # Full list of books settings
51 local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $ADVANCED_chroot $ADVANCED_common"
52 local -r hlfs_PARAM_LIST="$HLFS_book $GENERAL_common $HLFS_build $ADVANCED_chroot $ADVANCED_common"
53 local -r clfs_PARAM_LIST="$CLFS_book $GENERAL_common $CLFS_build $ADVANCED_chroot $ADVANCED_common"
54 local -r clfs2_PARAM_LIST="$CLFS2_book $GENERAL_common $CLFS2_build $ADVANCED_common"
55 local -r clfs3_PARAM_LIST="$CLFS3_book $GENERAL_common $CLFS3_build $ADVANCED_common"
[854854e]56# local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
[877cc6a]57
[854854e]58 # Additional variables
59 local -r blfs_tool_PARAM_LIST="\
60 BLFS_TREE BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
61 DEP_LIBXML DEP_LIBXSLT DEP_TIDY DEP_DBXML DEP_LYNX DEP_SUDO DEP_WGET \
62 DEP_SVN DEP_GPM DEP_OPENSSL DEP_PYTHON"
[53f291f]63 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
[4965fa8]64
[350625a]65 # Internal variables
[877cc6a]66 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
[4965fa8]67 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
[c14e4b3]68 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
[877cc6a]69
[3e7ceed]70 local PARAM_LIST=
[877cc6a]71 local config_param
72 local validation_str
[45f82718]73 local save_param
[877cc6a]74
75 write_error_and_die() {
76 echo -e "\n${DD_BORDER}"
77 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
78 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
79 echo -e "${DD_BORDER}\n"
80 exit 1
81 }
82
[45f82718]83 validate_file() {
84 # For parameters ending with a '+' failure causes a warning message only
85 echo -n "`eval echo $PARAM_VALS`"
86 while test $# -gt 0 ; do
87 case $1 in
88 # Failures caused program exit
89 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
90 "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
91 "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
92 "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
93 "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
94 "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
95 # Warning messages only
96 "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
97 esac
98 shift 1
99 done
100 echo
101 }
102
103 validate_dir() {
104 # For parameters ending with a '+' failure causes a warning message only
105 echo -n "`eval echo $PARAM_VALS`"
106 while test $# -gt 0 ; do
107 case $1 in
108 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
109 "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
110 "-w") if [[ ! -w "${!config_param}" ]]; then
111 echo "${nl_}${DD_BORDER}"
112 echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
113 echo "${tab_}${BOLD}${!config_param}${OFF}"
114 echo "${DD_BORDER}${nl_}"
115 exit 1
116 fi ;;
117 # Warnings only
118 "-w+") if [[ ! -w "${!config_param}" ]]; then
119 echo "${nl_}${DD_BORDER}"
120 echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
121 echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
122 echo "${DD_BORDER}"
123 fi ;;
124 "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
125 esac
126 shift 1
127 done
128 echo
129 }
130
[877cc6a]131 set +e
[45f82718]132 PARAM_GROUP=${PROGNAME}_PARAM_LIST
133 for config_param in ${!PARAM_GROUP}; do
134 case $config_param in
[4da2512]135 # Envvars that depend on other settings to be displayed
[de63126]136 COMPARE) [[ ! "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
137 RUN_ICA) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
138 RUN_FARCE) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
139 ITERATIONS) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
140 BOMB_TEST) [[ ! "$TEST" = "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
141 TARGET32) [[ -n "${TARGET32}" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
142 MIPS_LEVEL) [[ "${ARCH}" = "mips" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
143 SERVER) [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
144 RETRYSRCDOWNLOAD) [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
145 RETRYDOWNLOADCNT) [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
146 DOWNLOADTIMEOUT) [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
[4da2512]147
148 # Envars that requires some validation
149 LUSER) echo -e "`eval echo $PARAM_VALS`"
150 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
151 ;;
152 LGROUP) echo -e "`eval echo $PARAM_VALS`"
153 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
154 ;;
155 # BOOK validation. Very ugly, need be fixed
[4965fa8]156 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
[45f82718]157 validate_dir -z -d
158 else
[4da2512]159 echo -e "`eval echo $PARAM_VALS`"
[0210014]160 fi
161 ;;
[4da2512]162 # Validate directories, testable states:
163 # fatal -z -d -w,
164 # warning -z+ -w+
[401f81e]165 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
[4da2512]166 # The build directory/partition MUST exist and be writable by the user
167 BUILDDIR) validate_dir -z -d -w
[a96109a]168 [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
[962793a]169 LHOME) validate_dir -z -d ;;
[45f82718]170
[4da2512]171 # Validate files, testable states:
172 # fatal -z -e -s -w -x -r,
173 # warning -z+
[45f82718]174 FSTAB) validate_file -z+ -e -s ;;
175 CONFIG) validate_file -z+ -e -s ;;
176 BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
177
[5c575e1]178 # Treatment of LANG parameter
179 LANG ) # See it the locale value has been set
[45f82718]180 echo -n "`eval echo $PARAM_VALS`"
181 [[ -z "${!config_param}" ]] &&
182 echo " -- Variable $config_param cannot be empty!" &&
183 write_error_and_die
184 echo
185 ;;
[c59f9a0]186
[350625a]187 # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
188 * ) echo -e "`eval echo $PARAM_VALS`" ;;
189
[45f82718]190 esac
191 done
[4965fa8]192
193 if [[ "${BLFS_TOOL}" = "y" ]] ; then
194 echo "${nl_} ${BLUE}blfs-tool settings${OFF}"
195 for config_param in ${blfs_tool_PARAM_LIST}; do
196 echo -e "`eval echo $PARAM_VALS`"
197 done
198 fi
199
[53f291f]200 if [[ "${CUSTOM_TOOLS}" = "y" ]] && [[ "${BLFS_TOOL}" = "n" ]] ; then
201 for config_param in ${custom_tool_PARAM_LIST}; do
202 echo -e "`eval echo $PARAM_VALS`"
203 done
204 fi
205
[877cc6a]206 set -e
[21f0a91]207 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
[877cc6a]208}
Note: See TracBrowser for help on using the repository browser.