2 # divert_link <prefix> <suffix>
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>.
9 # undivert_unlink <prefix> <suffix>
11 # Undoes the action of divert_link <prefix> <suffix> specified
16 # Copyright © 2008–2012 Tim Abbott <tabbott@mit.edu> and Anders
17 # Kaseorg <andersk@mit.edu>
19 # Permission is hereby granted, free of charge, to any person
20 # obtaining a copy of this software and associated documentation files
21 # (the “Software”), to deal in the Software without restriction,
22 # including without limitation the rights to use, copy, modify, merge,
23 # publish, distribute, sublicense, and/or sell copies of the Software,
24 # and to permit persons to whom the Software is furnished to do so,
25 # subject to the following conditions:
27 # The above copyright notice and this permission notice shall be
28 # included in all copies or substantial portions of the Software.
30 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
31 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
34 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
35 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
36 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42 ours=#DEB_DIVERT_EXTENSION#
43 theirs=#DEB_DIVERT_EXTENSION#-orig
50 if ! LC_ALL=C dpkg-divert --list "$package" | \
51 grep -xFq "diversion of $file to $theirfile by $package"; then
52 dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file"
61 if [ ! -L "$file" ] && [ ! -e "$file" ]; then
62 ln -s "$(basename "$ourfile")" "$file"
63 elif [ ! -L "$file" ] || \
64 [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
65 "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
66 echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
76 ourfile=$prefix$ours$suffix
77 theirfile=$prefix$theirs$suffix
78 divert_link_divert "$file" "$ourfile" "$theirfile"
79 divert_link_symlink "$file" "$ourfile" "$theirfile"
87 divert_link_divert "$file" "$ourfile" "$theirfile"
90 undivert_unlink_symlink()
95 if [ ! -L "$file" ] || \
96 [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
97 "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
98 echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
104 undivert_unlink_divert()
107 if [ ! -L "$file" ] && [ ! -e "$file" ]; then
108 dpkg-divert --remove --rename --package "$package" "$file"
110 echo "Not removing diversion of $file by $package" >&2
120 ourfile=$prefix$ours$suffix
121 theirfile=$prefix$theirs$suffix
123 undivert_unlink_symlink "$file" "$ourfile" "$theirfile"
124 undivert_unlink_divert "$file"
130 undivert_unlink_divert "$file"
133 check_undivert_unlink()
139 ourfile=$prefix$ours$suffix
140 theirfile=$prefix$theirs$suffix
142 if LC_ALL=C dpkg-divert --list "$package" | \
143 grep -xFq "diversion of $file to $theirfile by $package"; then
144 undivert_unlink "$prefix" "$suffix"
148 check_undivert_unremove()
152 if LC_ALL=C dpkg-divert --list "$package" | \
153 grep -xFq "diversion of $file to $removedfile by $package"; then
154 undivert_unremove "$file"