source: trunk/debathena/debathena/config-package-dev/displace.sh.in @ 25844

Revision 25844, 4.2 KB checked in by geofft, 12 years ago (diff)
Sync config-package-dev 5.0 from Debian unstable.
RevLine 
[25844]1# displace.sh.in: diversion helpers for maintainer scripts
[22854]2#
[25844]3# displace_link <prefix> <suffix>
[22854]4#
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>.
9#
[25844]10# undisplace_unlink <prefix> <suffix>
[22854]11#
[25844]12#   Undoes the action of displace_link <prefix> <suffix> specified
[22854]13#   above.
14#
[22918]15# Version: 4.0
[22854]16#
[25844]17# Copyright © 2008–2012 Tim Abbott <tabbott@mit.edu> and Anders
18# Kaseorg <andersk@mit.edu>
19#
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:
27#
28# The above copyright notice and this permission notice shall be
29# included in all copies or substantial portions of the Software.
30#
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
38# SOFTWARE.
39#
[22854]40
41package=#PACKAGE#
42
[25844]43ours=#DEB_DISPLACE_EXTENSION#
44theirs=#DEB_DISPLACE_EXTENSION#-orig
[22854]45
[25844]46displace_link_displace()
[22854]47{
[22918]48    file=$1
49    ourfile=$2
50    theirfile=$3
[25427]51    if ! LC_ALL=C dpkg-divert --list "$package" | \
[22854]52        grep -xFq "diversion of $file to $theirfile by $package"; then
53        dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file"
54    fi
[22918]55}
56
[25844]57displace_link_symlink()
[22918]58{
59    file=$1
60    ourfile=$2
61    theirfile=$3
[22854]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
68    fi
69}
70
[25844]71displace_link()
[22854]72{
73    prefix=$1
74    suffix=$2
75
76    file=$prefix$suffix
77    ourfile=$prefix$ours$suffix
78    theirfile=$prefix$theirs$suffix
[25844]79    displace_link_displace "$file" "$ourfile" "$theirfile"
80    displace_link_symlink "$file" "$ourfile" "$theirfile"
[22918]81}
[22854]82
[25844]83displace_hide()
[22918]84{
85    file=$1
86    ourfile=""
87    theirfile=$2
[25844]88    displace_link_displace "$file" "$ourfile" "$theirfile"
[22918]89}
90
[25844]91undisplace_unlink_symlink()
[22918]92{
93    file="$1"
94    ourfile="$2"
95    theirfile="$3"
[22854]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
100    else
101        rm -f "$file"
102    fi
[22918]103}
104
[25844]105undisplace_unlink_displace()
[22918]106{
107    file="$1"
[22854]108    if [ ! -L "$file" ] && [ ! -e "$file" ]; then
109        dpkg-divert --remove --rename --package "$package" "$file"
110    else
111        echo "Not removing diversion of $file by $package" >&2
112    fi
113}
114
[25844]115undisplace_unlink()
[22918]116{
117    prefix=$1
118    suffix=$2
119
120    file=$prefix$suffix
121    ourfile=$prefix$ours$suffix
122    theirfile=$prefix$theirs$suffix
123
[25844]124    undisplace_unlink_symlink "$file" "$ourfile" "$theirfile"
125    undisplace_unlink_displace "$file"
[22918]126}
127
[25844]128undisplace_unhide()
[22918]129{
130    file=$1
[25844]131    undisplace_unlink_displace "$file"
[22918]132}
133
[25844]134check_undisplace_unlink()
[24906]135{
136    prefix=$1
137    suffix=$2
138
139    file=$prefix$suffix
140    ourfile=$prefix$ours$suffix
141    theirfile=$prefix$theirs$suffix
142
[25427]143    if LC_ALL=C dpkg-divert --list "$package" | \
[24906]144        grep -xFq "diversion of $file to $theirfile by $package"; then
[25844]145        undisplace_unlink "$prefix" "$suffix"
[24906]146    fi
147}
148
[25844]149check_undisplace_unhide()
[24906]150{
151    file=$1
[25844]152    hiddenfile=$2
[25427]153    if LC_ALL=C dpkg-divert --list "$package" | \
[25844]154        grep -xFq "diversion of $file to $hiddenfile by $package"; then
155        undisplace_unhide "$file"
[24906]156    fi
157}
[25844]158
159# End of divert.sh.in
Note: See TracBrowser for help on using the repository browser.