Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/Tools/scripts/distclean.sh
16462 views
1
#!/bin/sh
2
#
3
# distclean
4
# Compare distfiles in /usr/ports/distfiles
5
# with currently instaled ports collection
6
# and removes outdated files
7
#
8
# ----------------------------------------------------------------------------
9
# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
10
# Maxim Sobolev <[email protected]> wrote this file. As long as you retain
11
# this notice you can do whatever you want with this stuff. If we meet some
12
# day, and you think this stuff is worth it, you can buy me a beer in return.
13
#
14
# Maxim Sobolev
15
# ----------------------------------------------------------------------------
16
#
17
# MAINTAINER= [email protected]
18
19
PATH=/sbin:/bin:/usr/bin
20
21
cleanup() {
22
rm -f $FN_RESULTS_SCRIPT $FN_PORTS $FN_DISTFILES
23
echo "Terminated."
24
exit 1
25
}
26
27
PORTSDIR=${PORTSDIR:-/usr/ports}
28
if [ ! -d ${PORTSDIR} ]; then
29
echo "Ports directory ${PORTSDIR} does not exist."
30
exit 1
31
fi
32
33
DISTDIR=`(make -V DISTDIR -f ${PORTSDIR}/Mk/bsd.port.mk) 2>/dev/null`
34
DISTDIR=${DISTDIR:-/usr/ports/distfiles}
35
36
echo "Assumes that your ports are in ${PORTSDIR} and distfiles in ${DISTDIR}."
37
echo ""
38
39
if [ x"$1" = x"-f" ]; then
40
RM_FLAG="-f"
41
else
42
RM_FLAG="-i"
43
echo "Use \"`basename $0` -f\" to remove the files without prompting for confirmation."
44
echo ""
45
fi
46
47
umask 077
48
49
FN_PORTS=`mktemp -t dclean` || exit 1
50
FN_DISTFILES=`mktemp -t dclean` || exit 1
51
FN_RESULTS_SCRIPT=`mktemp -t dclean` || exit 1
52
53
trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 21 22 23 24 25 26 27 28 \
54
30 31
55
56
echo -n "Building ports sha256 index..."
57
find ${PORTSDIR}/ \
58
\( -name "distinfo" -or -name "distinfo.i386" -or -name "distinfo.alpha" \) \
59
-type f -mindepth 3 -maxdepth 3 | \
60
xargs cat | grep '^SHA256 ('| sort -u > $FN_PORTS
61
echo "Done."
62
P_SHA256_COUNT=`wc -l $FN_PORTS | sed "s| $FN_PORTS|| ; s| ||g"`
63
echo "Found $P_SHA256_COUNT sha256 entries in your ports directory."
64
65
echo -n "Building distfiles sha256 index..."
66
find ${DISTDIR}/ -type f | xargs sha256 | sed 's|'${DISTDIR}'/||' | sort > $FN_DISTFILES
67
echo "Done."
68
D_SHA256_COUNT=`wc -l $FN_DISTFILES | sed "s| $FN_DISTFILES|| ; s| ||g"`
69
echo "Found $D_SHA256_COUNT distfile(s) in your distfiles directory."
70
71
echo -n "Comparing results..."
72
diff -d $FN_DISTFILES $FN_PORTS | grep "^<" | sed 's|.*(|rm '$RM_FLAG' '${DISTDIR}'/| ; s|).*||' > $FN_RESULTS_SCRIPT
73
echo "Done."
74
R_SHA256_COUNT=`wc -l $FN_RESULTS_SCRIPT | sed "s| $FN_RESULTS_SCRIPT|| ; s| ||g"`
75
echo "$R_SHA256_COUNT distfile(s) doesn't have corresponding sha256 entries in ports directory."
76
/bin/sh $FN_RESULTS_SCRIPT
77
find ${DISTDIR}/ -type d -empty -delete
78
79
echo -n "Finishing..."
80
rm -f $FN_RESULTS_SCRIPT $FN_PORTS $FN_DISTFILES
81
echo "Done."
82
83