#!/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=echo # Uncomment for Debug session.
# DBG="distfiles_cmpd_debug: "
bleat=true # Uncomment for Normal Use
DBG=""
outer() {
# $bleat "${DBG}Outer0 $*"
del=$1
shift
# $bleat "${DBG}Outer1 $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"
dirs="${dirs} $D/current.old"
# 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: soemtimes
# 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.
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
# 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
dirs="${dirs} $D/6.2-RELEASE" # 2006.11.05 (ports, not src)
# 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.3-RELEASE" # 2008.01.15
dirs="${dirs} $D/6.4-RELEASE" # 2008.12 src tagged.
dirs="${dirs} $D/7.2-RELEASE" # tagged 2009.05.03
dirs="${dirs} $D/7.3-RELEASE" #
dirs="${dirs} $D/8.0-RELEASE" # tagged 2009.11
dirs="${dirs} $D/8.1-RELEASE" # tagged 2010.07
dirs="${dirs} $D/current"
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.
cd $D
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 . -type f -size 0c | xargs ls -l