checks 4.52 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
8
# Copyright 2007 - 2018 Christopher Bratusek		#
9 10 11 12
#							#
#########################################################

check () {
13

14
	for dir in ${PATH//:/ }; do
15
		[[ -x ${dir}/${1} ]] && (echo found && continue 2)
16
	done
17

18 19
}

20 21
check_helper () {

22 23 24 25 26 27 28 29 30 31 32 33
	[[ "${APPS[*]}" ]] && (section_message APP && check_apps "false" "${APPS[@]}")
	[[ "${OPT_APPS[*]}" ]] && (section_message OPT_APP && check_apps "true" "${OPT_APPS[@]}")
	[[ "${SAPPS[*]}" ]] && (section_message SBINAPP && check_apps "false" "${SAPPS[@]}")
	[[ "${OPT_SAPPS[*]}" ]] && (section_message OPT_SBINAPP && check_apps "true" "${OPT_SAPPS[@]}")
	[[ "${BUILD[*]}" ]] && (section_message BUILD && check_apps "false" "${BUILD[@]}")
	[[ "${PYMODS[*]}" ]] && check_python
	[[ "${PYMODS[*]}" ]] && (section_message PYMOD && check_pymods "false" "${PYMODS[@]}")
	[[ "${OPT_PYMODS[*]}" ]] && (section_message OPT_PYMOD && check_pymods "true" "${OPT_PYMODS[@]}")
	[[ "${LIBS[*]}" ]] && (section_message LIB && check_libs "false" "${LIBS[@]}")
	[[ "${OPT_LIBS[*]}" ]] && (section_message OPT_LIB && check_libs "false" "${OPT_LIBS[@]}")
	[[ "${GIR[*]}" ]] && (section_message GIR && check_gir "false" "${GIR[@]}")
	[[ "${OPT_GIR[*]}" ]] && (section_message OPT_GIR && check_gir "false" "${OPT_GIR[@]}")
34 35 36

}

37 38
check_apps () {

39 40 41 42 43 44
	OPT=${1}
	shift

	for ARG in "${@}"; do
		APP="${ARG/:*}"
		DESC="${ARG/*:}"
45
		DEP_RETURN=$(check "${APP}")
46
		if [[ ${DEP_RETURN} == *found* ]]; then
47
			ok_message "${APP}"
48
		elif [[ ${DEP_RETURN} != *found* && ${OPT} == true ]]; then
49
			warn_message "${APP}" "${DESC}"
50
			MISSING+=" ${APP}"
51 52
		else 	fail_message m "${APP}"
			kill -s TERM "${TOP_PID}"
53 54
		fi
	done
55 56 57 58

}

check_libs () {
59

60 61
	OPT=${1}
	shift
62

63
	for ARG in "${@}"; do
64

65 66 67 68
		LIB=$(gawk -F : '{print $1}' <(echo "${ARG}"))
		VERSION=$(gawk -F : '{print $2}' <(echo "${ARG}"))
		PC_FILE=$(gawk -F : '{print $3}' <(echo "${ARG}"))
		DESC=$(gawk -F : '{print $4}' <(echo "${ARG}"))
69

70
		pkg-config --exists "${PC_FILE}"
71
		EXIST_RETURN=$?
72

73
		pkg-config --atleast-version="${VERSION}" "${PC_FILE}"
74
		DEP_RETURN=$?
75

76
		if [[ ${EXIST_RETURN} != 0 && ! ${OPT} == true ]]; then
77 78
			fail_message m "${LIB}"
			kill -s TERM "${TOP_PID}"
79
		elif [[ ${DEP_RETURN} == 0 ]]; then
80
			ok_message "${LIB}" "${VERSION}"+
81
		elif [[ ${EXIST_RETURN} != 0 && ${OPT} == true ]]; then
82 83 84 85
			warn_message "${LIB}" "${DESC}"
			MISSING+=" ${LIB}"
		else	fail_message o "${LIB}" "${VERSION}"
			kill -s TERM "${TOP_PID}"
86
		fi
87

88
	done
89 90 91

}

92 93
check_gir () {

94 95 96 97 98
	OPT=${1}
	shift

	for ARG in "${@}"; do

99 100 101 102 103
		GIR=$(gawk -F : '{print $1}' <(echo "${ARG}"))
		VERSION=$(gawk -F : '{print $2}' <(echo "${ARG}"))
		TYPE_LIB=$(gawk -F : '{print $3}' <(echo "${ARG}"))
		DESC=$(gawk -F : '{print $4}' <(echo "${ARG}"))
		FILE=$(basename "${GIRPATH}"/"${TYPE_LIB}"* .typelib 2>/dev/null)
104 105 106

		if [[ $FILE != ".typelib" ]]; then
			EXIST_RETURN=0
107
			XVER=$(gawk -F - '{print $2}' <(echo "${FILE}"))
108 109 110 111
			DEP_RETURN=$(echo "$XVER >= ${VERSION}" | bc)
		fi

		if [[ ${EXIST_RETURN} != 0 && ! ${OPT} == true ]]; then
112 113
			fail_message m "${GIR}"
			kill -s TERM "${TOP_PID}"
114
		elif [[ ${DEP_RETURN} == 1 ]]; then
115
			ok_message "${GIR}" "${VERSION}"+
116
		elif [[ ${EXIST_RETURN} != 0 && ${OPT} == true ]]; then
117
			warn_message "${GIR}" "${DESC}"
118
			MISSING+=" ${GIR}"
119 120
		else	fail_message o "${GIR}" "${VERSION}"
			kill -s TERM "${TOP_PID}"
121
		fi
122

123
	done
124 125 126

}

127 128
check_python () {

129 130 131 132
	section_message PY

	if [[ ! -x ${PYTHON} ]]; then
		fail_message p
133
		kill -s TERM "${TOP_PID}"
134
	else
135
		PYVER=$(${PYTHON} --version 2>&1 | gawk '{ gsub(/\./,""); gsub(/\+/,""); gsub(/rc.*/,""); print $2 }')
136
		if [[ ${PYVER:0:3} -lt ${PYMINVER} ]]; then
137
			fail_message p-
138
			kill -s TERM "${TOP_PID}"
139
		elif [[ ${PYVER:0:3} -gt ${PYMAXVER} ]]; then
140
			fail_message p+
141
			kill -s TERM "${TOP_PID}"
142 143 144
		else
			ok_message Python
		fi
145 146 147 148
	fi

}

149 150
check_pymods () {

151 152 153 154 155
	OPT=${1}
	shift

	for ARG in "${@}"; do

156 157 158
		MOD=$(gawk -F : '{print $1}' <(echo "${ARG}"))
		SMOD=$(gawk -F : '{print $2}' <(echo "${ARG}"))
		DESC=$(gawk -F : '{print $3}' <(echo "${ARG}"))
159 160 161 162 163 164 165 166 167 168 169 170 171 172

		if [[ ${SMOD} ]]; then
			DEP="${SMOD} (${MOD})"
			${PYTHON} -c "from ${MOD} import ${SMOD}" 2>/dev/null
		else
			DEP="${MOD}"
			${PYTHON} -c "import imp
imp.find_module('${MOD}')" 2>/dev/null
		fi

		DEP_RETURN=$?
		if [[ ${DEP_RETURN} == 0 ]]; then
			ok_message "${DEP}"
		elif [[ ${DEP_RETURN} != 0 && ${OPT} == true ]]; then
173
			warn_message "${DEP}" "${DESC}"
174
			MISSING+=" ${DEP}"
175 176
		else 	fail_message m "${DEP}"
			kill -s TERM "${TOP_PID}"
177
		fi
178

179
	done
180

181
}