File: cruft

package info (click to toggle)
cruft 0.9.6-0.3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 648 kB
  • ctags: 34
  • sloc: ansic: 642; sh: 179; makefile: 66; perl: 64
file content (142 lines) | stat: -rwxr-xr-x 3,257 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh

#set -- `getopt hd:r:m:knN "$@"`
#if [ $? != 0 ]; then
#	exit 2
#fi

DRIVES=`mount | grep -v "^proc" | cut -d\  -f3`
REPORTFILE=/dev/stdout
MAILTO=""
CLEANUP=yes
FILES=yes
REPORT=yes

while [ $# != 0 ]; do
	case "$1" in
		-h)	echo "Usage: [-h] [-d DRIVES] [-r REPORTFILE] [-m ADDRESS] [-k | -n | -N]"
			exit 0;;

		-d)	DRIVES="$2"; shift;;
		-r)	REPORTFILE="$2"; shift;;
		-m)	MAILTO="$2"; shift;;
		-k)	CLEANUP=yes; FILES=no; REPORT=no;;
		-n)	CLEANUP=no; FILES=yes; REPORT=no;;
		-N)	CLEANUP=no; FILES=no; REPORT=yes;;
		-*)	echo "$0: invalid option -- ${i#-}"; exit 2;;
		*)	break;;
	esac
	shift
done

cd /var/spool/cruft || exit 1

# clean up from previous runs
if [ "$CLEANUP" = "yes" ]; then
	rm -f /var/spool/cruft/*
fi

if [ "$FILES" = yes ]; then
	# official explanations
	cd /usr/lib/cruft/explain
	rm -f /var/spool/cruft/expl_*

	for a in *; do 
		[ -x "$a" ] && 
			( ./$a | sed "s:/\.$:/:;s:/$::;s:^$:/:" |
			  /usr/lib/cruft/extrafiles |
			  /usr/lib/cruft/canonical |
			  sort | uniq > /var/spool/cruft/expl_$a
			) 3>&1 | sed "s:/\.$:/:;s:/$::;s:^$:/:" |
			  /usr/lib/cruft/extrafiles |
			  /usr/lib/cruft/canonical | 
			  sort | uniq > /var/spool/cruft/need_$a
	done

	# local explanations
	cd /etc/cruft/explain
	for a in *; do
		[ -x "$a" ] && 
			( ./$a | sed "s:/\.$:/:;s:/$::;s:^$:/:" |
			  /usr/lib/cruft/extrafiles |
			  /usr/lib/cruft/canonical | 
			  sort | uniq > /var/spool/cruft/expl_$a
			) 3>&1 | sed "s:/\.$:/:;s:/$::;s:^$:/:" |
			  /usr/lib/cruft/extrafiles |
			  /usr/lib/cruft/canonical | 
			  sort | uniq > /var/spool/cruft/need_$a
	done

	# files

	cd /var/spool/cruft
	rm -f /var/spool/cruft/file_*

	rm -f need_link_dests; touch need_link_dests

	for DRIVE in $DRIVES; do 
		if [ "$DRIVE" = "/" ]; then
			FILENAME=file_root
		else
			FILENAME=file_in_`echo "$DRIVE" | sed 's:^/::;s:/:-:g'`
		fi

		find "$DRIVE" -xdev -print -type l -fprint need_link_dests.tmp |
			/usr/lib/cruft/extrafiles | sort | uniq > "$FILENAME"

		cat need_link_dests.tmp | 
			/usr/lib/cruft/readlinks |
			  sed "s:/\.$:/:;s:/$::;s:^$:/:" |
			  /usr/lib/cruft/extrafiles |
			  /usr/lib/cruft/canonical | 
			  sort | sort -m - need_link_dests | 
			  uniq > need_link_dests.new

		mv need_link_dests.new need_link_dests
		rm need_link_dests.tmp
	done
fi

if [ "$REPORT" = yes ]; then
	# generate differences
	rm -f /var/spool/cruft/miss_*
	rm -f /var/spool/cruft/unex_*
		
	/usr/lib/cruft/merge_diff

	# remove empty files
	cd /var/spool/cruft
	for a in *; do
		if [ -e $a ] && ! [ -s $a ]; then rm $a; fi
	done

	# generate report
	( echo -n 'cruft report: '; date
	  echo
	  for a in miss_*; do
		if [ -e $a ]; then
			echo ---- $a ---- | sed 's/miss_/missing: /'
	 		cat $a | sed 's/^/        /'
	  	fi
	  done
	  for a in want_*; do
		if [ -e $a ]; then
			echo ---- $a ---- | sed 's/want_/missing: /'
	 		cat $a | sed 's/^/        /'
	  	fi
	  done
	  for a in unex_root unex_in_*; do
		if [ -e $a ]; then
	 	    echo ---- $a ---- | 
		     sed 's=unex_root=unexplained: /=;s=unex_in_=unexplained: ='
		    cat $a | sed 's/^/        /'
		fi
  	  done
	  echo
	  echo end.
	) > report

	cat report > "$REPORTFILE"
	[ "$MAILTO" = "" ] || 
            cat report | mail -s "[`hostname`] Cruft Report" $MAILTO
fi