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