#!@SH@ #-*-mode: sh -*- # Copyright (c) 2007-2008 Aleksey Cheusov # # 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 PKGSRCDIR=/usr/pkgsrc fi if test -z "$BMAKE"; then BMAKE=make fi ############################################################ usage (){ cat 1>&2 < obtain package names from a specified file, - for stdin -i|--fields -i|--fields= list of fields (separated by space character or comma) to be included to the summary, full summary is generated by default EOF } pkgs_fn='' while test $# -ne 0; do case "$1" in -h|--help) usage exit 0;; -f|--file) pkgs_fn="$2" shift;; --file=*|-f=*) pkgs_fn="`printf '%s\n' \"$1\" | sed 's,^[^=]*=,,'`";; -f*) pkgs_fn="`printf '%s\n' \"$1\" | cut -b3-`";; -i|--fields) fields="-f '$2'" shift;; -i=*|--fields=*) fields="-f '`echo $1 | cut -f2 -d=`'";; --) shift break;; -*) echo "Bad option $1" 1>&2 exit 1;; *) break esac shift done if test $# -ne 1; then usage exit 1 fi summary=$1 shift ############################################################ cd $PKGSRCDIR new_summary=$summary.new tmp_dir="/tmp/pkg_update_src_summary.$$" trap "rm -rf $tmp_dir $new_summary" 0 1 2 15 mkdir -m 700 "$tmp_dir" allpkgs_fn=$tmp_dir/allpkgs if test "$pkgs_fn"; then awk '{sub(/#.*/, "")} NF > 0 {print $1}' $pkgs_fn > $allpkgs_fn else pkg_list_all_pkgs > $allpkgs_fn fi ############################################################ #### process packages # src_summary from scratch if ! test -f $summary; then eval pkg_src_summary $fields < $allpkgs_fn > $new_summary mv $new_summary $summary exit $? fi # micro summary micsum_fn=$tmp_dir/micsum pkg_micro_src_summary < $allpkgs_fn >$micsum_fn # summary against microsummary cmp_fn=$tmp_dir/cmp pkg_cmp_summary -p $summary $micsum_fn > $cmp_fn # copying summary about unchanged packages eq_pkgs_fn=$tmp_dir/eqpkgs awk '$1 ~ /^[=]/ {print $2 ":" $3}' $cmp_fn > $eq_pkgs_fn # pkgpath:pkgbase copy_eq_pkgs (){ env eq_pkgs_fn="$eq_pkgs_fn" runawk -e ' #use "xgetline.awk" #use "pkg_grep_summary.awk" BEGIN { eq_pkgs_fn = ENVIRON ["eq_pkgs_fn"] FS = " " while (xgetline0(eq_pkgs_fn)){ eq_pkgs [$1] = 1 } FS = "=" } function grep_summary__condition ( pkgpath, pkgbase){ pkgpath = grep_summary__fields ["PKGPATH"] pkgbase = grep_summary__fields ["PKGNAME"] sub(/-[^-]+$/, "", pkgbase) if (pkgpath == "" || pkgbase == ""){ return -1 } if (((pkgpath ":" pkgbase) in eq_pkgs) && !((pkgpath ":" pkgbase) in processed)) { processed [pkgpath ":" pkgbase] = 1 return 1 } return 0 } ' "$@" } copy_eq_pkgs $summary > $new_summary # add new/updated/changed packages changed_pkgs_fn=$tmp_dir/changed_pkgs awk '$1 ~ /^[+<>?0-9]/ {print $2 ":" $3}' $cmp_fn > $changed_pkgs_fn extract_pkgpath (){ awk -v changed_pkgs_fn=$changed_pkgs_fn ' BEGIN { while (0 < (ret = getline < changed_pkgs_fn)){ pkgs [$1] = 1 } if (ret < 0){ printf "reading error from" changed_pkgs_fn > "/dev/stderr" } SUBSEP = ":" FS = "=" } $1 == "PKGNAME" { pkgbase = $2 sub(/-[^-]+$/, "", pkgbase) } $1 == "PKGPATH" { pkgpath = $2 } pkgpath != "" && pkgbase != "" { interesting = ((pkgpath ":" pkgbase) in pkgs) } NF == 0 && interesting { print pkgpath pkgbase = pkgpath = "" } ' "$@" } pkgpath_fn=$tmp_dir/pkgpaths extract_pkgpath $micsum_fn > $pkgpath_fn eval pkg_src_summary $fields < $pkgpath_fn >> $new_summary # result mv $new_summary $summary