pkg_bin_summary: -k option was added for enriching

package summary with checksums using algorithms supported by digest(1)
This commit is contained in:
Aleksey Cheusov 2011-08-27 17:13:03 +00:00 committed by Thomas Klausner
parent 615c12a711
commit d645586a85
3 changed files with 68 additions and 15 deletions

View file

@ -1,8 +1,5 @@
TODO list and thoughts
pkg_bin_summary: support for field CKSUMS with environment vatiable
XXX containing md5, sha1 etc.
existing tools:
pkg_cmp_summary:
@ -38,7 +35,6 @@ existing tools:
- checks for bad patterns like foobar<=1.1.1nb*
- improve REQUIRES/PROVIDES checks, i.e. use
PROVIDES from dependencies only
- CONFLICTS vs. actual PLISTs in packages
- distfiles checksums
- check binaries and their REQUIRES and analyse Makefile

View file

@ -1,4 +1,4 @@
.\" $NetBSD: pkg_bin_summary.1,v 1.4 2011/08/13 10:55:15 cheusov Exp $
.\" $NetBSD: pkg_bin_summary.1,v 1.5 2011/08/27 17:13:03 cheusov Exp $
.\"
.\" Copyright (c) 2010 by Aleksey Cheusov (vle@gmx.net)
.\" Absolutely no warranty.
@ -43,18 +43,31 @@ is applied,
.B pkg_bin_summary
does nothing in this case and exits immediately.
.TP
.B "-a <fields>"
.BI "-a " fields
add to the output the specified fields,
fields are separated by space or comma.
.TP
.B "-f <fields>"
.BI "-f " fields
output only specified fields,
fields are separated by space or comma.
.TP
.B "-r <fields>"
.BI "-r " fields
remove from output the specified fields,
fields are separated by space or comma.
.TP
.BI "-k " algorithms
Generate checksums for packages using digest(1)
and make them a part of output summary. CKSUM field is added to summary
that has the following format:
.br
.VB
CKSUMS=<ALGO> <CKSUM>
.VE
where ALGO is is an
.I algorithm
supported by digest(1), for example, md5, sha1 etc.,
and CKSUM is a checksum.
.TP
PKG_INFO_ARGS are
options passed to pkg_info(1) that default to -a.
In addition to these options -X is always applied to pkg_info
@ -79,9 +92,12 @@ if PKG_INFO_ARGS is not empty.
find /usr/pkgsrc/packages/All -name '*.tgz' |
xargs pkg_bin_summary -e -a PLIST
ls -1 | grep '[.]tgz$' | xargs pkg_bin_summary -e -k 'sha1 rmd160'
.VE
.SH SEE ALSO
.BR pkg_summary-utils(7) ,
.BR pkg_summary(5) ,
.BR digest(1)
.SH AUTHOR
Aleksey Cheusov <vle@gmx.net>

View file

@ -53,6 +53,8 @@ OPTIONS:
-r <fields> remove from output the specified fields,
fields are output only specified fields
-e does nothing if no packages were specified
-k <algorithms> generate checksums for binary packages
and make them a part of summary (CKSUM)
PKG_INFO_ARGS:
Options passed to pkg_info(1) that default to -a.
In addition to these options -X is always applied to pkg_info
@ -66,14 +68,16 @@ Samples of use:
EOF
}
while getopts hea:r:f: f; do
while getopts hea:r:f:k: f; do
case "$f" in
'?') exit 1;;
h) usage; exit 0;;
a) add_fields="$OPTARG";;
r) rem_fields="$OPTARG";;
f) only_fields="$OPTARG";;
e) explicit_pkgs=1;;
h) usage; exit 0;;
a) add_fields="$add_fields $OPTARG";;
r) rem_fields="$OPTARG";;
f) only_fields="$OPTARG";;
e) explicit_pkgs=1;;
k) cksums="$OPTARG"
add_fields="$add_fields FILE_NAME";;
esac
done
shift `expr $OPTIND - 1`
@ -97,4 +101,41 @@ if test -n "$explicit_pkgs"; then
else
$PKG_INFO_CMD $pkg_info_opts "$@"
fi |
$LIBEXECDIR/XB2bin_summary -a "$add_fields" -r "$rem_fields" -f "$only_fields"
$LIBEXECDIR/XB2bin_summary -a "$add_fields" -r "$rem_fields" -f "$only_fields" |
if test -z "$cksums"; then
cat
else
## Add CKSUM field to summary
tmpdir=`mktemp -d /tmp/bin_summary.XXXXXX`
test -n "$tmpdir" || exit 1
# generate checksums
for i in $cksums; do
digest $i "$@" >> $tmpdir/cksums
done
#
awk -v cksums="$cksums" '
BEGIN { cksums_cnt = split(cksums, cksums_arr) }
FILENAME != "-" && $3 == "=" {
fn = substr($2, 2, length($2)-2)
sub(/^.*\//, "", fn)
cksum [fn, tolower($1)] = $4
}
FILENAME == "-" {
if (/^FILE_NAME=/)
fn = substr($0, 11)
if (NF > 0) {
print
next
}
for (i=1; i <= cksums_cnt; ++i){
cksum_type = cksums_arr [i]
print "CKSUM=" cksum_type " " cksum [fn, cksum_type]
}
fn = ""
print ""
}' $tmpdir/cksums -
fi