source: common/libs/func_validate_configs.sh@ 1d4eebf

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 1d4eebf was d035526, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

HLFS: Added support for additional build features.

  • Property mode set to 100644
File size: 9.1 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 \
26 SERVER GETKERNEL RUNMAKE"
27 local -r BUILD_chroot="TEST BOMB_TEST STRIP"
[f546320]28 local -r BUILD_common="FSTAB CONFIG TIMEZONE PAGE LANG INSTALL_LOG"
[350625a]29 local -r ADVANCED_chroot="COMPARE RUN_ICA RUN_FARCE ITERATIONS OPTIMIZE"
30 local -r ADVANCED_common="REPORT REBUILD_MAKEFILE"
31
32 # BOOK Settings by book
33 local -r LFS_book="$BOOK_common BLFS_TOOL"
[d035526]34 local -r HLFS_added="SET_SSP SET_ASLR SET_PAX SET_HARDENED_TMP SET_WARNINGS \
35 SET_MISC SET_BLOWFISH"
36 local -r HLFS_book="$BOOK_common BLFS_TOOL MODEL KERNEL GRSECURITY_HOST $HLFS_added"
[350625a]37 local -r CLFS_book="$BOOK_common BLFS_TOOL METHOD $BOOK_clfsX TARGET32 BOOT_CONFIG"
38 local -r CLFS2_book="$BOOK_common BLFS_TOOL $BOOK_clfsX"
39 local -r CLFS3_book="$BOOK_common $BOOK_clfsX PLATFORM MIPS_LEVEL"
40
41 # Build Settings by book
[f546320]42 local -r LFS_build="$BUILD_chroot VIMLANG $BUILD_common"
[05760bc]43 local -r HLFS_build="$BUILD_chroot $BUILD_common"
[f546320]44 local -r CLFS_build="$BUILD_chroot VIMLANG $BUILD_common"
45 local -r CLFS2_build="STRIP VIMLANG $BUILD_common"
46 local -r CLFS3_build=" $BUILD_common"
[350625a]47
48 # Full list of books settings
49 local -r lfs_PARAM_LIST="$LFS_book $GENERAL_common $LFS_build $ADVANCED_chroot $ADVANCED_common"
50 local -r hlfs_PARAM_LIST="$HLFS_book $GENERAL_common $HLFS_build $ADVANCED_chroot $ADVANCED_common"
51 local -r clfs_PARAM_LIST="$CLFS_book $GENERAL_common $CLFS_build $ADVANCED_chroot $ADVANCED_common"
52 local -r clfs2_PARAM_LIST="$CLFS2_book $GENERAL_common $CLFS2_build $ADVANCED_common"
53 local -r clfs3_PARAM_LIST="$CLFS3_book $GENERAL_common $CLFS3_build $ADVANCED_common"
[f4ed135]54 local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
[877cc6a]55
[350625a]56 # Additional variables
57 local -r blfs_tool_PARAM_LIST="BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR \
58 DEP_LIBXML DEP_LIBXSLT DEP_TIDY DEP_UNZIP \
59 DEP_DBXML DEP_DBXSL DEP_LINKS DEP_SUDO DEP_WGET \
60 DEP_SVN DEP_GPM"
[53f291f]61 local -r custom_tool_PARAM_LIST="TRACKING_DIR"
[4965fa8]62
[350625a]63 # Internal variables
[877cc6a]64 local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
[4965fa8]65 local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
[c14e4b3]66 local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
[877cc6a]67
[3e7ceed]68 local PARAM_LIST=
[877cc6a]69 local config_param
70 local validation_str
[45f82718]71 local save_param
[877cc6a]72
73 write_error_and_die() {
74 echo -e "\n${DD_BORDER}"
75 echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
76 echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
77 echo -e "${DD_BORDER}\n"
78 exit 1
79 }
80
[45f82718]81 validate_file() {
82 # For parameters ending with a '+' failure causes a warning message only
83 echo -n "`eval echo $PARAM_VALS`"
84 while test $# -gt 0 ; do
85 case $1 in
86 # Failures caused program exit
87 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
88 "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
89 "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
90 "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
91 "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
92 "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
93 # Warning messages only
94 "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
95 esac
96 shift 1
97 done
98 echo
99 }
100
101 validate_dir() {
102 # For parameters ending with a '+' failure causes a warning message only
103 echo -n "`eval echo $PARAM_VALS`"
104 while test $# -gt 0 ; do
105 case $1 in
106 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
107 "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
108 "-w") if [[ ! -w "${!config_param}" ]]; then
109 echo "${nl_}${DD_BORDER}"
110 echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
111 echo "${tab_}${BOLD}${!config_param}${OFF}"
112 echo "${DD_BORDER}${nl_}"
113 exit 1
114 fi ;;
115 # Warnings only
116 "-w+") if [[ ! -w "${!config_param}" ]]; then
117 echo "${nl_}${DD_BORDER}"
118 echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
119 echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
120 echo "${DD_BORDER}"
121 fi ;;
122 "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
123 esac
124 shift 1
125 done
126 echo
127 }
128
[877cc6a]129 set +e
[45f82718]130 PARAM_GROUP=${PROGNAME}_PARAM_LIST
131 for config_param in ${!PARAM_GROUP}; do
132 case $config_param in
[4da2512]133 # Envvars that depend on other settings to be displayed
[294c937]134 GETKERNEL ) if [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] ; then
[4da2512]135 [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`"
[294c937]136 fi ;;
[4da2512]137 COMPARE) [[ ! "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
138 RUN_ICA) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
139 RUN_FARCE) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
140 ITERATIONS) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
141 BOMB_TEST) [[ ! "$TEST" = "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
142 TARGET32) [[ -n "${TARGET32}" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
[ee728b3]143 MIPS_LEVEL) [[ "${ARCH}" = "mips" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
[350625a]144 SERVER) [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
[4da2512]145
146 # Envars that requires some validation
147 LUSER) echo -e "`eval echo $PARAM_VALS`"
148 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
149 ;;
150 LGROUP) echo -e "`eval echo $PARAM_VALS`"
151 [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
152 ;;
153 # BOOK validation. Very ugly, need be fixed
[4965fa8]154 BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
[45f82718]155 validate_dir -z -d
156 else
[4da2512]157 echo -e "`eval echo $PARAM_VALS`"
[0210014]158 fi
159 ;;
[4da2512]160 # Validate directories, testable states:
161 # fatal -z -d -w,
162 # warning -z+ -w+
[401f81e]163 SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
[4da2512]164 # The build directory/partition MUST exist and be writable by the user
165 BUILDDIR) validate_dir -z -d -w
[a96109a]166 [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
[962793a]167 LHOME) validate_dir -z -d ;;
[45f82718]168
[4da2512]169 # Validate files, testable states:
170 # fatal -z -e -s -w -x -r,
171 # warning -z+
[45f82718]172 FSTAB) validate_file -z+ -e -s ;;
173 CONFIG) validate_file -z+ -e -s ;;
174 BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
175
[5c575e1]176 # Treatment of LANG parameter
177 LANG ) # See it the locale value has been set
[45f82718]178 echo -n "`eval echo $PARAM_VALS`"
179 [[ -z "${!config_param}" ]] &&
180 echo " -- Variable $config_param cannot be empty!" &&
181 write_error_and_die
182 echo
183 ;;
[c59f9a0]184
[4da2512]185 # BLFS params.
[f4ed135]186 BRANCH_ID | BLFS_ROOT | BLFS_XML ) echo "`eval echo $PARAM_VALS`" ;;
187 TRACKING_DIR ) validate_dir -z -d -w ;;
[c59f9a0]188
[350625a]189 # Display non-validated envars found in ${PROGNAME}_PARAM_LIST
190 * ) echo -e "`eval echo $PARAM_VALS`" ;;
191
[45f82718]192 esac
193 done
[4965fa8]194
195 if [[ "${BLFS_TOOL}" = "y" ]] ; then
196 echo "${nl_} ${BLUE}blfs-tool settings${OFF}"
197 for config_param in ${blfs_tool_PARAM_LIST}; do
198 echo -e "`eval echo $PARAM_VALS`"
199 done
200 fi
201
[53f291f]202 if [[ "${CUSTOM_TOOLS}" = "y" ]] && [[ "${BLFS_TOOL}" = "n" ]] ; then
203 for config_param in ${custom_tool_PARAM_LIST}; do
204 echo -e "`eval echo $PARAM_VALS`"
205 done
206 fi
207
[877cc6a]208 set -e
[21f0a91]209 echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
[877cc6a]210}
Note: See TracBrowser for help on using the repository browser.