source: common/libs/func_validate_configs.sh@ e2dfa2c

experimental
Last change on this file since e2dfa2c was 9c9775f, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Updated experimental branch to current trunk code.

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