summaryrefslogtreecommitdiff
path: root/update-ignore.d/01update-ignore
blob: 3fc825ea35f66db31e6faee63b223cf9057f5c5a (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh
set -e

if [ "$VCS" = git ]; then
	dir=.git
	file=.gitignore
elif [ "$VCS" = hg ]; then
	dir=.hg
	file=.hgignore
elif [ "$VCS" = bzr ]; then
	dir=.bzr
	file=.bzrignore
elif [ "$VCS" = darcs ]; then
	dir=_darcs
	file=.darcsignore
else
	echo "etckeeper: unsupported VCS $VCS" >&2
	exit 1
fi

if [ ! -d "$dir" ]; then
	exit 0
fi

managed_by_etckeeper="managed by etckeeper"

nl() {
	echo >>"$file"
}

comment() {
	comment="$1"
	echo "# $comment" >>"$file"
}

ignore() {
	glob="$1"
	
	case "$VCS" in
		git)
			# escape "#" in ignores, as otherwise it may
			# be considered a comment
			echo "$glob" | sed 's/#/\\#/g' >>"$file"
		;;
		bzr)
			echo "$glob" >>"$file"
		;;
		hg)
			# rather than converting the glob to a regexp, just
			# configure hg to use globs
			if [ -z "$hg_syntax_printed" ]; then
				comment "use glob syntax"
				echo "syntax: glob" >>"$file"
				nl
				hg_syntax_printed=1
			fi
			echo "$glob" | sed 's/#/\\#/g' >>"$file"
		;;
		darcs)
			# darcs doesn't understand globs, so we need to
			# translate them into regexs. Not a complete converter,
			# but suitable for given globs.
			if [ "${glob%\*}" != "$glob" ]; then
				glob="${glob%\*}"
			else
				glob="$glob"'($|/)'
			fi
			if [ "${glob#\*}" != "$glob" ]; then
				glob="${glob#\*}"
			else
				glob='(^|/)'"$glob"
			fi
			glob="$( printf %s $glob | sed -e 's/\./\\./g;s/\*/[^\/]*/g;s/\?/[^\/]/g' )"
			echo "$glob" >>"$file"
	esac
}

writefile () {
	comment "begin section $managed_by_etckeeper (do not edit this section by hand)"
	nl

	if [ "$VCS" = darcs ]; then
		darcs setpref boringfile .darcsignore
	fi

	if [ "$LOWLEVEL_PACKAGE_MANAGER" = dpkg ]; then
		comment "new and old versions of conffiles, stored by dpkg"
		ignore "*.dpkg-*"
		comment "new and old versions of conffiles, stored by ucf"
		ignore "*.ucf-*"
		nl
	elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "rpm" ]; then
		comment "new and old versions of conffiles, stored by apt/rpm"
		ignore "*.rpm*"
		nl
	elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" ]; then
		comment "new and old versions of conffiles, stored by pacman"
		ignore "*.pacnew"
		ignore "*.pacorig"
		ignore "*.pacsave"
		nl
	fi
	
	comment "old versions of files"
	ignore "*.old"
	# Not currently ignored as admins tend to rely on these files.
	#ignore "passwd-"
	#ignore "group-"
	#ignore "shadow-"
	#ignore "gshadow-"
	nl

	comment "mount(8) records system state here, no need to store these"
	ignore blkid.tab
	ignore blkid.tab.old
	nl
	
	comment "some other files in /etc that typically do not need to be tracked"
	ignore nologin
	ignore ld.so.cache
	ignore mtab
	ignore mtab.fuselock
	ignore .pwd.lock
	ignore network/run
	ignore adjtime
	ignore lvm/cache
	ignore "X11/xdm/authdir/authfiles/*"
	ignore ntp.conf.dhcp
	ignore "webmin/fsdump/*.status"
	ignore "webmin/webmin/oscache"
	ignore "apparmor.d/cache/*"
	ignore "service/*/supervise/*"
	ignore "service/*/log/supervise/*"
	ignore "sv/*/supervise/*"
	ignore "sv/*/log/supervise/*"
	ignore "*.elc"
	nl
	
	comment "editor temp files"
	ignore "*~"
	ignore ".*.sw?"
	ignore ".sw?"
	ignore "#*#"
	ignore DEADJOE

	nl
	comment "end section $managed_by_etckeeper"
}

if [ -e "$file" ]; then
	if ! grep -q "$managed_by_etckeeper" "$file"; then
		echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not updating"
		exit 1
	fi
	realfile="$file"
	if [ -n "`type -p tempfile`" ]; then
		tempfile="tempfile"
	elif [ -n "`type -p mktemp`" ]; then
		tempfile="mktemp"
	else
		echo "etckeeper warning: can't find tempfile or mktemp" >&2
	fi
	file=$($tempfile)
	(
		skipping=
		while read line; do
			if echo "$line" | grep -q "$managed_by_etckeeper"; then
				if [ ! "$skipping" ]; then
					skipping=1
				else
					skipping=
					writefile
				fi
			elif [ ! "$skipping" ]; then
				echo "$line" >> "$file"
			fi
		done
		if [ "$skipping" ]; then
			# reached end of file w/o ending block
			writefile
		fi
	) <"$realfile"

	mv -f "$file" "$realfile"
else
	writefile
fi