]> andersk Git - config-package-dev.git/blame - divert.sh.in
Fix bug where DEB_DIVERT code gets added twice if a package uses both DEB_DIVERT_FILE...
[config-package-dev.git] / divert.sh.in
CommitLineData
ab8e2a67
TA
1#
2# divert_link <prefix> <suffix>
3#
4# Ensures that the file <prefix><suffix> is properly diverted to
5# <prefix>.divert-orig<suffix> by this package, and becomes a
6# symbolic link to either <prefix>.divert<suffix> (default) or
7# <prefix>.divert-orig<suffix>.
8#
9# undivert_unlink <prefix> <suffix>
10#
11# Undoes the action of divert_link <prefix> <suffix> specified
12# above.
13#
14# Version: 3.4
15#
16
17package=#PACKAGE#
18
19ours=#DEB_DIVERT_EXTENSION#
20theirs=#DEB_DIVERT_EXTENSION#-orig
21
22divert_link()
23{
24 prefix=$1
25 suffix=$2
26
27 file=$prefix$suffix
28 ourfile=$prefix$ours$suffix
29 theirfile=$prefix$theirs$suffix
30
31 if ! dpkg-divert --list "$package" | \
32 grep -xFq "diversion of $file to $theirfile by $package"; then
33 dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file"
34 fi
35 if [ ! -L "$file" ] && [ ! -e "$file" ]; then
36 ln -s "$(basename "$ourfile")" "$file"
37 elif [ ! -L "$file" ] || \
38 [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
39 "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
40 echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
41 fi
42}
43
44undivert_unlink()
45{
46 prefix=$1
47 suffix=$2
48
49 file=$prefix$suffix
50 ourfile=$prefix$ours$suffix
51 theirfile=$prefix$theirs$suffix
52
53 if [ ! -L "$file" ] || \
54 [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
55 "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
56 echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
57 else
58 rm -f "$file"
59 fi
60 if [ ! -L "$file" ] && [ ! -e "$file" ]; then
61 dpkg-divert --remove --rename --package "$package" "$file"
62 else
63 echo "Not removing diversion of $file by $package" >&2
64 fi
65}
66
This page took 0.287772 seconds and 5 git commands to generate.