pkgsrc-wip/pkg_summary-utils/files/pkg_cleanup_distdir.in
Aleksey Cheusov d557c8d229 update to version 0.32.0
- Default values of variables PKG_SUFX, DISTDIR, PKGSRCDIR, BMAKE
    and PKG_INFO_CMD are embedded to scripts itself and are obtained
    from pkgsrc. Manual pages do not tell what is the default.

  - tests/test.sh:

    fix in regression test #3, pkgsrc vs. pkgsrc+wip ==> XXXX vs. XXXXX

    fix in regression test #11 (Darwin)

    "make test" doesn't need "make install" anymore
2009-09-19 13:31:58 +00:00

112 lines
2.7 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
export LC_ALL=C
############################################################
tmp_dir="/tmp/pkg_cleanup_distdir.$$"
trap "rm -rf $tmp_dir" 0 1 2 15
mkdir -m 700 "$tmp_dir"
############################################################
usage (){
cat 1>&2 <<EOF
pkg_cleanup_distdir - analyses ALLSRCFILES field of src_summary
given on input and optionally removes files and directories in DISTDIR
not referenced by any package.
usage: pkg_cleanup_distdir [OPTIONS] [files...]
OPTIONS:
-h|--help display this help message
-r remove unreferenced files and empty directories
EOF
}
delete=''
while test $# -ne 0; do
case "$1" in
-h|--help)
usage
exit 0;;
-r)
delete=1;;
--)
shift
break;;
-*)
echo "Bad option $1" 1>&2
exit 1;;
*)
break
esac
shift
done
DISTDIR=${DISTDIR:=@DISTDIR@}
cd "$DISTDIR"
useful_distfiles (){
awk '/^ALLSRCFILES=/ {
$0 = substr($0, 13)
for (i=1; i <= NF; ++i)
print $i
}' "$@" |
sort | uniq
}
existing_files (){
find . -type f | sed "s,^[.]/,,"
}
ex_file=$tmp_dir/existing
us_file=$tmp_dir/useful
rm_file=$tmp_dir/to_be_removed
rmdir_file=$tmp_dir/dirs
existing_files > "$ex_file"
useful_distfiles "$@" > "$us_file"
sort "$ex_file" "$ex_file" "$us_file" | uniq -c |
awk '$1 == 2 {print $2}' > "$rm_file"
if test -n "$delete"; then
xargs rm -f < "$rm_file"
sed 's,/[^/]*$,,' "$rm_file" | sort | uniq |
while read -r dir; do
while test "$dir" != '.'; do
if ! rmdir "$dir" 2>/dev/null; then
break
fi
dir=`dirname $dir`
done
done
else
cat "$rm_file"
fi