source: common/func_validate_configs.sh@ c0aeabe

experimental
Last change on this file since c0aeabe was c0aeabe, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Testing svn:keywords expansion.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1# $Id$
2# $Author$$Rev$$Date$
3#----------------------------#
4validate_config() { # Are the config values sane (within reason)
5#----------------------------#
6: <<inline_doc
7 Validates the configuration parameters. The global var PROGNAME selects the
8 parameter list.
9
10 input vars: none
11 externals: color constants
12 PROGNAME (lfs,clfs,hlfs,blfs)
13 modifies: none
14 returns: nothing
15 on error: write text to console and dies
16 on success: write text to console and returns
17inline_doc
18
19 local svn_tracking='$Id$'
20 local -r lfs_PARAM_LIST="BUILDDIR HPKG TEST TOOLCHAINTEST STRIP VIMLANG PAGE RUNMAKE"
21 local -r blfs_PARAM_LIST="BUILDDIR TEST DEPEND"
22 local -r hlfs_PARAM_LIST="BUILDDIR HPKG MODEL TEST TOOLCHAINTEST STRIP VIMLANG PAGE GRSECURITY_HOST RUNMAKE TIMEZONE"
23 local -r clfs_PARAM_LIST="ARCH BOOTMINIMAL RUNMAKE MKFILE"
24 local -r global_PARAM_LIST="BUILDDIR HPKG RUNMAKE TEST TOOLCHAINTEST STRIP PAGE TIMEZONE VIMLANG"
25
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}'
27 local -r PARAM_VALS='${config_param}: ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
28
29 local PARAM_LIST=
30
31 local config_param
32 local validation_str
33
34 write_error_and_die() {
35 echo -e "\n${DD_BORDER}"
36 echo -e "`eval echo ${ERROR_MSG}`" >&2
37 echo -e "${DD_BORDER}\n"
38 exit 1
39 }
40
41 set +e
42 for PARAM_GROUP in global_PARAM_LIST ${PROGNAME}_PARAM_LIST; do
43 for config_param in ${!PARAM_GROUP}; do
44 # This is a tricky little piece of code.. executes a cmd string.
45 [[ $1 = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
46 case $config_param in
47 BUILDDIR) # We cannot have an <empty> or </> root mount point
48 if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
49 write_error_and_die
50 fi
51 continue ;;
52 TIMEZONE) continue;;
53 MKFILE) continue;;
54 HPKG) validation_str="x0x x1x" ;;
55 RUNMAKE) validation_str="x0x x1x" ;;
56 TEST) validation_str="x0x x1x" ;;
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 xalphax" ;;
63 TOOLCHAINTEST) validation_str="x0x x1x" ;;
64 GRSECURITY_HOST) validation_str="x0x x1x" ;;
65 BOOTMINIMAL) validation_str="x0x x1x";;
66 *)
67 echo "WHAT PARAMETER IS THIS.. <<${config_param}>>"
68 exit
69 ;;
70 esac
71 #
72 # This is the 'regexp' test available in bash-3.0..
73 # using it as a poor man's test for substring
74 if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
75 # parameter value entered is no good
76 write_error_and_die
77 fi
78 done # for loop
79
80 # Not further tests needed on globals
81 if [[ "$PARAM_GROUP" = "global_PARAM_LIST" ]]; then
82 echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} parameters are valid${OFF}"
83 continue
84 fi
85
86 for config_param in LC_ALL LANG; do
87 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
88 [[ -z "${!config_param}" ]] && continue
89 # See it the locale values exist on this machine
90 [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue
91
92 # If you make it this far then there is a problem
93 write_error_and_die
94 done
95
96 for config_param in FSTAB CONFIG KEYMAP BOOK; do
97 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
98 if [[ $config_param = BOOK ]]; then
99 [[ ! "${WC}" = 1 ]] && continue
100 fi
101 [[ -z "${!config_param}" ]] && continue
102 [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
103
104 # If you make it this far then there is a problem
105 write_error_and_die
106 done
107 echo " ${BOLD}${GREEN}${PARAM_GROUP%%_*T} parameters are valid${OFF}"
108 done
109 set -e
110 echo "$tab_***${BOLD}${GREEN}Config parameters look good${OFF}***"
111}
Note: See TracBrowser for help on using the repository browser.