2
# postinst script for ptouch-driver
5
# see: dh_installdeb(1)
9
# summary of how this script can be called:
10
# * <postinst> `configure' <most-recently-configured-version>
11
# * <old-postinst> `abort-upgrade' <new version>
12
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
14
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15
# <failed-install-package> <version> `removing'
16
# <conflicting-package> <version>
17
# for details, see http://www.debian.org/doc/debian-policy/ or
18
# the debian-policy package
20
# quoting from the policy:
21
# Any necessary prompting should almost always be confined to the
22
# post-installation script, and should be protected with a conditional
23
# so that unnecessary prompting doesn't happen if a package's
24
# installation fails and the `postinst' is called with `abort-upgrade',
25
# `abort-remove' or `abort-deconfigure'.
29
# Do the following only if CUPS is running and the needed CUPS tools
31
if which lpstat > /dev/null 2>&1 && \
32
which lpinfo > /dev/null 2>&1 && \
33
which lpadmin > /dev/null 2>&1 && \
34
LC_ALL=C lpstat -h /var/run/cups/cups.sock -r | grep -v not > /dev/null 2>&1; then
35
# Update the PPD files of all already installed print queues
36
driverregexp='^foomatic:.*-ptouch\.ppd\b'
38
[ ! -z "$gennicknameregexp" ] && \
39
gennicknameregexp="; $gennicknameregexp"
40
gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp"
42
trap 'rm -f $tempfiles; exit 0' 0 HUP INT QUIT ILL ABRT PIPE TERM
43
tmpfile1=`mktemp -t updateppds.XXXXXX`
44
tempfiles="$tempfiles $tmpfile1"
45
lpinfo -h /var/run/cups/cups.sock -m | grep -E $driverregexp > $tmpfile1
48
[ -r "$ppd" ] || continue
50
lpstat -h /var/run/cups/cups.sock -p "$queue" >/dev/null 2>&1 || continue
51
nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'`
52
lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
55
tmpfile2=`mktemp -t updateppds.XXXXXX`
56
tempfiles="$tempfiles $tmpfile2"
57
cat $tmpfile1 | perl -p -e "$gennicknameregexp" | grep -E '^\S+\s+.*'"$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2
58
while read newppduri; do
59
[ "$ppdfound" = "0" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $newppduri 2>/dev/null || continue
60
newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
61
[ "$newlang" = "$lang" ] && ppdfound="1"
62
[ "$newlang" = "english" ] && englishppduri="$newppduri"
64
[ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1"
65
[ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2
70
abort-upgrade|abort-remove|abort-deconfigure)
74
echo "postinst called with unknown argument \`$1'" >&2
79
# dh_installdeb will replace this with shell code automatically
80
# generated by other debhelper scripts.