From cc82e3778f9782ab432d624b18ce8190140faacd Mon Sep 17 00:00:00 2001 From: George Boudreau Date: Tue, 28 Mar 2006 23:36:52 +0000 Subject: [PATCH] common/func_validate_configs.sh, changes internal structure to allow for more flexibility --- CLFS/config | 2 +- common/func_validate_configs.sh | 206 ++++++++++++++++++-------------- 2 files changed, 118 insertions(+), 90 deletions(-) diff --git a/CLFS/config b/CLFS/config index 3244e19..935a6a2 100644 --- a/CLFS/config +++ b/CLFS/config @@ -38,7 +38,7 @@ TARGET= #--- Create a minimal boot system chroot/boot # NOTE: not all combinations are 'bootable' yet. -METHOD=chroot +METHOD=boot #--- Location of fstab file (if empty, a template is created) FSTAB= diff --git a/common/func_validate_configs.sh b/common/func_validate_configs.sh index 94e4fd7..327644d 100644 --- a/common/func_validate_configs.sh +++ b/common/func_validate_configs.sh @@ -1,4 +1,3 @@ - # $Id$ #----------------------------# @@ -17,20 +16,20 @@ validate_config() { # Are the config values sane (within reason) on success: write text to console and returns inline_doc - local -r lfs_PARAM_LIST="RUNMAKE STRIP PAGE TIMEZONE VIMLANG" - local -r blfs_PARAM_LIST="DEPEND" - local -r hlfs_PARAM_LIST="RUNMAKE MODEL GRSECURITY_HOST STRIP PAGE TIMEZONE" - local -r clfs_PARAM_LIST="RUNMAKE METHOD ARCH STRIP PAGE TIMEZONE VIMLANG" - local -r global_PARAM_LIST="BUILDDIR HPKG TEST" + local -r lfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP FSTAB CONFIG" + local -r blfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE TEST LANG DEPEND" + local -r hlfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP FSTAB CONFIG MODEL GRSECURITY_HOST" + local -r clfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP ARCH FSTAB CONFIG BOOT_CONFIG METHOD" - local -r ERROR_MSG='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid, ${nl_}check the config file ${BOLD}${GREEN}\<$PROGNAME.conf\>${OFF}' + local -r ERROR_MSG='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid, ${nl_}check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \${OFF}' local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}' local PARAM_LIST= local config_param local validation_str - + local verbose=$1 + write_error_and_die() { echo -e "\n${DD_BORDER}" echo -e "`eval echo ${ERROR_MSG}`" >&2 @@ -38,109 +37,138 @@ inline_doc exit 1 } + validate_str() { + # This is the 'regexp' test available in bash-3.0.. + # using it as a poor man's test for substring + [[ $verbose = "1" ]] && echo -e "`eval echo $PARAM_VALS`" + if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then + # parameter value entered is no good + write_error_and_die + fi + } + set +e - for PARAM_GROUP in global_PARAM_LIST ${PROGNAME}_PARAM_LIST; do + for PARAM_GROUP in ${PROGNAME}_PARAM_LIST; do for config_param in ${!PARAM_GROUP}; do # This is a tricky little piece of code.. executes a cmd string. - [[ $1 = "1" ]] && echo -e "`eval echo $PARAM_VALS`" case $config_param in BUILDDIR) # We cannot have an or root mount point + [[ $verbose = "1" ]] && echo -e "`eval echo $PARAM_VALS`" if [[ "xx x/x" =~ "x${!config_param}x" ]]; then write_error_and_die fi continue ;; TIMEZONE) continue;; - MKFILE) continue;; - HPKG) validation_str="x0x x1x" ;; - RUNMAKE) validation_str="x0x x1x" ;; - TEST) validation_str="x0x x1x x2x x3x" ;; - STRIP) validation_str="x0x x1x" ;; - VIMLANG) validation_str="x0x x1x" ;; - DEPEND) validation_str="x0x x1x x2x" ;; - MODEL) validation_str="xglibcx xuclibcx" ;; - PAGE) validation_str="xletterx xA4x" ;; - ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ;; - GRSECURITY_HOST) validation_str="x0x x1x" ;; - METHOD) validation_str="xchrootx xbootx";; - *) - echo "WHAT PARAMETER IS THIS.. <<${config_param}>>" - exit - ;; + MKFILE) continue;; + HPKG) validation_str="x0x x1x"; validate_str; continue ;; + RUNMAKE) validation_str="x0x x1x"; validate_str; continue ;; + TEST) validation_str="x0x x1x x2x x3x"; validate_str; continue ;; + STRIP) validation_str="x0x x1x"; validate_str; continue ;; + VIMLANG) validation_str="x0x x1x"; validate_str; continue ;; + DEPEND) validation_str="x0x x1x x2x"; validate_str; continue ;; + MODEL) validation_str="xglibcx xuclibcx"; validate_str; continue ;; + PAGE) validation_str="xletterx xA4x"; validate_str; continue ;; + GRSECURITY_HOST) validation_str="x0x x1x"; validate_str; continue ;; + METHOD) validation_str="xchrootx xbootx"; validate_str; continue ;; + ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax"; validate_str; continue ;; esac - # - # This is the 'regexp' test available in bash-3.0.. - # using it as a poor man's test for substring - if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then - # parameter value entered is no good - write_error_and_die - fi - done # for loop - # No further tests needed on globals - if [[ "$PARAM_GROUP" = "global_PARAM_LIST" ]]; then - - for config_param in LC_ALL LANG; do - [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`" - [[ -z "${!config_param}" ]] && continue + if [[ "${config_param}" = "LC_ALL" ]]; then + [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`" + [[ -z "${!config_param}" ]] && continue # See it the locale values exist on this machine - [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue - - # If you make it this far then there is a problem - write_error_and_die - done - - for config_param in KEYMAP; do - [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`" - [[ "${!config_param}" = "none" ]] && continue - [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] && [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]] && continue - - # If you make it this far then there is a problem - write_error_and_die - done - - # Check out the global param SRC_ARCHIVE - config_param=SRC_ARCHIVE - [[ $1 = "1" ]] && echo -n "`eval echo $PARAM_VALS`" - if [ ! -z ${SRC_ARCHIVE} ]; then - if [ ! -d ${SRC_ARCHIVE} ]; then - echo " -- is NOT a directory" - write_error_and_die - fi - if [ ! -w ${SRC_ARCHIVE} ]; then - echo -n "${nl_} [${BOLD}${YELLOW}WARN$OFF] You do not have access to this directory, ${nl_}${tab_}downloaded files can not be saved in this archive" - fi + if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then + continue + else # If you make it this far then there is a problem + write_error_and_die + fi fi - echo "${nl_} ${BOLD}${GREEN}global parameters are valid${OFF}${nl_}" - continue - fi + + if [[ "${config_param}" = "LANG" ]]; then + [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`" + [[ -z "${!config_param}" ]] && continue + # See it the locale values exist on this machine + if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then + continue + else # If you make it this far then there is a problem + write_error_and_die + fi + fi - for config_param in FSTAB BOOK CONFIG; do - [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`" - if [[ $config_param = BOOK ]]; then + if [[ "${config_param}" = "KEYMAP" ]]; then + [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`" + [[ "${!config_param}" = "none" ]] && continue + if [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] && + [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]]; then + continue + else + write_error_and_die + fi + fi + + if [[ "${config_param}" = "SRC_ARCHIVE" ]]; then + [[ $verbose = "1" ]] && echo -n "`eval echo $PARAM_VALS`" + if [ ! -z ${SRC_ARCHIVE} ]; then + if [ ! -d ${SRC_ARCHIVE} ]; then + echo " -- is NOT a directory" + write_error_and_die + fi + if [ ! -w ${SRC_ARCHIVE} ]; then + echo -n "${nl_} [${BOLD}${YELLOW}WARN$OFF] You do not have access to this directory, ${nl_}${tab_}downloaded files can not be saved in this archive" + fi + fi + echo + continue + fi + + if [[ "${config_param}" = "FSTAB" ]]; then + [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`" + [[ -z "${!config_param}" ]] && continue + if [[ -e "${!config_param}" ]] && + [[ -s "${!config_param}" ]]; then + continue + else + write_error_and_die + fi + fi + + if [[ "${config_param}" = "BOOK" ]]; then + [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`" [[ ! "${WC}" = 1 ]] && continue + [[ -z "${!config_param}" ]] && continue + if [[ -e "${!config_param}" ]] && + [[ -s "${!config_param}" ]]; then + continue + else + write_error_and_die + fi fi - [[ -z "${!config_param}" ]] && continue - [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue - # If you make it this far then there is a problem - write_error_and_die - done - - [[ "$PROGNAME" = "clfs" ]] && - for config_param in BOOT_CONFIG; do - if [[ "${METHOD}" = "boot" ]]; then - [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`" - # There must be a config file when the build method is 'boot' - [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue - # If you make it this far then there is a problem - write_error_and_die + if [[ "${config_param}" = "CONFIG" ]]; then + [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`" + [[ -z "${!config_param}" ]] && continue + if [[ -e "${!config_param}" ]] && + [[ -s "${!config_param}" ]]; then + continue + else + write_error_and_die + fi fi - done - echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} specific parameters are valid${OFF}" + + if [[ "${config_param}" = "BOOT_CONFIG" ]]; then + if [[ "${METHOD}" = "boot" ]]; then + [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`" + # There must be a config file when the build method is 'boot' + [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue + # If you make it this far then there is a problem + write_error_and_die + fi + fi + done done set -e - echo "$tab_***${BOLD}${GREEN}Config parameters look good${OFF}***" + echo "$tab_***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***" }