Correction : tool=$(readlink "$tool") .
[lhc/ateliers.git] / etc / etckeeper / update-ignore.d / 02custom-ignore
1 #!/bin/sh
2 # NOTE: file derived from etckeeper/update-ignore.d/01update-ignore
3 set -e
4
5 if [ "$VCS" = git ]; then
6 dir=.git
7 file=.gitignore
8 elif [ "$VCS" = hg ]; then
9 dir=.hg
10 file=.hgignore
11 elif [ "$VCS" = bzr ]; then
12 dir=.bzr
13 file=.bzrignore
14 elif [ "$VCS" = darcs ]; then
15 dir=_darcs
16 file=.darcsignore
17 else
18 echo "etckeeper: unsupported VCS $VCS" >&2
19 exit 1
20 fi
21
22 if [ ! -d "$dir" ]; then
23 exit 0
24 fi
25
26 managed_by_etckeeper="managed by update-ignore.d/02custom-ignore"
27
28 nl() {
29 echo >>"$file"
30 }
31
32 comment() {
33 comment="$1"
34 echo "# $comment" >>"$file"
35 }
36
37 ignore() {
38 glob="$1"
39
40 case "$VCS" in
41 git)
42 # escape "#" in ignores, as otherwise it may
43 # be considered a comment
44 echo "$glob" | sed 's/#/\\#/g' >>"$file"
45 ;;
46 bzr)
47 echo "$glob" >>"$file"
48 ;;
49 hg)
50 # rather than converting the glob to a regexp, just
51 # configure hg to use globs
52 if [ -z "$hg_syntax_printed" ]; then
53 comment "use glob syntax"
54 echo "syntax: glob" >>"$file"
55 nl
56 hg_syntax_printed=1
57 fi
58 echo "$glob" | sed 's/#/\\#/g' >>"$file"
59 ;;
60 darcs)
61 # darcs doesn't understand globs, so we need to
62 # translate them into regexs. Not a complete converter,
63 # but suitable for given globs.
64 if [ "${glob%\*}" != "$glob" ]; then
65 glob="${glob%\*}"
66 else
67 glob="$glob"'($|/)'
68 fi
69 if [ "${glob#\*}" != "$glob" ]; then
70 glob="${glob#\*}"
71 else
72 glob='(^|/)'"$glob"
73 fi
74 glob="$( printf %s $glob | sed -e 's/\./\\./g;s/\*/[^\/]*/g;s/\?/[^\/]/g' )"
75 echo "$glob" >>"$file"
76 esac
77 }
78
79 writefile () {
80 comment "begin section $managed_by_etckeeper (do not edit this section by hand)"
81 nl
82 ignore "aliases.db"
83 ignore "postfix/*.db"
84 nl
85 comment "end section $managed_by_etckeeper"
86 }
87
88 if [ -e "$file" ]; then
89 if ! grep -q "$managed_by_etckeeper" "$file"; then
90 if [ "$1" != "-a" ]; then
91 echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not updating"
92 exit 1
93 else
94 echo "etckeeper: "$file" exists but does not contain \"$managed_by_etckeeper\" comment; updating"
95 writefile
96 exit 0
97 fi
98 fi
99 realfile="$file"
100 if [ -n "`type -p tempfile`" ]; then
101 tempfile="tempfile"
102 elif [ -n "`type -p mktemp`" ]; then
103 tempfile="mktemp"
104 else
105 echo "etckeeper warning: can't find tempfile or mktemp" >&2
106 fi
107 file=$($tempfile)
108 (
109 skipping=
110 while read line; do
111 if echo "$line" | grep -q "$managed_by_etckeeper"; then
112 if [ ! "$skipping" ]; then
113 skipping=1
114 else
115 skipping=
116 writefile
117 fi
118 elif [ ! "$skipping" ]; then
119 echo "$line" >> "$file"
120 fi
121 done
122 if [ "$skipping" ]; then
123 # reached end of file w/o ending block
124 writefile
125 fi
126 ) <"$realfile"
127
128 mv -f "$file" "$realfile"
129 else
130 writefile
131 fi