[877cc6a] | 1 | # $Id$
|
---|
| 2 |
|
---|
[45f82718] | 3 | #----------------------------#
|
---|
| 4 | validate_target() { #
|
---|
| 5 | #----------------------------#
|
---|
[877cc6a] | 6 | local -r ERROR_MSG_pt1='The variable \"${L_arrow}TARGET${R_arrow}\" value ${L_arrow}${BOLD}${TARGET}${R_arrow} is invalid for the ${L_arrow}${BOLD}${ARCH}${R_arrow} architecture'
|
---|
| 7 | local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
|
---|
| 8 |
|
---|
| 9 | local -r PARAM_VALS='TARGET: ${L_arrow}${BOLD}${TARGET}${OFF}${R_arrow}'
|
---|
| 10 | local -r PARAM_VALS2='TARGET32: ${L_arrow}${BOLD}${TARGET32}${OFF}${R_arrow}'
|
---|
| 11 |
|
---|
| 12 | write_error_and_die() {
|
---|
| 13 | echo -e "\n${DD_BORDER}"
|
---|
| 14 | echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
|
---|
| 15 | echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
|
---|
| 16 | echo -e "${DD_BORDER}\n"
|
---|
| 17 | exit 1
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | if [[ ! "${TARGET32}" = "" ]]; then
|
---|
| 21 | echo -e "`eval echo $PARAM_VALS2`"
|
---|
| 22 | fi
|
---|
| 23 | echo -e "`eval echo $PARAM_VALS`"
|
---|
| 24 |
|
---|
| 25 | case "${ARCH}" in
|
---|
| 26 | "x86") [[ "${TARGET}" = "i486-pc-linux-gnu" ]] && return
|
---|
| 27 | [[ "${TARGET}" = "i586-pc-linux-gnu" ]] && return
|
---|
| 28 | [[ "${TARGET}" = "i686-pc-linux-gnu" ]] && return
|
---|
| 29 | ;;
|
---|
| 30 | "ppc") [[ "${TARGET}" = "powerpc-unknown-linux-gnu" ]] && return
|
---|
| 31 | ;;
|
---|
| 32 | "mips") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] && return
|
---|
| 33 | [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] && return
|
---|
| 34 | ;;
|
---|
| 35 | "sparc") [[ "${TARGET}" = "sparcv9-unknown-linux-gnu" ]] && return
|
---|
| 36 | ;;
|
---|
| 37 | "x86_64-64") [[ "${TARGET}" = "x86_64-unknown-linux-gnu" ]] && return
|
---|
| 38 | ;;
|
---|
| 39 | "mips64-64") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] && return
|
---|
| 40 | [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] && return
|
---|
| 41 | ;;
|
---|
| 42 | "sparc64-64") [[ "${TARGET}" = "sparc64-unknown-linux-gnu" ]] && return
|
---|
| 43 | ;;
|
---|
| 44 | "alpha") [[ "${TARGET}" = "alpha-unknown-linux-gnu" ]] && return
|
---|
| 45 | ;;
|
---|
| 46 | "x86_64") [[ "${TARGET}" = "x86_64-unknown-linux-gnu" ]] &&
|
---|
| 47 | [[ "${TARGET32}" = "i686-pc-linux-gnu" ]] && return
|
---|
| 48 | ;;
|
---|
| 49 | "mips64") [[ "${TARGET}" = "mipsel-unknown-linux-gnu" ]] &&
|
---|
| 50 | [[ "${TARGET32}" = "mipsel-unknown-linux-gnu" ]] && return
|
---|
| 51 |
|
---|
| 52 | [[ "${TARGET}" = "mips-unknown-linux-gnu" ]] &&
|
---|
| 53 | [[ "${TARGET32}" = "mips-unknown-linux-gnu" ]] && return
|
---|
| 54 | ;;
|
---|
| 55 | "sparc64") [[ "${TARGET}" = "sparc64-unknown-linux-gnu" ]] &&
|
---|
| 56 | [[ "${TARGET32}" = "sparcv9-unknown-linux-gnu" ]] && return
|
---|
| 57 | ;;
|
---|
| 58 | "ppc64") [[ "${TARGET}" = "powerpc64-unknown-linux-gnu" ]] &&
|
---|
| 59 | [[ "${TARGET32}" = "powerpc-unknown-linux-gnu" ]] && return
|
---|
| 60 | ;;
|
---|
| 61 | *) write_error_and_die
|
---|
| 62 | ;;
|
---|
| 63 | esac
|
---|
| 64 |
|
---|
| 65 | # If you end up here then there was an error SO...
|
---|
| 66 | write_error_and_die
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | #----------------------------#
|
---|
[45f82718] | 71 | validate_config() { # Are the config values sane (within reason)
|
---|
[877cc6a] | 72 | #----------------------------#
|
---|
| 73 | : <<inline_doc
|
---|
| 74 | Validates the configuration parameters. The global var PROGNAME selects the
|
---|
| 75 | parameter list.
|
---|
| 76 |
|
---|
| 77 | input vars: none
|
---|
| 78 | externals: color constants
|
---|
[1ec8fce] | 79 | PROGNAME (lfs,clfs,hlfs)
|
---|
[877cc6a] | 80 | modifies: none
|
---|
| 81 | returns: nothing
|
---|
[45f82718] | 82 | on error: write text to console and dies
|
---|
[877cc6a] | 83 | on success: write text to console and returns
|
---|
| 84 | inline_doc
|
---|
| 85 |
|
---|
| 86 | # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
|
---|
[1b65a84] | 87 | local -r hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG KEYMAP PAGE TIMEZONE LANG LC_ALL"
|
---|
| 88 | local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD ARCH TARGET TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
|
---|
| 89 | local -r lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB CONFIG VIMLANG PAGE TIMEZONE LANG"
|
---|
[877cc6a] | 90 |
|
---|
| 91 | local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
|
---|
| 92 | local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
|
---|
| 93 | local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
| 94 |
|
---|
| 95 | local PARAM_LIST=
|
---|
| 96 | local config_param
|
---|
| 97 | local validation_str
|
---|
[45f82718] | 98 | local save_param
|
---|
[877cc6a] | 99 |
|
---|
| 100 | write_error_and_die() {
|
---|
| 101 | echo -e "\n${DD_BORDER}"
|
---|
| 102 | echo -e "`eval echo ${ERROR_MSG_pt1}`" >&2
|
---|
| 103 | echo -e "`eval echo ${ERROR_MSG_pt2}`" >&2
|
---|
| 104 | echo -e "${DD_BORDER}\n"
|
---|
| 105 | exit 1
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[45f82718] | 108 | validate_against_str() {
|
---|
[877cc6a] | 109 | # This is the 'regexp' test available in bash-3.0..
|
---|
| 110 | # using it as a poor man's test for substring
|
---|
| 111 | echo -e "`eval echo $PARAM_VALS`"
|
---|
[45f82718] | 112 | if [[ ! "$1" =~ "x${!config_param}x" ]] ; then
|
---|
[877cc6a] | 113 | # parameter value entered is no good
|
---|
| 114 | write_error_and_die
|
---|
| 115 | fi
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[45f82718] | 118 | validate_file() {
|
---|
| 119 | # For parameters ending with a '+' failure causes a warning message only
|
---|
| 120 | echo -n "`eval echo $PARAM_VALS`"
|
---|
| 121 | while test $# -gt 0 ; do
|
---|
| 122 | case $1 in
|
---|
| 123 | # Failures caused program exit
|
---|
| 124 | "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;;
|
---|
| 125 | "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;;
|
---|
| 126 | "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;;
|
---|
| 127 | "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;;
|
---|
| 128 | "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;;
|
---|
| 129 | "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;;
|
---|
| 130 | # Warning messages only
|
---|
| 131 | "-z+") [[ -z "${!config_param}" ]] && echo && return ;;
|
---|
| 132 | esac
|
---|
| 133 | shift 1
|
---|
| 134 | done
|
---|
| 135 | echo
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | validate_dir() {
|
---|
| 139 | # For parameters ending with a '+' failure causes a warning message only
|
---|
| 140 | echo -n "`eval echo $PARAM_VALS`"
|
---|
| 141 | while test $# -gt 0 ; do
|
---|
| 142 | case $1 in
|
---|
| 143 | "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;;
|
---|
| 144 | "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;;
|
---|
| 145 | "-w") if [[ ! -w "${!config_param}" ]]; then
|
---|
| 146 | echo "${nl_}${DD_BORDER}"
|
---|
| 147 | echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}"
|
---|
| 148 | echo "${tab_}${BOLD}${!config_param}${OFF}"
|
---|
| 149 | echo "${DD_BORDER}${nl_}"
|
---|
| 150 | exit 1
|
---|
| 151 | fi ;;
|
---|
| 152 | # Warnings only
|
---|
| 153 | "-w+") if [[ ! -w "${!config_param}" ]]; then
|
---|
| 154 | echo "${nl_}${DD_BORDER}"
|
---|
| 155 | echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}"
|
---|
| 156 | echo "${tab_} -- ${BOLD}${!config_param}${OFF}"
|
---|
| 157 | echo "${DD_BORDER}"
|
---|
| 158 | fi ;;
|
---|
| 159 | "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return
|
---|
| 160 | esac
|
---|
| 161 | shift 1
|
---|
| 162 | done
|
---|
| 163 | echo
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[877cc6a] | 166 | set +e
|
---|
[45f82718] | 167 | PARAM_GROUP=${PROGNAME}_PARAM_LIST
|
---|
| 168 | for config_param in ${!PARAM_GROUP}; do
|
---|
| 169 | # This is a tricky little piece of code.. executes a cmd string.
|
---|
| 170 | case $config_param in
|
---|
[0ad851d] | 171 | TIMEZONE) echo -e "`eval echo $PARAM_VALS`" ;;
|
---|
[45f82718] | 172 |
|
---|
| 173 | # Validate general parameters..
|
---|
[15cad16] | 174 | GETPKG) validate_against_str "x0x x1x" ;;
|
---|
[45f82718] | 175 | RUNMAKE) validate_against_str "x0x x1x" ;;
|
---|
| 176 | REPORT) validate_against_str "x0x x1x"
|
---|
| 177 | if [[ "${!config_param}" = "1" ]]; then
|
---|
| 178 | if [[ `type -p bc` ]]; then
|
---|
| 179 | continue
|
---|
| 180 | else
|
---|
| 181 | echo -e " ${BOLD}The bc binary was not found${OFF}"
|
---|
| 182 | echo -e " The SBU and disk usage report creation will be skiped"
|
---|
| 183 | REPORT=0
|
---|
| 184 | continue
|
---|
| 185 | fi
|
---|
| 186 | fi ;;
|
---|
| 187 | COMPARE) if [[ ! "$COMPARE" = "1" ]]; then
|
---|
| 188 | validate_against_str "x0x x1x"
|
---|
| 189 | else
|
---|
| 190 | if [[ ! "${RUN_ICA}" = "1" ]] && [[ ! "${RUN_FARCE}" = "1" ]]; then
|
---|
| 191 | echo "${nl_}${DD_BORDER}"
|
---|
| 192 | echo "You have elected to analyse your build but have failed to select a tool." >&2
|
---|
| 193 | echo "Edit /common/config and set ${L_arrow}${BOLD}RUN_ICA${R_arrow} and/or ${L_arrow}${BOLD}RUN_FARCE${R_arrow} to the required values" >&2
|
---|
| 194 | echo "${DD_BORDER}${nl_}"
|
---|
| 195 | exit 1
|
---|
| 196 | fi
|
---|
| 197 | fi ;;
|
---|
| 198 | RUN_ICA) [[ "$COMPARE" = "1" ]] && validate_against_str "x0x x1x" ;;
|
---|
| 199 | RUN_FARCE) [[ "$COMPARE" = "1" ]] && validate_against_str "x0x x1x" ;;
|
---|
| 200 | ITERATIONS) [[ "$COMPARE" = "1" ]] && validate_against_str "x2x x3x x4x x5x" ;;
|
---|
| 201 | TEST) validate_against_str "x0x x1x x2x x3x" ;;
|
---|
[1b65a84] | 202 | OPTIMIZE) validate_against_str "x0x x1x x2x" ;;
|
---|
[45f82718] | 203 | STRIP) validate_against_str "x0x x1x" ;;
|
---|
| 204 | VIMLANG) validate_against_str "x0x x1x" ;;
|
---|
| 205 | MODEL) validate_against_str "xglibcx xuclibcx" ;;
|
---|
| 206 | PAGE) validate_against_str "xletterx xA4x" ;;
|
---|
| 207 | METHOD) validate_against_str "xchrootx xbootx" ;;
|
---|
| 208 | ARCH) validate_against_str "xx86x xx86_64x xx86_64-64x xsparcx xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ;;
|
---|
| 209 | TARGET) validate_target ;;
|
---|
| 210 | GRSECURITY_HOST) validate_against_str "x0x x1x" ;;
|
---|
| 211 |
|
---|
| 212 | # BOOK validation. Very ugly, need be fixed
|
---|
| 213 | BOOK) if [[ "${WC}" = "1" ]] ; then
|
---|
| 214 | validate_dir -z -d
|
---|
| 215 | else
|
---|
[0ad851d] | 216 | validate_against_str "x${PROGNAME}-developmentx"
|
---|
| 217 | fi ;;
|
---|
[877cc6a] | 218 |
|
---|
[45f82718] | 219 | # Validate directories, testable states:
|
---|
| 220 | # fatal -z -d -w,
|
---|
| 221 | # warning -z+ -w+
|
---|
| 222 | SRC_ARCHIVE) validate_dir -z+ -d -w+ ;;
|
---|
[863c595] | 223 | BUILDDIR) # The build directory/partition MUST exist and be writable by the user
|
---|
| 224 | validate_dir -z -d -w
|
---|
| 225 | [[ "xx x/x" =~ "x${!config_param}x" ]] &&
|
---|
| 226 | write_error_and_die
|
---|
| 227 | ;;
|
---|
[45f82718] | 228 |
|
---|
| 229 | # Validate files, testable states:
|
---|
| 230 | # fatal -z -e -s -w -x -r,
|
---|
| 231 | # warning -z+
|
---|
| 232 | FSTAB) validate_file -z+ -e -s ;;
|
---|
| 233 | CONFIG) validate_file -z+ -e -s ;;
|
---|
| 234 | BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;;
|
---|
| 235 |
|
---|
| 236 | # Treatment of 'special' parameters
|
---|
| 237 | LANG | \
|
---|
| 238 | LC_ALL) # See it the locale values exist on this machine
|
---|
| 239 | echo -n "`eval echo $PARAM_VALS`"
|
---|
| 240 | [[ -z "${!config_param}" ]] &&
|
---|
| 241 | echo " -- Variable $config_param cannot be empty!" &&
|
---|
| 242 | write_error_and_die
|
---|
| 243 | echo
|
---|
| 244 | ;;
|
---|
| 245 | KEYMAP) echo "`eval echo $PARAM_VALS`"
|
---|
| 246 | save_param=${KEYMAP}
|
---|
| 247 | [[ ! "${!config_param}" = "none" ]] &&
|
---|
| 248 | KEYMAP="/usr/share/kbd/keymaps/${KEYMAP}" &&
|
---|
| 249 | validate_file -z -e -s
|
---|
| 250 | KEYMAP=${save_param}
|
---|
| 251 | ;;
|
---|
| 252 | esac
|
---|
| 253 | done
|
---|
[877cc6a] | 254 | set -e
|
---|
[21f0a91] | 255 | echo "${nl_}***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***${nl_}"
|
---|
[877cc6a] | 256 | }
|
---|