devscript: factor list_apps_in_pkg into functions

no functional change
This commit is contained in:
Roland Walker
2014-01-31 12:33:29 -05:00
parent bc650b8079
commit e7cdc72ff6
+34 -19
View File
@@ -7,6 +7,33 @@ set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions
app_source_1 () {
/usr/bin/find "$tmpdir" -name PackageInfo -print0 | \
/usr/bin/xargs -0 /usr/bin/perl -0777 -ne \
'while (m{<pkg-info[^\n]*install-location="/Applications".*?path\s*=\s*"([^"]+)"}sg) { my $p = $1; $p =~ s{\A.*/}{}; print "$p\n" }';
}
app_source_2 () {
/usr/bin/find "$tmpdir" -name PackageInfo -print0 | \
/usr/bin/xargs -0 /usr/bin/perl -0777 -ne \
'while (m{<pkg-info[^\n]*install-location="/".*?path\s*=\s*"./Applications/([^"]+)"}sg) { my $p = $1; $p =~ s{\A.*/}{}; print "$p\n" }';
}
app_source_3 () {
/usr/bin/find "$tmpdir" -type d -name '*.app' | \
perl -pe 's{\A.*/}{}';
}
merge_sources () {
/usr/bin/sort | /usr/bin/uniq
}
mark_up_sources () {
/usr/bin/perl -pe 's{\n}{\000}sg' | \
/usr/bin/xargs -0 -I{} -n1 /bin/bash -c \
'printf "{}"; /bin/test -n "$(/usr/bin/find /Applications -type d -maxdepth 3 -name "{}" -print0; /usr/bin/find ~/Applications -type d -maxdepth 3 -name "{}")" && printf " (+)"; printf "\n"'
}
_list_apps_in_pkg () {
local tmpdir=`/usr/bin/mktemp -d -t list_apps_in_pkg`
@@ -15,25 +42,13 @@ _list_apps_in_pkg () {
/usr/sbin/pkgutil --expand "$1" "$tmpdir/unpack"
{
# source 1
/usr/bin/find "$tmpdir" -name PackageInfo -print0 | \
/usr/bin/xargs -0 /usr/bin/perl -0777 -ne \
'while (m{<pkg-info[^\n]*install-location="/Applications".*?path\s*=\s*"([^"]+)"}sg) { my $p = $1; $p =~ s{\A.*/}{}; print "$p\n" }'; \
# source 2
/usr/bin/find "$tmpdir" -name PackageInfo -print0 | \
/usr/bin/xargs -0 /usr/bin/perl -0777 -ne \
'while (m{<pkg-info[^\n]*install-location="/".*?path\s*=\s*"./Applications/([^"]+)"}sg) { my $p = $1; $p =~ s{\A.*/}{}; print "$p\n" }'; \
# source 3
/usr/bin/find "$tmpdir" -type d -name '*.app' | \
perl -pe 's{\A.*/}{}'; \
} | \
# merge sources
/usr/bin/sort | /usr/bin/uniq | \
# markup
/usr/bin/perl -pe 's{\n}{\000}sg' | \
/usr/bin/xargs -0 -I{} -n1 /bin/bash -c \
'printf "{}"; /bin/test -n "$(/usr/bin/find /Applications -type d -maxdepth 3 -name "{}" -print0; /usr/bin/find ~/Applications -type d -maxdepth 3 -name "{}")" && printf " (+)"; printf "\n"'
# strings that look like appnames (Something.app)
app_source_1;
app_source_2;
app_source_3;
} | \
merge_sources | \
mark_up_sources
}
if [[ $1 =~ ^-+h(elp)?$ || -z "$1" ]]; then