devscript: refactor list_ids_in_pkg into functions

This commit is contained in:
Roland Walker
2014-01-31 12:33:30 -05:00
parent cd4ee5d3bb
commit bffec0e719
+28 -9
View File
@@ -7,6 +7,27 @@ set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions
bundle_id_source_1 () {
/usr/bin/find "$tmpdir" -name PackageInfo -print0 | \
/usr/bin/xargs -0 /usr/bin/perl -0777 -ne \
'while (m{<pkg-info.*?\sid(?:entifier)?\s*=\s*"([^"]*?)"}sg) { print "$1\n" }'
}
merge_sources () {
/usr/bin/sort | /usr/bin/uniq
}
clean_sources () {
/usr/bin/egrep -v '^com\.apple\.' | \
/usr/bin/egrep -v 'sparkle\.finish-installation$'
}
mark_up_sources () {
/usr/bin/perl -pe 's{\n}{\000}sg' | \
/usr/bin/xargs -0 -I{} -n1 /bin/bash -c \
'printf "{}"; /usr/sbin/pkgutil --pkg-info "{}" >/dev/null 2>&1 && printf " (+)"; printf "\n"'
}
_list_ids_in_pkg () {
local tmpdir=`/usr/bin/mktemp -d -t list_ids_in_pkg`
@@ -14,15 +35,13 @@ _list_ids_in_pkg () {
/usr/sbin/pkgutil --expand "$1" "$tmpdir/unpack"
/usr/bin/find "$tmpdir" -name PackageInfo -print0 | \
/usr/bin/xargs -0 /usr/bin/perl -0777 -ne \
'while (m{<pkg-info.*?\sid(?:entifier)?\s*=\s*"([^"]*?)"}sg) { print "$1\n" }' | \
/usr/bin/sort | /usr/bin/uniq | \
/usr/bin/egrep -v '^com\.apple\.' | \
/usr/bin/egrep -v 'sparkle\.finish-installation$' | \
/usr/bin/perl -pe 's{\n}{\000}sg' | \
/usr/bin/xargs -0 -I{} -n1 /bin/bash -c \
'printf "{}"; /usr/sbin/pkgutil --pkg-info "{}" >/dev/null 2>&1 && printf " (+)"; printf "\n"'
{
# emit strings that look like bundle ids
bundle_id_source_1;
} | \
merge_sources | \
clean_sources | \
mark_up_sources
}