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

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