[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 | |
---|
| 17 | package=#PACKAGE# |
---|
| 18 | |
---|
| 19 | ours=#DEB_DIVERT_EXTENSION# |
---|
| 20 | theirs=#DEB_DIVERT_EXTENSION#-orig |
---|
| 21 | |
---|
[22918] | 22 | divert_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 | |
---|
| 33 | divert_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] | 47 | divert_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] | 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" |
---|
[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 | |
---|
| 81 | undivert_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] | 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 | |
---|