Path: blob/main/Tools/scripts/distclean.sh
16123 views
#!/bin/sh1#2# distclean3# Compare distfiles in /usr/ports/distfiles4# with currently instaled ports collection5# and removes outdated files6#7# ----------------------------------------------------------------------------8# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):9# Maxim Sobolev <[email protected]> wrote this file. As long as you retain10# this notice you can do whatever you want with this stuff. If we meet some11# day, and you think this stuff is worth it, you can buy me a beer in return.12#13# Maxim Sobolev14# ----------------------------------------------------------------------------15#16# MAINTAINER= [email protected]1718PATH=/sbin:/bin:/usr/bin1920cleanup() {21rm -f $FN_RESULTS_SCRIPT $FN_PORTS $FN_DISTFILES22echo "Terminated."23exit 124}2526PORTSDIR=${PORTSDIR:-/usr/ports}27if [ ! -d ${PORTSDIR} ]; then28echo "Ports directory ${PORTSDIR} does not exist."29exit 130fi3132DISTDIR=`(make -V DISTDIR -f ${PORTSDIR}/Mk/bsd.port.mk) 2>/dev/null`33DISTDIR=${DISTDIR:-/usr/ports/distfiles}3435echo "Assumes that your ports are in ${PORTSDIR} and distfiles in ${DISTDIR}."36echo ""3738if [ x"$1" = x"-f" ]; then39RM_FLAG="-f"40else41RM_FLAG="-i"42echo "Use \"`basename $0` -f\" to remove the files without prompting for confirmation."43echo ""44fi4546umask 0774748FN_PORTS=`mktemp -t dclean` || exit 149FN_DISTFILES=`mktemp -t dclean` || exit 150FN_RESULTS_SCRIPT=`mktemp -t dclean` || exit 15152trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 21 22 23 24 25 26 27 28 \5330 315455echo -n "Building ports sha256 index..."56find ${PORTSDIR}/ \57\( -name "distinfo" -or -name "distinfo.i386" -or -name "distinfo.alpha" \) \58-type f -mindepth 3 -maxdepth 3 | \59xargs cat | grep '^SHA256 ('| sort -u > $FN_PORTS60echo "Done."61P_SHA256_COUNT=`wc -l $FN_PORTS | sed "s| $FN_PORTS|| ; s| ||g"`62echo "Found $P_SHA256_COUNT sha256 entries in your ports directory."6364echo -n "Building distfiles sha256 index..."65find ${DISTDIR}/ -type f | xargs sha256 | sed 's|'${DISTDIR}'/||' | sort > $FN_DISTFILES66echo "Done."67D_SHA256_COUNT=`wc -l $FN_DISTFILES | sed "s| $FN_DISTFILES|| ; s| ||g"`68echo "Found $D_SHA256_COUNT distfile(s) in your distfiles directory."6970echo -n "Comparing results..."71diff -d $FN_DISTFILES $FN_PORTS | grep "^<" | sed 's|.*(|rm '$RM_FLAG' '${DISTDIR}'/| ; s|).*||' > $FN_RESULTS_SCRIPT72echo "Done."73R_SHA256_COUNT=`wc -l $FN_RESULTS_SCRIPT | sed "s| $FN_RESULTS_SCRIPT|| ; s| ||g"`74echo "$R_SHA256_COUNT distfile(s) doesn't have corresponding sha256 entries in ports directory."75/bin/sh $FN_RESULTS_SCRIPT76find ${DISTDIR}/ -type d -empty -delete7778echo -n "Finishing..."79rm -f $FN_RESULTS_SCRIPT $FN_PORTS $FN_DISTFILES80echo "Done."818283