source: config-package-dev/displace.sh.in @ a63dcf1

Revision a63dcf1, 4.2 KB checked in by Geoffrey Thomas <geofft@…>, 9 years ago (diff)
displace.sh.in: Fix ending comment
  • Property mode set to 100644
Line 
1# displace.sh.in: diversion helpers for maintainer scripts
2#
3# displace_link <prefix> <suffix>
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#
10# undisplace_unlink <prefix> <suffix>
11#
12#   Undoes the action of displace_link <prefix> <suffix> specified
13#   above.
14#
15# Version: 4.0
16#
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#
40
41package=#PACKAGE#
42
43ours=#DEB_DISPLACE_EXTENSION#
44theirs=#DEB_DISPLACE_EXTENSION#-orig
45
46displace_link_displace()
47{
48    file=$1
49    ourfile=$2
50    theirfile=$3
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"
54    fi
55}
56
57displace_link_symlink()
58{
59    file=$1
60    ourfile=$2
61    theirfile=$3
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
71displace_link()
72{
73    prefix=$1
74    suffix=$2
75
76    file=$prefix$suffix
77    ourfile=$prefix$ours$suffix
78    theirfile=$prefix$theirs$suffix
79    displace_link_displace "$file" "$ourfile" "$theirfile"
80    displace_link_symlink "$file" "$ourfile" "$theirfile"
81}
82
83displace_hide()
84{
85    file=$1
86    ourfile=""
87    theirfile=$2
88    displace_link_displace "$file" "$ourfile" "$theirfile"
89}
90
91undisplace_unlink_symlink()
92{
93    file="$1"
94    ourfile="$2"
95    theirfile="$3"
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
103}
104
105undisplace_unlink_displace()
106{
107    file="$1"
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
115undisplace_unlink()
116{
117    prefix=$1
118    suffix=$2
119
120    file=$prefix$suffix
121    ourfile=$prefix$ours$suffix
122    theirfile=$prefix$theirs$suffix
123
124    undisplace_unlink_symlink "$file" "$ourfile" "$theirfile"
125    undisplace_unlink_displace "$file"
126}
127
128undisplace_unhide()
129{
130    file=$1
131    undisplace_unlink_displace "$file"
132}
133
134check_undisplace_unlink()
135{
136    prefix=$1
137    suffix=$2
138
139    file=$prefix$suffix
140    ourfile=$prefix$ours$suffix
141    theirfile=$prefix$theirs$suffix
142
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"
146    fi
147}
148
149check_undisplace_unhide()
150{
151    file=$1
152    hiddenfile=$2
153    if LC_ALL=C dpkg-divert --list "$package" | \
154        grep -xFq "diversion of $file to $hiddenfile by $package"; then
155        undisplace_unhide "$file"
156    fi
157}
158
159# End of displace.sh.in
Note: See TracBrowser for help on using the repository browser.