Changeset cc82e37 for common


Ignore:
Timestamp:
03/28/2006 11:36:52 PM (18 years ago)
Author:
George Boudreau <georgeb@…>
Branches:
experimental
Children:
25b25ef
Parents:
232a860
Message:

common/func_validate_configs.sh, changes internal structure to allow for more flexibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/func_validate_configs.sh

    r232a860 rcc82e37  
    1 
    21# $Id$
    32
     
    1817inline_doc
    1918
    20   local -r  lfs_PARAM_LIST="RUNMAKE STRIP PAGE TIMEZONE VIMLANG"
    21   local -r blfs_PARAM_LIST="DEPEND"
    22   local -r hlfs_PARAM_LIST="RUNMAKE MODEL GRSECURITY_HOST STRIP PAGE TIMEZONE"
    23   local -r clfs_PARAM_LIST="RUNMAKE METHOD ARCH STRIP PAGE TIMEZONE VIMLANG"
    24   local -r global_PARAM_LIST="BUILDDIR HPKG TEST"
     19  local -r  lfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP FSTAB CONFIG"
     20  local -r blfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE TEST LANG DEPEND"
     21  local -r hlfs_PARAM_LIST="BUILDDIR SRC_ARCHIVE HPKG RUNMAKE TEST STRIP PAGE TIMEZONE VIMLANG LC_ALL LANG KEYMAP FSTAB CONFIG MODEL GRSECURITY_HOST"
     22  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"
    2523
    26   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}'
     24  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 \<common/config\>${OFF}'
    2725  local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
    2826
     
    3129  local config_param
    3230  local validation_str
    33 
     31  local verbose=$1
     32 
    3433  write_error_and_die() {
    3534    echo -e "\n${DD_BORDER}"
     
    3938  }
    4039
     40  validate_str() {
     41     # This is the 'regexp' test available in bash-3.0..
     42     # using it as a poor man's test for substring
     43     [[ $verbose = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
     44     if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
     45       # parameter value entered is no good
     46       write_error_and_die
     47     fi
     48  }
     49 
    4150  set +e
    42   for PARAM_GROUP in global_PARAM_LIST ${PROGNAME}_PARAM_LIST; do
     51  for PARAM_GROUP in ${PROGNAME}_PARAM_LIST; do
    4352    for config_param in ${!PARAM_GROUP}; do
    4453      # This is a tricky little piece of code.. executes a cmd string.
    45       [[ $1 = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
    4654      case $config_param in
    4755        BUILDDIR) # We cannot have an <empty> or </> root mount point
     56            [[ $verbose = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
    4857            if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
    4958              write_error_and_die
     
    5160            continue  ;;
    5261        TIMEZONE)  continue;;
    53         MKFILE)    continue;;
    54         HPKG)      validation_str="x0x x1x"  ;;
    55         RUNMAKE)   validation_str="x0x x1x"  ;;
    56         TEST)      validation_str="x0x x1x x2x x3x"  ;;
    57         STRIP)     validation_str="x0x x1x"  ;;
    58         VIMLANG)   validation_str="x0x x1x"  ;;
    59         DEPEND)    validation_str="x0x x1x x2x" ;;
    60         MODEL)     validation_str="xglibcx xuclibcx" ;;
    61         PAGE)      validation_str="xletterx xA4x"  ;;
    62         ARCH)      validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ;;
    63         GRSECURITY_HOST)  validation_str="x0x x1x"  ;;
    64         METHOD)      validation_str="xchrootx xbootx";;
    65         *)
    66           echo "WHAT PARAMETER IS THIS.. <<${config_param}>>"
    67           exit
    68         ;;
     62        MKFILE)    continue;;
     63        HPKG)      validation_str="x0x x1x";          validate_str; continue ;;
     64        RUNMAKE)   validation_str="x0x x1x";          validate_str; continue ;;
     65        TEST)      validation_str="x0x x1x x2x x3x";  validate_str; continue ;;
     66        STRIP)     validation_str="x0x x1x";          validate_str; continue ;;
     67        VIMLANG)   validation_str="x0x x1x";          validate_str; continue ;;
     68        DEPEND)    validation_str="x0x x1x x2x";      validate_str; continue ;;
     69        MODEL)     validation_str="xglibcx xuclibcx"; validate_str; continue ;;
     70        PAGE)      validation_str="xletterx xA4x";    validate_str; continue ;;
     71        GRSECURITY_HOST)  validation_str="x0x x1x";   validate_str; continue ;;
     72        METHOD)    validation_str="xchrootx xbootx";  validate_str; continue ;;
     73        ARCH)      validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax";  validate_str; continue ;;
    6974      esac
    70         #
    71         # This is the 'regexp' test available in bash-3.0..
    72         # using it as a poor man's test for substring
    73       if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
    74         # parameter value entered is no good
    75         write_error_and_die
    76       fi
    77     done # for loop
    7875
    7976
    80       # No further tests needed on globals
    81     if [[ "$PARAM_GROUP" = "global_PARAM_LIST" ]]; then
     77      if [[ "${config_param}" = "LC_ALL" ]]; then
     78         [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
     79         [[ -z "${!config_param}" ]] && continue
     80          # See it the locale values exist on this machine
     81         if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then
     82           continue
     83         else  # If you make it this far then there is a problem
     84           write_error_and_die
     85         fi
     86      fi
    8287
    83       for config_param in LC_ALL LANG; do
    84         [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
    85         [[ -z "${!config_param}" ]] && continue
     88      if [[ "${config_param}" = "LANG" ]]; then
     89         [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
     90         [[ -z "${!config_param}" ]] && continue
    8691          # See it the locale values exist on this machine
    87         [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue
     92         if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then
     93           continue
     94         else  # If you make it this far then there is a problem
     95           write_error_and_die
     96         fi
     97      fi     
    8898
    89           # If you make it this far then there is a problem
    90         write_error_and_die
    91       done
    9299
    93       for config_param in KEYMAP; do
    94         [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
    95         [[ "${!config_param}" = "none" ]] && continue
    96         [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] && [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]] && continue
     100      if [[ "${config_param}"  = "KEYMAP" ]]; then
     101         [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
     102         [[ "${!config_param}" = "none" ]] && continue
     103         if [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] &&
     104            [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]]; then
     105            continue
     106         else
     107            write_error_and_die
     108         fi
     109      fi
    97110
    98           # If you make it this far then there is a problem
    99         write_error_and_die
    100       done
     111      if [[ "${config_param}" = "SRC_ARCHIVE" ]]; then
     112         [[ $verbose = "1" ]] && echo -n "`eval echo $PARAM_VALS`"
     113         if [ ! -z ${SRC_ARCHIVE} ]; then
     114           if [ ! -d ${SRC_ARCHIVE} ]; then
     115             echo "   -- is NOT a directory"
     116             write_error_and_die
     117           fi
     118           if [ ! -w ${SRC_ARCHIVE} ]; then
     119             echo -n "${nl_} [${BOLD}${YELLOW}WARN$OFF] You do not have <write> access to this directory, ${nl_}${tab_}downloaded files can not be saved in this archive"
     120           fi
     121        fi
     122        echo
     123        continue
     124      fi
    101125
    102       # Check out the global param SRC_ARCHIVE
    103       config_param=SRC_ARCHIVE
    104       [[ $1 = "1" ]] && echo -n "`eval echo $PARAM_VALS`"
    105       if [ ! -z ${SRC_ARCHIVE} ]; then
    106         if [ ! -d ${SRC_ARCHIVE} ]; then
    107           echo "   -- is NOT a directory"
    108           write_error_and_die
    109         fi
    110         if [ ! -w ${SRC_ARCHIVE} ]; then
    111           echo -n "${nl_} [${BOLD}${YELLOW}WARN$OFF] You do not have <write> access to this directory, ${nl_}${tab_}downloaded files can not be saved in this archive"
     126      if [[ "${config_param}" = "FSTAB" ]]; then
     127         [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
     128         [[ -z "${!config_param}" ]] && continue
     129         if [[ -e "${!config_param}" ]] &&
     130            [[ -s "${!config_param}" ]]; then
     131           continue
     132         else
     133           write_error_and_die
     134         fi
     135      fi
     136
     137      if [[ "${config_param}" = "BOOK" ]]; then
     138         [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
     139         [[ ! "${WC}" = 1 ]] && continue
     140         [[ -z "${!config_param}" ]] && continue
     141         if [[ -e "${!config_param}" ]] &&
     142            [[ -s "${!config_param}" ]]; then
     143           continue
     144         else
     145           write_error_and_die
     146         fi
     147      fi
     148
     149      if [[ "${config_param}" = "CONFIG" ]]; then
     150         [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
     151         [[ -z "${!config_param}" ]] && continue
     152         if [[ -e "${!config_param}" ]] &&
     153            [[ -s "${!config_param}" ]]; then
     154           continue
     155         else
     156           write_error_and_die
     157         fi
     158      fi
     159
     160      if [[ "${config_param}" = "BOOT_CONFIG" ]]; then
     161        if [[ "${METHOD}" = "boot" ]]; then
     162           [[ $verbose = "1" ]] && echo "`eval echo $PARAM_VALS`"
     163           # There must be a config file when the build method is 'boot'
     164           [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
     165           # If you make it this far then there is a problem
     166          write_error_and_die
    112167        fi
    113168      fi
    114       echo  "${nl_}   ${BOLD}${GREEN}global parameters are valid${OFF}${nl_}"
    115       continue
    116     fi
    117 
    118 
    119     for config_param in FSTAB BOOK CONFIG; do
    120       [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
    121       if [[ $config_param = BOOK ]]; then
    122          [[ ! "${WC}" = 1 ]] && continue
    123       fi
    124       [[ -z "${!config_param}" ]] && continue
    125       [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
    126 
    127       # If you make it this far then there is a problem
    128       write_error_and_die
    129     done
    130 
    131     [[ "$PROGNAME" = "clfs" ]] &&
    132     for config_param in BOOT_CONFIG; do
    133       if [[ "${METHOD}" = "boot" ]]; then
    134         [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
    135           # There must be a config file when the build method is 'boot'
    136         [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
    137           # If you make it this far then there is a problem
    138         write_error_and_die
    139       fi
    140     done
    141     echo "   ${BOLD}${GREEN}${PARAM_GROUP%%_*T} specific parameters are valid${OFF}"
     169  done
    142170  done
    143171
    144172  set -e
    145   echo "$tab_***${BOLD}${GREEN}Config parameters look good${OFF}***"
     173  echo "$tab_***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***"
    146174}
Note: See TracChangeset for help on using the changeset viewer.