root/trunk/source/config-common/divert.sh

Revision 111, 1.7 kB (checked in by broder, 16 years ago)

Starting to try and build config packages

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1 #
2 # divert_link <prefix> <suffix>
3 #
4 #   Ensures that the file <prefix><suffix> is properly diverted to
5 #   <prefix>.debathena-orig<suffix> by this package, and becomes a
6 #   symbolic link to either <prefix>.debathena<suffix> (default) or
7 #   <prefix>.debathena-orig<suffix>.
8 #
9 # undivert_unlink <prefix> <suffix>
10 #
11 #   Undoes the action of divert_link <prefix> <suffix> specified
12 #   above.
13 #
14 # Version: 3.4
15 #
16
17 ours=.macathena
18 theirs=.macathena-orig
19
20 divert_link()
21 {
22     prefix=$1
23     suffix=$2
24    
25     file=$prefix$suffix
26     ourfile=$prefix$ours$suffix
27     theirfile=$prefix$theirs$suffix
28
29     if ! dpkg-divert --list "$package" | \
30         grep -xFq "diversion of $file to $theirfile by $package"; then
31         dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file"
32     fi
33     if [ ! -L "$file" ] && [ ! -e "$file" ]; then
34         ln -s "$(basename "$ourfile")" "$file"
35     elif [ ! -L "$file" ] || \
36         [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
37           "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
38         echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
39     fi
40 }
41
42 undivert_unlink()
43 {
44     prefix=$1
45     suffix=$2
46
47     file=$prefix$suffix
48     ourfile=$prefix$ours$suffix
49     theirfile=$prefix$theirs$suffix
50
51     if [ ! -L "$file" ] || \
52         [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
53           "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
54         echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
55     else
56         rm -f "$file"
57     fi
58     if [ ! -L "$file" ] && [ ! -e "$file" ]; then
59         dpkg-divert --remove --rename --package "$package" "$file"
60     else
61         echo "Not removing diversion of $file by $package" >&2
62     fi
63 }
64
Note: See TracBrowser for help on using the browser.