source: common/func_validate_configs.sh@ bd99331

experimental
Last change on this file since bd99331 was 4fcc4d4, checked in by George Boudreau <georgeb@…>, 19 years ago

common/func_validate_configs.sh, ADDED ppc64 as a valid architecture

  • Property mode set to 100644
File size: 5.3 KB
Line 
1
2# $Id$
3
4#----------------------------#
5validate_config() { # Are the config values sane (within reason)
6#----------------------------#
7: <<inline_doc
8 Validates the configuration parameters. The global var PROGNAME selects the
9 parameter list.
10
11 input vars: $1 0/1 0=quiet, 1=verbose output
12 externals: color constants
13 PROGNAME (lfs,clfs,hlfs,blfs)
14 modifies: none
15 returns: nothing
16 on error: write text to console and dies
17 on success: write text to console and returns
18inline_doc
19
20 local -r lfs_PARAM_LIST="VIMLANG"
21 local -r blfs_PARAM_LIST="TEST DEPEND"
22 local -r hlfs_PARAM_LIST="MODEL GRSECURITY_HOST"
23 local -r clfs_PARAM_LIST="ARCH METHOD VIMLANG"
24 local -r global_PARAM_LIST="BUILDDIR HPKG RUNMAKE TEST STRIP PAGE TIMEZONE"
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 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 ;;
69 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
78
79
80 # No further tests needed on globals
81 if [[ "$PARAM_GROUP" = "global_PARAM_LIST" ]]; then
82
83 for config_param in LC_ALL LANG; do
84 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
85 [[ -z "${!config_param}" ]] && continue
86 # See it the locale values exist on this machine
87 [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue
88
89 # If you make it this far then there is a problem
90 write_error_and_die
91 done
92
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
97
98 # If you make it this far then there is a problem
99 write_error_and_die
100 done
101
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"
112 fi
113 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}"
142 done
143
144 set -e
145 echo "$tab_***${BOLD}${GREEN}Config parameters look good${OFF}***"
146}
Note: See TracBrowser for help on using the repository browser.