File: z_cruft

package info (click to toggle)
cruft 0.9.39
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,024 kB
  • sloc: ansic: 811; sh: 375; perl: 197; python: 85; makefile: 56
file content (77 lines) | stat: -rwxr-xr-x 1,709 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=492001
#
# needs: bash, mailx, cron-daemon, cruft-ng or cruft
#
# symlink/copy this in /etc/cron.daily
#
# this is called 'z_...' because it must run after
# /etc/cron.daily/apt & /etc/cron.daily/mlocate
#

dpkg_ts_before=$(date -r /var/lib/dpkg/status +%s)

# clean-up from previous interrupted runs
rm -f /var/spool/cruft/report_*.log.tmp

if [ -x /usr/bin/cruft-ng ]
then
	CRUFT=cruft-ng
elif [ -x /usr/sbin/cruft ]
then
	CRUFT=cruft
else
	echo ERROR: please install cruft-ng or cruft
	exit 1
fi

prev=$(ls /var/spool/cruft/report_*.log 2>/dev/null | tail -n 1)
last=/var/spool/cruft/report_$(date '+%Y%m%d').log

# can only run once a day
[ "$prev" = "$last" ] && exit 0

# avoid spurious diff in 'missing: dpkg' if this is on a tmpfs
# and there was nothing to update today
mkdir -p /var/cache/apt/archives/partial

nice ionice $CRUFT > $last.tmp

# abort if $CRUFT has been killed
if ! grep ^end $last.tmp -q
then
	rm $last.tmp
	# don't complain, simply try again tomorrow
	exit 0
fi

# first run
if [ -z "$prev" ]
then
	mv $last.tmp $last
	exit 0
fi

# check for race with manually-run dpkg/apt/aptitude
#
# unattended-upgrades is not impacted thanks to
# /etc/cron.daily/ execution being serialized by run-parts.

dpkg_ts_after=$(date -r /var/lib/dpkg/status +%s)
if [ $dpkg_ts_after -ne $dpkg_ts_before ]
then
	rm $last.tmp
	# don't complain, simply try again tomorrow
	exit 0
fi

# abort on no-change
if [ -z "$(diff <(sed -n '1!p' < $prev) <(sed -n '1!p' < $last.tmp) 2>/dev/null)" ]
then
	rm $last.tmp
	exit 0
fi

mv $last.tmp $last
diff --show-function-line='^-' -u $prev $last | mailx -s "delta cruft for $(date '+%Y%m%d')" root