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

Revision 8dc79e2, 3.0 KB checked in by Geoffrey Thomas <geofft@…>, 11 years ago (diff)
Rename 'divert' to 'displace' and 'remove' to 'hide'
  • Property mode set to 100644
Line 
1#
2# displace_link <prefix> <suffix>
3#
4#   Ensures that the file <prefix><suffix> is properly diverted to
5#   <prefix>.divert-orig<suffix> by this package, and becomes a
6#   symbolic link to either <prefix>.divert<suffix> (default) or
7#   <prefix>.divert-orig<suffix>.
8#
9# undisplace_unlink <prefix> <suffix>
10#
11#   Undoes the action of displace_link <prefix> <suffix> specified
12#   above.
13#
14# Version: 4.0
15#
16
17package=#PACKAGE#
18
19ours=#DEB_DISPLACE_EXTENSION#
20theirs=#DEB_DISPLACE_EXTENSION#-orig
21
22displace_link_displace()
23{
24    file=$1
25    ourfile=$2
26    theirfile=$3
27    if ! LC_ALL=C dpkg-divert --list "$package" | \
28        grep -xFq "diversion of $file to $theirfile by $package"; then
29        dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file"
30    fi
31}
32
33displace_link_symlink()
34{
35    file=$1
36    ourfile=$2
37    theirfile=$3
38    if [ ! -L "$file" ] && [ ! -e "$file" ]; then
39        ln -s "$(basename "$ourfile")" "$file"
40    elif [ ! -L "$file" ] || \
41        [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
42          "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
43        echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
44    fi
45}
46
47displace_link()
48{
49    prefix=$1
50    suffix=$2
51
52    file=$prefix$suffix
53    ourfile=$prefix$ours$suffix
54    theirfile=$prefix$theirs$suffix
55    displace_link_displace "$file" "$ourfile" "$theirfile"
56    displace_link_symlink "$file" "$ourfile" "$theirfile"
57}
58
59displace_hide()
60{
61    file=$1
62    ourfile=""
63    theirfile=$2
64    displace_link_displace "$file" "$ourfile" "$theirfile"
65}
66
67undisplace_unlink_symlink()
68{
69    file="$1"
70    ourfile="$2"
71    theirfile="$3"
72    if [ ! -L "$file" ] || \
73        [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
74          "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
75        echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
76    else
77        rm -f "$file"
78    fi
79}
80
81undisplace_unlink_displace()
82{
83    file="$1"
84    if [ ! -L "$file" ] && [ ! -e "$file" ]; then
85        dpkg-divert --remove --rename --package "$package" "$file"
86    else
87        echo "Not removing diversion of $file by $package" >&2
88    fi
89}
90
91undisplace_unlink()
92{
93    prefix=$1
94    suffix=$2
95
96    file=$prefix$suffix
97    ourfile=$prefix$ours$suffix
98    theirfile=$prefix$theirs$suffix
99
100    undisplace_unlink_symlink "$file" "$ourfile" "$theirfile"
101    undisplace_unlink_displace "$file"
102}
103
104undisplace_unhide()
105{
106    file=$1
107    undisplace_unlink_displace "$file"
108}
109
110check_undisplace_unlink()
111{
112    prefix=$1
113    suffix=$2
114
115    file=$prefix$suffix
116    ourfile=$prefix$ours$suffix
117    theirfile=$prefix$theirs$suffix
118
119    if LC_ALL=C dpkg-divert --list "$package" | \
120        grep -xFq "diversion of $file to $theirfile by $package"; then
121        undisplace_unlink "$prefix" "$suffix"
122    fi
123}
124
125check_undisplace_unhide()
126{
127    file=$1
128    hiddenfile=$2
129    if LC_ALL=C dpkg-divert --list "$package" | \
130        grep -xFq "diversion of $file to $hiddenfile by $package"; then
131        undisplace_unhide "$file"
132    fi
133}
Note: See TracBrowser for help on using the repository browser.