~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to debian/hplip-cups.postinst

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-10-06 15:03:44 UTC
  • mfrom: (1.6.1) (20.1.16 quantal)
  • Revision ID: package-import@ubuntu.com-20121006150344-2p3xz26br0t3hu2q
Tags: 3.12.10-1
* New upstream release
  - Fixes "Network scanning fails (Closes: #683033)
* quilt refresh hplip-syslog-fix-debug-messages-to-error.dpatch
* Fix "error in clean build env" updated debian/rules (Closes: #687129)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
# postinst script for hplip-cups
3
 
# $Id: $
4
 
#
5
 
# see: dh_installdeb(1)
6
 
 
7
 
set -e
8
 
 
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>
13
 
#          <new-version>
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
19
 
#
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'.
26
 
 
27
 
case "$1" in
28
 
    configure)
29
 
        # Do the following only if CUPS is running and the needed CUPS tools
30
 
        # are available
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='drv:///hpcups.drv/|lsb/usr/hplip/HP/HP-Fax.*-hpcups'
37
 
            gennicknameregexp=' s/,?(\s*hpijs,?|,)\s*[\d\.]+[a-zA-Z]*[\d\.]*\s*$//; s/\s*(Foomatic\/|)(hpijs)(\s*\S+|)$//i; s/,?\s*hpcups,?\s+[\d\.]+[a-zA-Z]*[\d\.]*\s*$//; s/\s*(Foomatic\/|)(hpcups)(\s*\S+|)$//i; s/\s*Series$//i; s/(HP\s+)PhotoSmart(\s+)/\1PS\2/i; s/(HP\s+)DeskJet(\s+)/\1DJ\2/i; s/(HP\s+)Color\s*(LaserJet|LJ)(\s+)/\1CLJ\3/i; s/(HP\s+)LaserJet(\s+)/\1LJ\2/i; s/(HP\s+)OfficeJet(\s+)/\1OJ\2/i; s/(HP\s+)Business\s*InkJet(\s+)/\1BIJ\2/i; s/(HP\s+)DesignJet(\s+)/\1DESIGNJ\2/i; s/(HP\s+)Printer\s*Scanner\s*Copier(\s+)/\1PSC\2/i; s/(HP\s+)Color\s*InkJet\s*Printer\s+/\1/i; s/\s+(zjs|zxs|pcl3)//i'
38
 
            [ ! -z "$gennicknameregexp" ] && \
39
 
                gennicknameregexp="; $gennicknameregexp"
40
 
            gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp"
41
 
            tempfiles=
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
46
 
            cd /etc/cups/ppd
47
 
            for ppd in *.ppd; do
48
 
                [ -r "$ppd" ] || continue
49
 
                queue=${ppd%.ppd}
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'`
53
 
                ppdfound="0"
54
 
                englishppduri=""
55
 
                tmpfile2=`mktemp -t updateppds.XXXXXX`
56
 
                tempfiles="$tempfiles $tmpfile2"
57
 
                cat $tmpfile1 | perl -p -e "$gennicknameregexp; s/\s*$/\n/" | grep -E '\b'"$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"
63
 
                done < $tmpfile2
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
66
 
            done
67
 
        fi
68
 
    ;;
69
 
 
70
 
    abort-upgrade|abort-remove|abort-deconfigure)
71
 
    ;;
72
 
 
73
 
    *)
74
 
        echo "postinst called with unknown argument \`$1'" >&2
75
 
        exit 1
76
 
    ;;
77
 
esac
78
 
 
79
 
# dh_installdeb will replace this with shell code automatically
80
 
# generated by other debhelper scripts.
81
 
 
82
 
#DEBHELPER#
83
 
 
84
 
exit 0