#!/bin/sh
# ~jhs/public_html/bin/.sh/distfiles_cmpd by jhs@
# Removes duplicate distfiles.
# I keep my distfiles in seperate smaller directories,
# segregated by release, with newest release directory containing most files,
# but a few older directories holding more stuff I need for legacy support.
# This shell script strips identical copies.
# See also: /site/domain/this/etc/make.conf.common
# See also: ~jhs/bin/.sh/distfiles_fetch
# Alternates I havent tried:
# cd /usr/ports/sysutils/portupgrade ; make install ; rehash
# portsclean -D # Remove all distfiles not ref''d by ports
# portsclean -DD # Remove all distfiles not used by an installed port
# cd /usr/ports ; make distclean
# # Uses /usr/ports/Mk/bsd.port.mk --distclean
bleat=true
bleat=echo # Uncomment for Debug session.
DBG="distfiles_cmpd_debug: "
DBG=""
outer() {
# $bleat "${DBG}Outer_0 $*"
del=$1
shift
# $bleat "${DBG}Outer_1 $del : $*"
for i in $*
do
# $bleat "${DBG}Calling Inner $del : $*"
inner $del "$*"
del=$1
shift
done
}
inner() {
# $bleat "${DBG}Inner $1 : $2 :"
for i in $2
do
# $bleat "${DBG}zap $1 $i"
zap $1 $i
done
}
zap() {
$bleat "${DBG}Stripping $1 against $2"
( cd $1 && nice find . -type f -exec cmpd -v -d -s {} $2 \; )
}
# Start Of Main.
D=/pub/FreeBSD/dists
dirs=
sense=`cd /usr/ports/distfiles;/bin/pwd` # not `pwd` as it returns distfiles
sense2=`basename $sense`
if [ "$sense2" = "distfiles" ]; then
# You have a local distfiles/ to be stripped.
dirs="${dirs} /usr/ports/distfiles"
# If this happens to be the same as another directory in the
# $dirs path, for each duplicate file cmpd will warn:
# ...... share same device (major & minor) & inode ,
# link count is 1; Skipping.
else
# You do not have a local distfiles/ to be stripped.
# (Your /usr/ports/distfiles is presumably just a symbolic link
# to eg $D/5.3-RELEASE)
fi
# Next directories are in strip order, ie first gets stripped against
# reference 2nd etc. Best in approx newest release last.
# In approx reverse order to /site/domain/this/etc/make.conf.common
# Not in simple 4 before 5 numeric order as releases 4.x 5.x & 6.x & 7.x
# overlap / interleave in time.
# For release dates see http://www.freebsd.org/releases/index.html
# /usr/www/en/releases
# dirs="${dirs} /chroot/usr/ports/distfiles"
cd $D
if test -d $D/current.old ; then
dirs="${dirs} $D/current.old"
# echo "$D/current.old exists so added to list ${dirs}"
else
# echo "$D/current.old does not exist, so not added to list ${dirs}"
true
fi
# For when I occasionally manually:
# cd /pub/FreeBSD/dists;mv current current.old;mkdir current
# cd /pri/FreeBSD/branches/-current/ports
# setenv PORTSDIR `pwd`
# nice nice make -k -j 5 BATCH=yes fetch
# distfiles_cmpd
# so that current/ only contains what is now needed, & old files no
# longer needed by current ports/ can be removed to save space.
# Also where I can periodically
# cp -R /usrb/chroot/usr/ports/distfiles
dirs="${dirs} $D/current"
# current is moved about manually by an editor: sometimes
# it is near the beginning, to keep it stripped
# as small as possible, with most files in the latest release
# directories. Other times, eg shortly before a new release is due,
# to ensure I pre fetch as many current distfiles as possible I run
# make fetch on current ports/, before that I either:
# - move current to end of list to ensure I don't transiently
# have too many duplicate distfiles overflowing the disc.
# - Or mv current current.old; make fetch ; distfiles_cmpd
# Warning theres an additional pain: ports Mk/ macros are too dumb,
# try to force me to remote refetch & reclick certain
# license crap again, even if I already hold distfile localy in another
# dir which is not directly /usr/ports/distfiles.
# /host/gate/usr/ports/distfiles is currently a link to $D/6.4-RELEASE
# so avoid doing it twice.
if false ; then
if test -e /host/gate/usr/ports/distfiles ; then
dirs="${dirs} /host/gate/usr/ports/distfiles"
else
true # Dummy.
# Probably AMD has failed to mount, showable with:
# cd /host/gate
# /host/gate: Operation timed out.
fi
else
fi
# dirs="${dirs} $D/common" # individual hosts'' local copies
# Various hosts running different releases share this via sym links.
dirs="${dirs} $D/4.11-RELEASE" # 2005.01, 5.3 G
# Shortly after a release is made, I list the release last
# & run a make fetch, as best time to grab stuff that may later migrate
# elsewhere on the net & be harder to find.
dirs="${dirs} $D/6.4-RELEASE" # 2008.12 src tagged, 11.4 G
dirs="${dirs} $D/7.4-RELEASE" # tagged 2011.02.21, 400 K
dirs="${dirs} $D/8.2-RELEASE" # tagged 2011.03, 30 G & 1.2 G stripped
dirs="${dirs} $D/9.0-RELEASE" # tagged 2012.01
# dirs="${dirs} $D/current" # 86 G
dirs="${dirs} $D/jhs"
# Estic for which I am master repository.
# Word perfect, that I'm licensed to use, & dont want stupid
# ports scripts forcing me to fetch again.
outer ${dirs}
# echo "$D/common/ should be empty, looking now:"
# ls $D/common
echo "Zero size files (if any) in /pub/freebsd/dists"
cd /pub/freebsd/dists
# find has no --exclude parameter so just list where I want to search.
# Transient zero size files in ./httree/hts-cache/ref/*.ref
find [0-9]* current jhs -type f -size 0c | xargs rm