12aff3f95a05657f04857505ff4d697b57d9bf80
[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
10 tmpdir=$(mktemp -d)
11 if [[ -z "${tmpdir}" ]] ; then
12         echo "${module_name}: Unable to create temporary directory."
13         exit 1
14 fi
15 trap "rm -rf ${tmpdir}" EXIT
16
17 sed -r -e "s/^([^ =]+)\s*=\s*(.*)$/\1=\"\2\"/g" ${ASTTOPDIR}/makeopts >${tmpdir}/makeopts
18 source ${tmpdir}/makeopts
19 if [[ -z "${ASTMODDIR}" ]] ; then
20         echo "${module_name}: Unable to parse ${ASTTOPDIR}/makeopts."
21         exit 1
22 fi
23
24 XMLSTARLET=${XMLSTARLET:-xmlstarlet}
25 if [[ "${XMLSTARLET}" = ":" ]] ; then
26         echo "${module_name}: The externals downloader requires xmlstarlet to be installed."
27         exit 1
28 fi
29
30 version=$(${ASTTOPDIR}/build_tools/make_version ${ASTTOPDIR})
31 if [[ ! ${version} =~ ^(GIT-)?([^.-]+)[.-].* ]] ; then
32         echo "${module_name}: Couldn't parse version ${version}"
33         exit 1
34 fi
35 major_version=${BASH_REMATCH[2]}.0
36
37 if [[ "${HOST_CPU}" = "x86_64" ]] ; then
38         host_bits=64
39 else
40         host_bits=32
41 fi
42
43 names=""
44 for manifest in ${DESTDIR}${ASTMODDIR}/*.manifest.xml ; do
45         if [ ! -f "$manifest" ] ; then
46                 break
47         fi
48         package_version=$(${XMLSTARLET} sel -t -v "/package/@version" ${manifest})
49         package_major_version=${package_version%_*}
50         package_arch=$(${XMLSTARLET} sel -t -v "/package/@arch" ${manifest})
51         if [[ "$package_major_version" = "$major_version" && "${package_arch}" = "x86_${host_bits}" ]] ; then
52                 names+=$(${XMLSTARLET} sel -t -m "//file[@executable = 'yes']" -v "concat(@name, ' ')" ${manifest})
53         fi
54 done
55 echo $names