2008-10-23 00:16:19 +02:00
|
|
|
#!@SH@
|
2008-05-07 01:03:26 +02:00
|
|
|
|
|
|
|
# Copyright (c) 2007-2008 Aleksey Cheusov <vle@gmx.net>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
set -e
|
2008-05-07 13:03:33 +02:00
|
|
|
|
|
|
|
usage (){
|
|
|
|
cat 1>&2 <<EOF
|
2008-05-07 20:50:13 +02:00
|
|
|
pkg_grep_summary - output summaries about packages that matches
|
|
|
|
the specified condition.
|
2008-05-07 13:03:33 +02:00
|
|
|
|
2008-09-19 23:06:11 +02:00
|
|
|
USAGE: pkg_grep_summary -h
|
|
|
|
pkg_grep_summary <FIELD> <AWK_CONDITION>
|
|
|
|
pkg_grep_summary -e <FIELD>
|
2008-05-07 20:50:13 +02:00
|
|
|
<FIELD> - PKGNAME, PKGPATH, DEPENDS etc.
|
|
|
|
<AWK_CONDITION> - boolean expression written in AWK language
|
|
|
|
|
|
|
|
OPTIONS:
|
2008-09-19 23:06:11 +02:00
|
|
|
-h|--help display this message
|
|
|
|
-e|--empty <field> matches empty and absent fields only
|
|
|
|
(equivalent to '<field>' 'fvalue == ""')
|
2008-07-07 16:25:26 +02:00
|
|
|
EXAMPLES:
|
2008-09-07 18:53:32 +02:00
|
|
|
pkg_grep_summary 'PKGNAME' 'fvalue ~ /judy/' \\
|
2008-05-07 20:42:06 +02:00
|
|
|
< /usr/pkgsrc/packages/pkg_summary.txt
|
2008-09-07 18:53:32 +02:00
|
|
|
pkg_grep_summary 'PKGPATH' 'fvalue ~ /^lang\//' \\
|
2008-05-07 20:42:06 +02:00
|
|
|
< /usr/pkgsrc/packages/pkg_summary.txt
|
2008-09-07 18:53:32 +02:00
|
|
|
pkg_grep_summary 'DEPENDS' 'fvalue ~ /libX/' \\
|
2008-05-07 20:42:06 +02:00
|
|
|
< /usr/pkgsrc/pkg_src_summary.txt
|
2008-09-07 18:53:32 +02:00
|
|
|
pkg_grep_summary 'COMMENT' 'toupper(fvalue) ~ /DNS/' \\
|
2008-05-07 22:16:12 +02:00
|
|
|
< /usr/pkgsrc/pkg_src_summary.txt
|
2008-09-19 23:06:11 +02:00
|
|
|
pkg_grep_summary -e 'NO_BIN_ON_FTP' \\
|
|
|
|
< /usr/pkgsrc/pkg_src_summary.txt
|
2008-05-07 13:03:33 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while test $# -ne 0; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0;;
|
2008-09-19 23:06:11 +02:00
|
|
|
-e|--empty)
|
|
|
|
empty_field=$2
|
|
|
|
shift;;
|
2008-05-07 13:03:33 +02:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break;;
|
|
|
|
-*)
|
|
|
|
echo "Bad option $1" 1>&2
|
|
|
|
exit 1;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2008-09-19 23:06:11 +02:00
|
|
|
if test -z "$empty_field" -a $# -ne 2 ||
|
|
|
|
test -n "$empty_field" -a $# -ne 0
|
|
|
|
then
|
2008-09-06 18:05:20 +02:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2008-05-07 01:03:26 +02:00
|
|
|
|
2008-09-19 23:06:11 +02:00
|
|
|
if test -z "$empty_field"; then
|
|
|
|
field=$1
|
|
|
|
condition="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
field="$empty_field"
|
|
|
|
condition='fvalue == ""'
|
|
|
|
fi
|
2008-05-07 01:03:26 +02:00
|
|
|
|
2008-05-08 13:01:22 +02:00
|
|
|
runawk -e '
|
2008-10-22 21:09:38 +02:00
|
|
|
#use "pkg_grep_summary.awk"
|
2008-05-07 01:03:26 +02:00
|
|
|
|
2008-05-08 13:01:22 +02:00
|
|
|
BEGIN {
|
|
|
|
grep_summary__field="'"$field"'"
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
|
2008-05-08 13:01:22 +02:00
|
|
|
function grep_summary__condition (){
|
|
|
|
return '"$condition"'
|
2008-05-07 01:03:26 +02:00
|
|
|
}
|
|
|
|
'
|