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