source: trunk/debathena/debathena/config-package-dev/divert.sh.in @ 22918

Revision 22918, 2.4 KB checked in by tabbott, 17 years ago (diff)
In config-package-dev: * Add new DEB_REMOVE_FILES_$package variable designed for removing files in .d directories. * Move the "configure-" in the filename encoding from the encode script to divert.mk, so that we can re-use the encoder for DEB_REMOVE_FILES. * Add new DEB_UNDIVERT_FILES_package and DEB_UNREMOVE_FILES_package API variables for having a new version of the package stop diverting a file. * Correct check for not generating an empty if clause when no files are being diverted. * Remove only the last DEB_DIVERT_EXTENSION from filenames.
RevLine 
[22854]1#
2# divert_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# undivert_unlink <prefix> <suffix>
10#
11#   Undoes the action of divert_link <prefix> <suffix> specified
12#   above.
13#
[22918]14# Version: 4.0
[22854]15#
16
17package=#PACKAGE#
18
19ours=#DEB_DIVERT_EXTENSION#
20theirs=#DEB_DIVERT_EXTENSION#-orig
21
[22918]22divert_link_divert()
[22854]23{
[22918]24    file=$1
25    ourfile=$2
26    theirfile=$3
[22854]27    if ! 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
[22918]31}
32
33divert_link_symlink()
34{
35    file=$1
36    ourfile=$2
37    theirfile=$3
[22854]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
[22918]47divert_link()
[22854]48{
49    prefix=$1
50    suffix=$2
51
52    file=$prefix$suffix
53    ourfile=$prefix$ours$suffix
54    theirfile=$prefix$theirs$suffix
[22918]55    divert_link_divert "$file" "$ourfile" "$theirfile"
56    divert_link_symlink "$file" "$ourfile" "$theirfile"
57}
[22854]58
[22918]59divert_remove()
60{
61    file=$1
62    ourfile=""
63    theirfile=$2
64    divert_link_divert "$file" "$ourfile" "$theirfile"
65}
66
67undivert_unlink_symlink()
68{
69    file="$1"
70    ourfile="$2"
71    theirfile="$3"
[22854]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
[22918]79}
80
81undivert_unlink_divert()
82{
83    file="$1"
[22854]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
[22918]91undivert_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    undivert_unlink_symlink "$file" "$ourfile" "$theirfile"
101    undivert_unlink_divert "$file" "$package"
102}
103
104undivert_unremove()
105{
106    file=$1
107    undivert_unlink_divert "$file"
108}
109
Note: See TracBrowser for help on using the repository browser.