chan_vpb: Fix a gcc 7 out-of-bounds complaint
[asterisk/asterisk.git] / build_tools / list_valid_installed_externals
1 #!/usr/bin/env bash
2
3 if [[ ( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} > 1 ) || ${BASH_VERSINFO[0]} > 4 ]] ; then
4         shopt -s compat41
5 fi
6 set -e
7
8 ASTTOPDIR=${ASTTOPDIR:-.}
9 export make=`sed -n -r -e "s/^MAKE\s*=\s*//gp" ${ASTTOPDIR}/makeopts`
10
11 getvar() {
12         $make --quiet --no-print-directory -f- <<EOF
13 include ${ASTTOPDIR}/makeopts
14 all:
15         @echo "\$($1)"
16 EOF
17 }
18
19
20 XMLSTARLET=`getvar XMLSTARLET`
21 ASTMODDIR=`getvar ASTMODDIR`
22 cache_dir=`getvar EXTERNALS_CACHE_DIR`
23 DOWNLOAD_TO_STDOUT=`getvar DOWNLOAD_TO_STDOUT`
24 HOST_CPU=`getvar HOST_CPU`
25 INSTALL=`getvar INSTALL`
26
27 tmpdir=$(mktemp -d)
28 if [[ -z "${tmpdir}" ]] ; then
29         echo "${module_name}: Unable to create temporary directory."
30         exit 1
31 fi
32 trap "rm -rf ${tmpdir}" EXIT
33
34 if [[ -z "${ASTMODDIR}" ]] ; then
35         echo "${module_name}: Unable to parse ${ASTTOPDIR}/makeopts."
36         exit 1
37 fi
38
39 if [[ "${XMLSTARLET}" = ":" ]] ; then
40         echo "${module_name}: The externals downloader requires xmlstarlet to be installed."
41         exit 1
42 fi
43
44 version=$(${ASTTOPDIR}/build_tools/make_version ${ASTTOPDIR})
45 if [[ ! ${version} =~ ^(GIT-)?([^.-]+)[.-].* ]] ; then
46         echo "${module_name}: Couldn't parse version ${version}"
47         exit 1
48 fi
49 major_version=${BASH_REMATCH[2]}.0
50
51 if [[ "${HOST_CPU}" = "x86_64" ]] ; then
52         host_bits=64
53 else
54         host_bits=32
55 fi
56
57 names=""
58 for manifest in ${DESTDIR}${ASTMODDIR}/*.manifest.xml ; do
59         if [ ! -f "$manifest" ] ; then
60                 break
61         fi
62         package_version=$(${XMLSTARLET} sel -t -v "/package/@version" ${manifest})
63         package_major_version=${package_version%_*}
64         package_arch=$(${XMLSTARLET} sel -t -v "/package/@arch" ${manifest})
65         if [[ "$package_major_version" = "$major_version" && "${package_arch}" = "x86_${host_bits}" ]] ; then
66                 names+=$(${XMLSTARLET} sel -t -m "//file[@executable = 'yes']" -v "concat(@name, ' ')" ${manifest})
67         fi
68 done
69 echo $names