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: 4.0 |
---|
15 | # |
---|
16 | |
---|
17 | package=#PACKAGE# |
---|
18 | |
---|
19 | ours=#DEB_DIVERT_EXTENSION# |
---|
20 | theirs=#DEB_DIVERT_EXTENSION#-orig |
---|
21 | |
---|
22 | divert_link_divert() |
---|
23 | { |
---|
24 | file=$1 |
---|
25 | ourfile=$2 |
---|
26 | theirfile=$3 |
---|
27 | if ! LC_ALL=C dpkg-divert --list "$package" | \ |
---|
28 | grep -xFq "diversion of $file to $theirfile by $package"; then |
---|
29 | dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file" |
---|
30 | fi |
---|
31 | } |
---|
32 | |
---|
33 | divert_link_symlink() |
---|
34 | { |
---|
35 | file=$1 |
---|
36 | ourfile=$2 |
---|
37 | theirfile=$3 |
---|
38 | if [ ! -L "$file" ] && [ ! -e "$file" ]; then |
---|
39 | ln -s "$(basename "$ourfile")" "$file" |
---|
40 | elif [ ! -L "$file" ] || \ |
---|
41 | [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \ |
---|
42 | "$(readlink "$file")" != "$(basename "$theirfile")" ]; then |
---|
43 | echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2 |
---|
44 | fi |
---|
45 | } |
---|
46 | |
---|
47 | divert_link() |
---|
48 | { |
---|
49 | prefix=$1 |
---|
50 | suffix=$2 |
---|
51 | |
---|
52 | file=$prefix$suffix |
---|
53 | ourfile=$prefix$ours$suffix |
---|
54 | theirfile=$prefix$theirs$suffix |
---|
55 | divert_link_divert "$file" "$ourfile" "$theirfile" |
---|
56 | divert_link_symlink "$file" "$ourfile" "$theirfile" |
---|
57 | } |
---|
58 | |
---|
59 | divert_remove() |
---|
60 | { |
---|
61 | file=$1 |
---|
62 | ourfile="" |
---|
63 | theirfile=$2 |
---|
64 | divert_link_divert "$file" "$ourfile" "$theirfile" |
---|
65 | } |
---|
66 | |
---|
67 | undivert_unlink_symlink() |
---|
68 | { |
---|
69 | file="$1" |
---|
70 | ourfile="$2" |
---|
71 | theirfile="$3" |
---|
72 | if [ ! -L "$file" ] || \ |
---|
73 | [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \ |
---|
74 | "$(readlink "$file")" != "$(basename "$theirfile")" ]; then |
---|
75 | echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2 |
---|
76 | else |
---|
77 | rm -f "$file" |
---|
78 | fi |
---|
79 | } |
---|
80 | |
---|
81 | undivert_unlink_divert() |
---|
82 | { |
---|
83 | file="$1" |
---|
84 | if [ ! -L "$file" ] && [ ! -e "$file" ]; then |
---|
85 | dpkg-divert --remove --rename --package "$package" "$file" |
---|
86 | else |
---|
87 | echo "Not removing diversion of $file by $package" >&2 |
---|
88 | fi |
---|
89 | } |
---|
90 | |
---|
91 | undivert_unlink() |
---|
92 | { |
---|
93 | prefix=$1 |
---|
94 | suffix=$2 |
---|
95 | |
---|
96 | file=$prefix$suffix |
---|
97 | ourfile=$prefix$ours$suffix |
---|
98 | theirfile=$prefix$theirs$suffix |
---|
99 | |
---|
100 | undivert_unlink_symlink "$file" "$ourfile" "$theirfile" |
---|
101 | undivert_unlink_divert "$file" |
---|
102 | } |
---|
103 | |
---|
104 | undivert_unremove() |
---|
105 | { |
---|
106 | file=$1 |
---|
107 | undivert_unlink_divert "$file" |
---|
108 | } |
---|
109 | |
---|
110 | check_undivert_unlink() |
---|
111 | { |
---|
112 | prefix=$1 |
---|
113 | suffix=$2 |
---|
114 | |
---|
115 | file=$prefix$suffix |
---|
116 | ourfile=$prefix$ours$suffix |
---|
117 | theirfile=$prefix$theirs$suffix |
---|
118 | |
---|
119 | if LC_ALL=C dpkg-divert --list "$package" | \ |
---|
120 | grep -xFq "diversion of $file to $theirfile by $package"; then |
---|
121 | undivert_unlink "$prefix" "$suffix" |
---|
122 | fi |
---|
123 | } |
---|
124 | |
---|
125 | check_undivert_unremove() |
---|
126 | { |
---|
127 | file=$1 |
---|
128 | removedfile=$2 |
---|
129 | if LC_ALL=C dpkg-divert --list "$package" | \ |
---|
130 | grep -xFq "diversion of $file to $removedfile by $package"; then |
---|
131 | undivert_unremove "$file" |
---|
132 | fi |
---|
133 | } |
---|