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