131 lines
3.2 KiB
Bash
Executable file
131 lines
3.2 KiB
Bash
Executable file
#!@SH@
|
|
#-*-mode: sh -*-
|
|
|
|
# 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
|
|
|
|
. pipestatus
|
|
|
|
############################################################
|
|
# user settable variables
|
|
if test -z "$PKGSRCDIR"; then
|
|
export PKGSRCDIR=/usr/pkgsrc # export - for pkg_src_fetch_var
|
|
fi
|
|
|
|
if test -z "$BMAKE"; then
|
|
export BMAKE=make
|
|
fi
|
|
|
|
############################################################
|
|
tmpdir=/tmp/pkg_micro_src_summary.$$
|
|
trap "rm -rf $tmpdir" 0 1 2 15
|
|
mkdir -m 700 $tmpdir
|
|
|
|
errsfn=$tmpdir/errors.txt
|
|
|
|
############################################################
|
|
usage (){
|
|
cat 1>&2 <<EOF
|
|
pkg_micro_src_summary - builds micro summary information
|
|
about source packages
|
|
|
|
usage: pkg_micro_src_summary [OPTIONS] [pkgpath1 pkgpath2 ...]
|
|
OPTIONS:
|
|
-h|--help display this help message
|
|
-f|--fields <filename>
|
|
-f|--fields=<filename> fields to be included to summary,
|
|
PKGNAME and PKGPATH by default
|
|
EOF
|
|
}
|
|
|
|
fields='PKGNAME PKGPATH'
|
|
|
|
while test $# -ne 0; do
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 0;;
|
|
-f|--fields)
|
|
fields="`echo $2 | tr , ' '`"
|
|
shift;;
|
|
-f=*)
|
|
printf '%s\n' '-f= is not allowed' 1>&2
|
|
exit 1;;
|
|
--fields=*)
|
|
fields="$(echo $1 | cut -f2 -d= | tr , ' ')";;
|
|
-f*)
|
|
fields="$(echo $1 | cut -b 3- | tr , ' ')";;
|
|
--)
|
|
shift
|
|
break;;
|
|
-*)
|
|
echo "Unrecognized option " $1 ". Type --help to see usage" 1>&2
|
|
exit 1;;
|
|
*)
|
|
break;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
############################################################
|
|
cd $PKGSRCDIR
|
|
|
|
# running helper
|
|
helper_out=$tmpdir/helper_out.txt
|
|
|
|
list_pkgs (){
|
|
if test $# -ne 0; then
|
|
# processing arguments
|
|
for pkgpath in "$@"; do
|
|
echo $pkgpath
|
|
done
|
|
else
|
|
cat
|
|
fi
|
|
}
|
|
|
|
runpipe \
|
|
list_pkgs "$@" '|' \
|
|
pkg_src_fetch_var -f "$fields" > "$helper_out"
|
|
|
|
# `+' to micro_summary (fast!)
|
|
awk -F'\t' -v fields="$fields" '
|
|
BEGIN {
|
|
fcnt = split(fields, fname, " ")
|
|
}
|
|
|
|
/^[+]/ {
|
|
for (i=1; i <= fcnt; ++i){
|
|
printf "%s=%s\n", fname [i], $(i+1)
|
|
}
|
|
|
|
printf "\n"
|
|
}' "$helper_out"
|
|
|
|
# `-' to micro_summary (slo-o-o-ow!)
|
|
make_out=$tmpdir/make_out.txt
|
|
awk -F'\t' '
|
|
/^[-]/ {
|
|
print $NF
|
|
}' "$helper_out" |
|
|
pkg_src_summary -f "$fields"
|