[877cc6a] | 1 | # $Id$
|
---|
| 2 |
|
---|
[c14e4b3] | 3 | declare -r dotSTR=".................."
|
---|
| 4 |
|
---|
[877cc6a] | 5 |
|
---|
| 6 | #----------------------------#
|
---|
[45f82718] | 7 | validate_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
|
---|
[1ec8fce] | 15 | PROGNAME (lfs,clfs,hlfs)
|
---|
[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
|
---|
| 20 | inline_doc
|
---|
| 21 |
|
---|
| 22 | # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
|
---|
[962793a] | 23 | local -r hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG GETKERNEL PAGE TIMEZONE LANG LC_ALL LUSER LGROUP LHOME BLFS_TOOL CUSTOM_TOOLS REBUILD_MAKEFILE"
|
---|
| 24 | local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD ARCH TARGET TARGET32 TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG GETKERNEL VIMLANG PAGE TIMEZONE LANG LUSER LGROUP LHOME BLFS_TOOL CUSTOM_TOOLS REBUILD_MAKEFILE"
|
---|
| 25 | local -r clfs2_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE ARCH TARGET REPORT STRIP FSTAB CONFIG GETKERNEL VIMLANG PAGE TIMEZONE LANG LUSER LGROUP LHOME BLFS_TOOL CUSTOM_TOOLS REBUILD_MAKEFILE"
|
---|
| 26 | local -r clfs3_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE ARCH PLATFORM TARGET MIPS_LEVEL REPORT FSTAB CONFIG GETKERNEL VIMLANG PAGE TIMEZONE LANG LUSER LGROUP LHOME CUSTOM_TOOLS REBUILD_MAKEFILE"
|
---|
| 27 | local -r lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG GETKERNEL VIMLANG PAGE TIMEZONE LANG LUSER LGROUP LHOME BLFS_TOOL CUSTOM_TOOLS REBUILD_MAKEFILE"
|
---|
[f4ed135] | 28 | local -r blfs_PARAM_LIST="BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR"
|
---|
[877cc6a] | 29 |
|
---|
[3e7ceed] | 30 | local -r blfs_tool_PARAM_LIST="BLFS_BRANCH_ID BLFS_ROOT BLFS_XML TRACKING_DIR DEP_LIBXML DEP_LIBXSLT DEP_TIDY DEP_UNZIP DEP_DBXML DEP_DBXSL DEP_LINKS DEP_SUDO DEP_WGET DEP_SVN DEP_GPM"
|
---|
[53f291f] | 31 | local -r custom_tool_PARAM_LIST="TRACKING_DIR"
|
---|
[4965fa8] | 32 |
|
---|
[877cc6a] | 33 | local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
|
---|
[4965fa8] | 34 | local -r ERROR_MSG_pt2='rerun make and fix your configuration settings${OFF}'
|
---|
[c14e4b3] | 35 | local -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
[877cc6a] | 36 |
|
---|
[3e7ceed] | 37 | local PARAM_LIST=
|
---|
[877cc6a] | 38 | local config_param
|
---|
| 39 | local validation_str
|
---|
[45f82718] | 40 | local save_param
|
---|
[877cc6a] | 41 |
|
---|
| 42 | write_error_and_die() {
|
---|
| 43 | echo -e "\n${DD_BORDER}"
|
---|
| 44 | echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
|
---|
| 45 | echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
|
---|
| 46 | echo -e "${DD_BORDER}\n"
|
---|
| 47 | exit 1
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[45f82718] | 50 | validate_file() {
|
---|
| 51 | # For parameters ending with a '+' failure causes a warning message only
|
---|
| 52 | echo -n "`eval echo $PARAM_VALS`"
|
---|
| 53 | while test $# -gt 0 ; do
|
---|
| 54 | case $1 in
|
---|
| 55 | # Failures caused program exit
|
---|
| 56 | "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
|
---|
| 57 | "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
|
---|
| 58 | "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
|
---|
| 59 | "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
|
---|
| 60 | "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
|
---|
| 61 | "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
|
---|
| 62 | # Warning messages only
|
---|
| 63 | "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
|
---|
| 64 | esac
|
---|
| 65 | shift 1
|
---|
| 66 | done
|
---|
| 67 | echo
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | validate_dir() {
|
---|
| 71 | # For parameters ending with a '+' failure causes a warning message only
|
---|
| 72 | echo -n "`eval echo $PARAM_VALS`"
|
---|
| 73 | while test $# -gt 0 ; do
|
---|
| 74 | case $1 in
|
---|
| 75 | "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
|
---|
| 76 | "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
|
---|
| 77 | "-w") if [[ ! -w "${!config_param}" ]]; then
|
---|
| 78 | echo "${nl_}${DD_BORDER}"
|
---|
| 79 | echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
|
---|
| 80 | echo "${tab_}${BOLD}${!config_param}${OFF}"
|
---|
| 81 | echo "${DD_BORDER}${nl_}"
|
---|
| 82 | exit 1
|
---|
| 83 | fi ;;
|
---|
| 84 | # Warnings only
|
---|
| 85 | "-w+") if [[ ! -w "${!config_param}" ]]; then
|
---|
| 86 | echo "${nl_}${DD_BORDER}"
|
---|
| 87 | echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
|
---|
| 88 | echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
|
---|
| 89 | echo "${DD_BORDER}"
|
---|
| 90 | fi ;;
|
---|
| 91 | "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
|
---|
| 92 | esac
|
---|
| 93 | shift 1
|
---|
| 94 | done
|
---|
| 95 | echo
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[877cc6a] | 98 | set +e
|
---|
[45f82718] | 99 | PARAM_GROUP=${PROGNAME}_PARAM_LIST
|
---|
| 100 | for config_param in ${!PARAM_GROUP}; do
|
---|
| 101 | case $config_param in
|
---|
[4da2512] | 102 | # Allways display this, if found in ${PROGNAME}_PARAM_LIST
|
---|
| 103 | GETPKG | \
|
---|
| 104 | RUNMAKE | \
|
---|
| 105 | TEST | \
|
---|
| 106 | OPTIMIZE | \
|
---|
| 107 | STRIP | \
|
---|
| 108 | VIMLANG | \
|
---|
| 109 | MODEL | \
|
---|
| 110 | METHOD | \
|
---|
| 111 | ARCH | \
|
---|
[9bbf240] | 112 | PLATFORM | \
|
---|
[4da2512] | 113 | TARGET | \
|
---|
| 114 | GRSECURITY_HOST | \
|
---|
[4965fa8] | 115 | BLFS_TOOL | \
|
---|
[9a536f7] | 116 | CUSTOM_TOOLS | \
|
---|
[4da2512] | 117 | TIMEZONE | \
|
---|
[a16f769] | 118 | PAGE | \
|
---|
| 119 | REBUILD_MAKEFILE ) echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
[4da2512] | 120 |
|
---|
| 121 | # Envvars that depend on other settings to be displayed
|
---|
[294c937] | 122 | GETKERNEL ) if [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] ; then
|
---|
[4da2512] | 123 | [[ "$GETPKG" = "y" ]] && echo -e "`eval echo $PARAM_VALS`"
|
---|
[294c937] | 124 | fi ;;
|
---|
[4da2512] | 125 | COMPARE) [[ ! "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
| 126 | RUN_ICA) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
| 127 | RUN_FARCE) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
| 128 | ITERATIONS) [[ "$COMPARE" = "y" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
| 129 | BOMB_TEST) [[ ! "$TEST" = "0" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
| 130 | TARGET32) [[ -n "${TARGET32}" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
[ee728b3] | 131 | MIPS_LEVEL) [[ "${ARCH}" = "mips" ]] && echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
[4da2512] | 132 |
|
---|
| 133 | # Envars that requires some validation
|
---|
| 134 | LUSER) echo -e "`eval echo $PARAM_VALS`"
|
---|
| 135 | [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
|
---|
| 136 | ;;
|
---|
| 137 | LGROUP) echo -e "`eval echo $PARAM_VALS`"
|
---|
| 138 | [[ "${!config_param}" = "**EDIT ME**" ]] && write_error_and_die
|
---|
| 139 | ;;
|
---|
| 140 | REPORT) echo -e "`eval echo $PARAM_VALS`"
|
---|
[401f81e] | 141 | if [[ "${!config_param}" = "y" ]]; then
|
---|
[45f82718] | 142 | if [[ `type -p bc` ]]; then
|
---|
| 143 | continue
|
---|
| 144 | else
|
---|
| 145 | echo -e " ${BOLD}The bc binary was not found${OFF}"
|
---|
| 146 | echo -e " The SBU and disk usage report creation will be skiped"
|
---|
[401f81e] | 147 | REPORT=n
|
---|
[45f82718] | 148 | continue
|
---|
| 149 | fi
|
---|
| 150 | fi ;;
|
---|
| 151 |
|
---|
[4da2512] | 152 | # BOOK validation. Very ugly, need be fixed
|
---|
[4965fa8] | 153 | BOOK) if [[ "${WORKING_COPY}" = "y" ]] ; then
|
---|
[45f82718] | 154 | validate_dir -z -d
|
---|
| 155 | else
|
---|
[4da2512] | 156 | echo -e "`eval echo $PARAM_VALS`"
|
---|
[0ad851d] | 157 | fi ;;
|
---|
[877cc6a] | 158 |
|
---|
[4da2512] | 159 | # Validate directories, testable states:
|
---|
| 160 | # fatal -z -d -w,
|
---|
| 161 | # warning -z+ -w+
|
---|
[401f81e] | 162 | SRC_ARCHIVE) [[ "$GETPKG" = "y" ]] && validate_dir -z+ -d -w+ ;;
|
---|
[4da2512] | 163 | # The build directory/partition MUST exist and be writable by the user
|
---|
| 164 | BUILDDIR) validate_dir -z -d -w
|
---|
[a96109a] | 165 | [[ "xx x/x" =~ x${!config_param}x ]] && write_error_and_die ;;
|
---|
[962793a] | 166 | LHOME) validate_dir -z -d ;;
|
---|
[45f82718] | 167 |
|
---|
[4da2512] | 168 | # Validate files, testable states:
|
---|
| 169 | # fatal -z -e -s -w -x -r,
|
---|
| 170 | # warning -z+
|
---|
[45f82718] | 171 | FSTAB) validate_file -z+ -e -s ;;
|
---|
| 172 | CONFIG) validate_file -z+ -e -s ;;
|
---|
| 173 | BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
|
---|
| 174 |
|
---|
[4da2512] | 175 | # Treatment of 'special' parameters
|
---|
[45f82718] | 176 | LANG | \
|
---|
| 177 | LC_ALL) # See it the locale values exist on this machine
|
---|
| 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 |
|
---|
[45f82718] | 189 | esac
|
---|
| 190 | done
|
---|
[4965fa8] | 191 |
|
---|
| 192 | if [[ "${BLFS_TOOL}" = "y" ]] ; then
|
---|
| 193 | echo "${nl_} ${BLUE}blfs-tool settings${OFF}"
|
---|
| 194 | for config_param in ${blfs_tool_PARAM_LIST}; do
|
---|
| 195 | echo -e "`eval echo $PARAM_VALS`"
|
---|
| 196 | done
|
---|
| 197 | fi
|
---|
| 198 |
|
---|
[53f291f] | 199 | if [[ "${CUSTOM_TOOLS}" = "y" ]] && [[ "${BLFS_TOOL}" = "n" ]] ; then
|
---|
| 200 | for config_param in ${custom_tool_PARAM_LIST}; do
|
---|
| 201 | echo -e "`eval echo $PARAM_VALS`"
|
---|
| 202 | done
|
---|
| 203 | fi
|
---|
| 204 |
|
---|
[877cc6a] | 205 | set -e
|
---|
[21f0a91] | 206 | echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
|
---|
[877cc6a] | 207 | }
|
---|