1
# displace.sh.in: diversion helpers for maintainer scripts
3
# displace_link <prefix> <suffix>
5
# Ensures that the file <prefix><suffix> is properly diverted to
6
# <prefix>.divert-orig<suffix> by this package, and becomes a
7
# symbolic link to either <prefix>.divert<suffix> (default) or
8
# <prefix>.divert-orig<suffix>.
10
# undisplace_unlink <prefix> <suffix>
12
# Undoes the action of displace_link <prefix> <suffix> specified
17
# Copyright © 2008–2012 Tim Abbott <tabbott@mit.edu> and Anders
18
# Kaseorg <andersk@mit.edu>
20
# Permission is hereby granted, free of charge, to any person
21
# obtaining a copy of this software and associated documentation files
22
# (the “Software”), to deal in the Software without restriction,
23
# including without limitation the rights to use, copy, modify, merge,
24
# publish, distribute, sublicense, and/or sell copies of the Software,
25
# and to permit persons to whom the Software is furnished to do so,
26
# subject to the following conditions:
28
# The above copyright notice and this permission notice shall be
29
# included in all copies or substantial portions of the Software.
31
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
32
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
35
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
36
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
37
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
ours=#DEB_DISPLACE_EXTENSION#
44
theirs=#DEB_DISPLACE_EXTENSION#-orig
46
displace_link_displace()
51
if ! LC_ALL=C dpkg-divert --list "$package" | \
52
grep -xFq "diversion of $file to $theirfile by $package"; then
53
dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file"
57
displace_link_symlink()
62
if [ ! -L "$file" ] && [ ! -e "$file" ]; then
63
ln -s "$(basename "$ourfile")" "$file"
64
elif [ ! -L "$file" ] || \
65
[ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
66
"$(readlink "$file")" != "$(basename "$theirfile")" ]; then
67
echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
77
ourfile=$prefix$ours$suffix
78
theirfile=$prefix$theirs$suffix
79
displace_link_displace "$file" "$ourfile" "$theirfile"
80
displace_link_symlink "$file" "$ourfile" "$theirfile"
88
displace_link_displace "$file" "$ourfile" "$theirfile"
91
undisplace_unlink_symlink()
96
if [ ! -L "$file" ] || \
97
[ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
98
"$(readlink "$file")" != "$(basename "$theirfile")" ]; then
99
echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
105
undisplace_unlink_displace()
108
if [ ! -L "$file" ] && [ ! -e "$file" ]; then
109
dpkg-divert --remove --rename --package "$package" "$file"
111
echo "Not removing diversion of $file by $package" >&2
121
ourfile=$prefix$ours$suffix
122
theirfile=$prefix$theirs$suffix
124
undisplace_unlink_symlink "$file" "$ourfile" "$theirfile"
125
undisplace_unlink_displace "$file"
131
undisplace_unlink_displace "$file"
134
check_undisplace_unlink()
140
ourfile=$prefix$ours$suffix
141
theirfile=$prefix$theirs$suffix
143
if LC_ALL=C dpkg-divert --list "$package" | \
144
grep -xFq "diversion of $file to $theirfile by $package"; then
145
undisplace_unlink "$prefix" "$suffix"
149
check_undisplace_unhide()
153
if LC_ALL=C dpkg-divert --list "$package" | \
154
grep -xFq "diversion of $file to $hiddenfile by $package"; then
155
undisplace_unhide "$file"
159
# End of divert.sh.in