Changeset b1c7734 for common/func_validate_configs.sh
- Timestamp:
- 04/13/2006 04:20:14 PM (18 years ago)
- Branches:
- experimental
- Children:
- 18911500
- Parents:
- 21530e9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/func_validate_configs.sh
r21530e9 rb1c7734 1 1 # $Id$ 2 2 3 validate_target() { 4 3 #----------------------------# 4 validate_target() { # 5 #----------------------------# 5 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' 6 7 local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}' … … 70 71 71 72 #----------------------------# 72 validate_config() {# Are the config values sane (within reason)73 validate_config() { # Are the config values sane (within reason) 73 74 #----------------------------# 74 75 : <<inline_doc … … 107 108 } 108 109 109 validate_ str() {110 validate_against_str() { 110 111 # This is the 'regexp' test available in bash-3.0.. 111 112 # using it as a poor man's test for substring 112 113 echo -e "`eval echo $PARAM_VALS`" 113 if [[ ! "$ {validation_str}" =~ "x${!config_param}x" ]] ; then114 if [[ ! "$1" =~ "x${!config_param}x" ]] ; then 114 115 # parameter value entered is no good 115 116 write_error_and_die … … 117 118 } 118 119 120 validate_file() { 121 # For parameters ending with a '+' failure causes a warning message only 122 echo -n "`eval echo $PARAM_VALS`" 123 while test $# -gt 0 ; do 124 case $1 in 125 # Failures caused program exit 126 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO file name given" && write_error_and_die ;; 127 "-e") [[ ! -e "${!config_param}" ]] && echo "${tab_}<-- file does not exist" && write_error_and_die ;; 128 "-s") [[ ! -s "${!config_param}" ]] && echo "${tab_}<-- file has zero bytes" && write_error_and_die ;; 129 "-r") [[ ! -r "${!config_param}" ]] && echo "${tab_}<-- no read permission " && write_error_and_die ;; 130 "-w") [[ ! -w "${!config_param}" ]] && echo "${tab_}<-- no write permission" && write_error_and_die ;; 131 "-x") [[ ! -x "${!config_param}" ]] && echo "${tab_}<-- file cannot be executed" && write_error_and_die ;; 132 # Warning messages only 133 "-z+") [[ -z "${!config_param}" ]] && echo && return ;; 134 esac 135 shift 1 136 done 137 echo 138 } 139 140 validate_dir() { 141 # For parameters ending with a '+' failure causes a warning message only 142 echo -n "`eval echo $PARAM_VALS`" 143 while test $# -gt 0 ; do 144 case $1 in 145 "-z") [[ -z "${!config_param}" ]] && echo "${tab_}NO directory name given" && write_error_and_die ;; 146 "-d") [[ ! -d "${!config_param}" ]] && echo "${tab_}This is NOT a directory" && write_error_and_die ;; 147 "-w") if [[ ! -w "${!config_param}" ]]; then 148 echo "${nl_}${DD_BORDER}" 149 echo "${tab_}${RED}You do not have ${L_arrow}write${R_arrow}${RED} access to the directory${OFF}" 150 echo "${tab_}${BOLD}${!config_param}${OFF}" 151 echo "${DD_BORDER}${nl_}" 152 exit 1 153 fi ;; 154 # Warnings only 155 "-w+") if [[ ! -w "${!config_param}" ]]; then 156 echo "${nl_}${DD_BORDER}" 157 echo "${tab_}WARNING-- You do not have ${L_arrow}write${R_arrow} access to the directory${OFF}" 158 echo "${tab_} -- ${BOLD}${!config_param}${OFF}" 159 echo "${DD_BORDER}" 160 fi ;; 161 "-z+") [[ -z "${!config_param}" ]] && echo "${tab_}<-- NO directory name given" && return 162 esac 163 shift 1 164 done 165 echo 166 } 167 119 168 set +e 120 for PARAM_GROUP in ${PROGNAME}_PARAM_LIST; do 121 for config_param in ${!PARAM_GROUP}; do 122 # This is a tricky little piece of code.. executes a cmd string. 123 case $config_param in 124 BUILDDIR) # We cannot have an <empty> or </> root mount point 125 echo -e "`eval echo $PARAM_VALS`" 126 if [[ "xx x/x" =~ "x${!config_param}x" ]]; then 127 write_error_and_die 128 fi 129 continue ;; 130 TIMEZONE) continue;; 131 MKFILE) continue;; 132 HPKG) validation_str="x0x x1x"; validate_str; continue ;; 133 RUNMAKE) validation_str="x0x x1x"; validate_str; continue ;; 134 135 COMPARE) if [[ ! "$COMPARE" = "1" ]]; then 136 validation_str="x0x x1x"; validate_str 137 else 138 if [[ ! "${RUN_ICA}" = "1" ]] && [[ ! "${RUN_FARCE}" = "1" ]]; then 139 echo "${nl_}${DD_BORDER}" 140 echo "You have elected to analyse the build but have failed to select a tool." >&2 141 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 142 echo "${DD_BORDER}${nl_}" 143 exit 1 144 fi 169 PARAM_GROUP=${PROGNAME}_PARAM_LIST 170 for config_param in ${!PARAM_GROUP}; do 171 # This is a tricky little piece of code.. executes a cmd string. 172 case $config_param in 173 BUILDDIR) # We cannot have an <empty> or </> root mount point 174 echo -e "`eval echo $PARAM_VALS`" 175 [[ "xx x/x" =~ "x${!config_param}x" ]] && 176 write_error_and_die 177 ;; 178 TIMEZONE) ;; 179 180 # Validate general parameters.. 181 HPKG) validate_against_str "x0x x1x" ;; 182 RUNMAKE) validate_against_str "x0x x1x" ;; 183 COMPARE) if [[ ! "$COMPARE" = "1" ]]; then 184 validate_against_str "x0x x1x" 185 else 186 if [[ ! "${RUN_ICA}" = "1" ]] && [[ ! "${RUN_FARCE}" = "1" ]]; then 187 echo "${nl_}${DD_BORDER}" 188 echo "You have elected to analyse your build but have failed to select a tool." >&2 189 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 190 echo "${DD_BORDER}${nl_}" 191 exit 1 145 192 fi 146 continue ;; 147 RUN_ICA) [[ "$COMPARE" = "1" ]] && validation_str="x0x x1x" && validate_str 148 continue ;; 149 RUN_FARCE) [[ "$COMPARE" = "1" ]] && validation_str="x0x x1x" && validate_str 150 continue ;; 151 ITERATIONS) [[ "$COMPARE" = "1" ]] && validation_str="x2x x3x x4x x5x" && validate_str 152 continue ;; 153 154 TEST) validation_str="x0x x1x x2x x3x"; validate_str; continue ;; 155 STRIP) validation_str="x0x x1x"; validate_str; continue ;; 156 VIMLANG) validation_str="x0x x1x"; validate_str; continue ;; 157 DEPEND) validation_str="x0x x1x x2x"; validate_str; continue ;; 158 MODEL) validation_str="xglibcx xuclibcx"; validate_str; continue ;; 159 PAGE) validation_str="xletterx xA4x"; validate_str; continue ;; 160 GRSECURITY_HOST) validation_str="x0x x1x"; validate_str; continue ;; 161 METHOD) validation_str="xchrootx xbootx"; validate_str; continue ;; 162 ARCH) validation_str="xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax"; validate_str; continue ;; 163 TARGET) validate_target; continue ;; 164 esac 165 166 if [[ "${config_param}" = "LC_ALL" ]]; then 167 echo "`eval echo $PARAM_VALS`" 168 [[ -z "${!config_param}" ]] && echo -e "\nVariable LC_ALL cannot be empty!" && write_error_and_die 169 # See it the locale values exist on this machine 170 if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then 171 continue 172 else # If you make it this far then there is a problem 173 write_error_and_die 174 fi 175 fi 176 177 if [[ "${config_param}" = "LANG" ]]; then 178 echo "`eval echo $PARAM_VALS`" 179 [[ -z "${!config_param}" ]] && echo -e "\nVariable LANG cannot be empty!" && write_error_and_die 180 # See it the locale values exist on this machine 181 if [[ "`locale -a | grep -c ${!config_param}`" > 0 ]]; then 182 continue 183 else # If you make it this far then there is a problem 184 write_error_and_die 185 fi 186 fi 187 188 189 if [[ "${config_param}" = "KEYMAP" ]]; then 190 echo "`eval echo $PARAM_VALS`" 191 [[ "${!config_param}" = "none" ]] && continue 192 if [[ -e "/usr/share/kbd/keymaps/${!config_param}" ]] && 193 [[ -s "/usr/share/kbd/keymaps/${!config_param}" ]]; then 194 continue 195 else 196 write_error_and_die 197 fi 198 fi 199 200 if [[ "${config_param}" = "SRC_ARCHIVE" ]]; then 201 echo -n "`eval echo $PARAM_VALS`" 202 if [ ! -z ${SRC_ARCHIVE} ]; then 203 if [ ! -d ${SRC_ARCHIVE} ]; then 204 echo " -- is NOT a directory" 205 write_error_and_die 206 fi 207 if [ ! -w ${SRC_ARCHIVE} ]; then 208 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" 209 fi 210 fi 211 echo 212 continue 213 fi 214 215 if [[ "${config_param}" = "FSTAB" ]]; then 216 echo "`eval echo $PARAM_VALS`" 217 [[ -z "${!config_param}" ]] && continue 218 if [[ -e "${!config_param}" ]] && 219 [[ -s "${!config_param}" ]]; then 220 continue 221 else 222 write_error_and_die 223 fi 224 fi 225 226 if [[ "${config_param}" = "BOOK" ]]; then 227 echo "`eval echo $PARAM_VALS`" 228 [[ ! "${WC}" = 1 ]] && continue 229 [[ -z "${!config_param}" ]] && continue 230 if [[ -e "${!config_param}" ]] && 231 [[ -s "${!config_param}" ]]; then 232 continue 233 else 234 write_error_and_die 235 fi 236 fi 237 238 if [[ "${config_param}" = "CONFIG" ]]; then 239 echo "`eval echo $PARAM_VALS`" 240 [[ -z "${!config_param}" ]] && continue 241 if [[ -e "${!config_param}" ]] && 242 [[ -s "${!config_param}" ]]; then 243 continue 244 else 245 write_error_and_die 246 fi 247 fi 248 249 if [[ "${config_param}" = "BOOT_CONFIG" ]]; then 250 if [[ "${METHOD}" = "boot" ]]; then 251 echo "`eval echo $PARAM_VALS`" 252 # There must be a config file when the build method is 'boot' 253 [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue 254 # If you make it this far then there is a problem 255 write_error_and_die 256 fi 257 fi 258 done 193 fi ;; 194 RUN_ICA) [[ "$COMPARE" = "1" ]] && validate_against_str "x0x x1x" ;; 195 RUN_FARCE) [[ "$COMPARE" = "1" ]] && validate_against_str "x0x x1x" ;; 196 ITERATIONS) [[ "$COMPARE" = "1" ]] && validate_against_str "x2x x3x x4x x5x" ;; 197 TEST) validate_against_str "x0x x1x x2x x3x" ;; 198 STRIP) validate_against_str "x0x x1x" ;; 199 VIMLANG) validate_against_str "x0x x1x" ;; 200 DEPEND) validate_against_str "x0x x1x x2x" ;; 201 MODEL) validate_against_str "xglibcx xuclibcx" ;; 202 PAGE) validate_against_str "xletterx xA4x" ;; 203 METHOD) validate_against_str "xchrootx xbootx" ;; 204 ARCH) validate_against_str "xx86x xx86_64x xx86_64-64x xsparcx xsparcv8x xsparc64x xsparc64-64x xmipsx xmips64x xmips64-64x xppcx xppc64x xalphax" ;; 205 TARGET) validate_target ;; 206 GRSECURITY_HOST) validate_against_str "x0x x1x" ;; 207 208 # Validate directories, testable states: 209 # fatal -z -d -w, 210 # warning -z+ -w+ 211 SRC_ARCHIVE) validate_dir -z+ -d -w+ ;; 212 213 # Validate files, testable states: 214 # fatal -z -e -s -w -x -r, 215 # warning -z+ 216 FSTAB) validate_file -z+ -e -s ;; 217 CONFIG) validate_file -z+ -e -s ;; 218 BOOK) [[ "${WC}" = 1 ]] && validate_file -z -e -s ;; 219 BOOT_CONFIG) [[ "${METHOD}" = "boot" ]] && validate_file -z -e -s ;; 220 221 # Treatment of 'special' parameters 222 LANG | \ 223 LC_ALL) # See it the locale values exist on this machine 224 echo -n "`eval echo $PARAM_VALS`" 225 [[ -z "${!config_param}" ]] && 226 echo " -- Variable $config_param cannot be empty!" && 227 write_error_and_die 228 [[ ! "`locale -a | grep -c ${!config_param}`" > 0 ]] && 229 write_error_and_die 230 echo 231 ;; 232 KEYMAP) [[ ! "${!config_param}" = "none" ]] && 233 KEYMAP="/usr/share/kbd/keymaps/${KEYMAP}" && 234 validate_file -z -e -s 235 ;; 236 esac 259 237 done 260 261 238 set -e 262 239 echo "$tab_***${BOLD}${GREEN} ${PARAM_GROUP%%_*T} config parameters look good${OFF} ***"
Note:
See TracChangeset
for help on using the changeset viewer.