:
# @(#) $Id: scopaksiz.sh,v 1.2 1991/12/02 09:02:06 ronald Exp $
# Create a script to update the sizes of packages in a perms file.
PATH=/usr/local/bin:/bin:/usr/bin export PATH
tmp=/tmp/$0$$
trap "rm -f $tmp" 0 1 2 3 15
die() { echo "$1" >&2 ; exit 1; }
test "$1" || die "usage: $0 <set>"
perm=./etc/perms/$1
test -f ./etc/perms/$1 || die "$perm not found"
sets="`sed -n 's/^\([A-Z][^ 	]*\)[ 	].*$/\1/p' $perm | sort -u`"
all=0

DU='
	$total = 0;
	while (<>) {
		next if /^\.\/tmp\//;
		chop;
		($ino, $siz) = (stat($_))[1,7];
		next unless $ino;
		next if $seen{$ino}++;
		$total += $siz;
	}
	$total = int($total/512);
	$total++;
	$total++ if $total & 1;
	print $total, "\n";
'

for i in $sets ; do
	echo "$i\t\c"
	( echo 0
	  /etc/fixperm -f -d$i $perm | perl -e "$DU" | sed 's/[ 	]*\.\/.*/ +/'
	  echo p ) | dc
done | (
	while read i j
	do
		all="$all $j +"
		echo "g/^\\(#!$i[ \t]*\\)[0-9][0-9]*/s//\\1$j/"
	done
	i=ALL j="`echo $all p | dc`"
	echo "g/^\\(#!$i[ \t]*\\)[0-9][0-9]*/s//\\1$j/"
)
echo w
