~ubuntu-branches/ubuntu/lucid/config-package-dev/lucid-backports

« back to all changes in this revision

Viewing changes to divert.sh.in

  • Committer: Bazaar Package Importer
  • Author(s): Tim Abbott
  • Date: 2008-05-03 13:37:12 UTC
  • Revision ID: james.westby@ubuntu.com-20080503133712-fpjefhoe3hbnr30c
Tags: 4.7
* Move homepage field to source package section, so it works.
* Make DEB_TRANSFROM_FILES targets depend on common-build-arch and
  common-build-indep, so it works with architecture-dependent packages.
* Remove useless clean code from transform-files.mk.
* Move divert.mk from binary-fixup to binary-post-install.
* Add debhelper.mk to divert.mk, since we use its
  binary-post-install/package target.
* Change maintainer to me, rather than debathena@mit.edu, since I'll be
  maintaining config-package-dev in Debian.
* Upload to Debian (Closes: #469107)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#
 
14
# Version: 4.0
 
15
#
 
16
 
 
17
package=#PACKAGE#
 
18
 
 
19
ours=#DEB_DIVERT_EXTENSION#
 
20
theirs=#DEB_DIVERT_EXTENSION#-orig
 
21
 
 
22
divert_link_divert()
 
23
{
 
24
    file=$1
 
25
    ourfile=$2
 
26
    theirfile=$3
 
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
 
31
}
 
32
 
 
33
divert_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
 
 
47
divert_link()
 
48
{
 
49
    prefix=$1
 
50
    suffix=$2
 
51
 
 
52
    file=$prefix$suffix
 
53
    ourfile=$prefix$ours$suffix
 
54
    theirfile=$prefix$theirs$suffix
 
55
    divert_link_divert "$file" "$ourfile" "$theirfile"
 
56
    divert_link_symlink "$file" "$ourfile" "$theirfile"
 
57
}
 
58
 
 
59
divert_remove()
 
60
{
 
61
    file=$1
 
62
    ourfile=""
 
63
    theirfile=$2
 
64
    divert_link_divert "$file" "$ourfile" "$theirfile"
 
65
}
 
66
 
 
67
undivert_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
 
 
81
undivert_unlink_divert()
 
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
 
 
91
undivert_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
 
 
104
undivert_unremove()
 
105
{
 
106
    file=$1
 
107
    undivert_unlink_divert "$file"
 
108
}
 
109