~ubuntu-branches/ubuntu/trusty/config-package-dev/trusty-proposed

« back to all changes in this revision

Viewing changes to displace.sh.in

  • Committer: Package Import Robot
  • Author(s): Geoffrey Thomas
  • Date: 2013-03-06 17:14:42 UTC
  • Revision ID: package-import@ubuntu.com-20130306171442-k3sj6klfu28zghqr
Tags: 5.0
* Add Debhelper support (Debathena: #867) (Closes: #693672).  This
  release includes a new command, dh_configpackage, and a sequencer
  extension, dh --with config-package.
* Use the terms "displace" and "hide" for actions of the
  config-package-dev system, instead of the terms "divert" and
  "remove", which already have existing (related) meanings in the
  context of Debian packages.
* Move examples/* to examples/cdbs/*, and create examples/debhelper/*,
  with the same packages using Debhelper 7-style packaging.

* Change config-package-dev's own packaging to Debhelper 7.
* Bump Standards-Version to 3.9.4 (no changes required).
* Update Vcs-Git and Vcs-Browser locations to new upstream.
* Drop CDBS runtime dependency. CDBS users should be explicitly
  Build-Depending on CDBS, probably through use of the @cdbs@ macro in
  debian/control.in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
41
package=#PACKAGE#
 
42
 
 
43
ours=#DEB_DISPLACE_EXTENSION#
 
44
theirs=#DEB_DISPLACE_EXTENSION#-orig
 
45
 
 
46
displace_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
 
 
57
displace_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
 
 
71
displace_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
 
 
83
displace_hide()
 
84
{
 
85
    file=$1
 
86
    ourfile=""
 
87
    theirfile=$2
 
88
    displace_link_displace "$file" "$ourfile" "$theirfile"
 
89
}
 
90
 
 
91
undisplace_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
 
 
105
undisplace_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
 
 
115
undisplace_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
 
 
128
undisplace_unhide()
 
129
{
 
130
    file=$1
 
131
    undisplace_unlink_displace "$file"
 
132
}
 
133
 
 
134
check_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
 
 
149
check_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 divert.sh.in