summaryrefslogtreecommitdiffhomepage
path: root/subr/pre_prereqs.subr
blob: c5a965b3eb39d5abcc0cd26609d87e5a23988752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#
# . ./build.vars and set -o errexit -o noglob are assumed.
#

pre_prereqs() {
	for __ in ${CHECK_PATH_VARS}; do
		if [ -z "${___:=$(get_var_unsafe "${__}")}" ]; then
			log_msg failexit "Error: variable \`${__}' is empty or unset.";
		elif [ "${___#* *}" != "${___}" ]; then
			log_msg failexit "Error: variable \`${__}' contains one or more whitespace characters.";
		fi;
	done;
	for __ in ${CHECK_PREREQ_CMDS} $(eval echo ${CHECK_PREREQ_FILES_DYNAMIC}) ${CHECK_PREREQ_FILES}; do
		if [ "${__#/}" != "${__}" ]; then
			if [ ! -e "${__}" ]; then
				log_msg fail "Error: missing prerequisite file \`${__}'.";
				__exit=1;
			fi;
		else
			if ! test_cmd "${__}"; then
				log_msg fail "Error: missing prerequisite command \`${__}'.";
				__exit=1;
			fi;
		fi;
	done;
	for __ in ${CHECK_PREREQ_PERL_MODULES}; do
		if ! perl -M"${__}" -e "" 2>/dev/null; then
			log_msg fail "Error: missing prerequisite Perl module \`${__}'.";
			__exit=1;
		fi;
	done;
	if [ ${__exit:-0} = 1 ]; then
		exit 1;
	elif [ -n "${__exit}" ]; then
		unset __exit;
	fi;
};

# vim:filetype=sh