1 | #! /bin/sh |
---|
2 | # postinst script for cups |
---|
3 | # |
---|
4 | # see: dh_installdeb(1) |
---|
5 | |
---|
6 | set -e |
---|
7 | |
---|
8 | # summary of how this script can be called: |
---|
9 | # * <postinst> `configure' <most-recently-configured-version> |
---|
10 | # * <old-postinst> `abort-upgrade' <new version> |
---|
11 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
---|
12 | # <new-version> |
---|
13 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
---|
14 | # <failed-install-package> <version> `removing' |
---|
15 | # <conflicting-package> <version> |
---|
16 | # for details, see /usr/doc/packaging-manual/ |
---|
17 | # |
---|
18 | # quoting from the policy: |
---|
19 | # Any necessary prompting should almost always be confined to the |
---|
20 | # post-installation script, and should be protected with a conditional |
---|
21 | # so that unnecessary prompting doesn't happen if a package's |
---|
22 | # installation fails and the `postinst' is called with `abort-upgrade', |
---|
23 | # `abort-remove' or `abort-deconfigure'. |
---|
24 | |
---|
25 | # Debconf |
---|
26 | . /usr/share/debconf/confmodule |
---|
27 | |
---|
28 | # Default Configuration file |
---|
29 | if [ -e /etc/default/cups ]; then |
---|
30 | . /etc/default/cups |
---|
31 | fi |
---|
32 | |
---|
33 | if [ "$1" = configure ]; then |
---|
34 | # Set up lpadmin group. |
---|
35 | if [ -z "`getent group lpadmin`" ]; then |
---|
36 | addgroup --system lpadmin |
---|
37 | fi |
---|
38 | |
---|
39 | if [ -L /usr/share/ppd/cups-transitional-dir ]; then |
---|
40 | rm -f /usr/share/ppd/cups-transitional-dir |
---|
41 | fi |
---|
42 | if [ -L /usr/share/cups/model/cups-included ]; then |
---|
43 | rm -f /usr/share/cups/model/cups-included |
---|
44 | fi |
---|
45 | |
---|
46 | # set up custom PPD directory |
---|
47 | chown root:lpadmin /usr/share/ppd/custom 2>/dev/null || true |
---|
48 | chmod 3775 /usr/share/ppd/custom 2>/dev/null || true |
---|
49 | |
---|
50 | # Generate raw MIME handling files if they don't already exist. |
---|
51 | if [ ! -e /etc/cups/raw.types ]; then |
---|
52 | cat >/etc/cups/raw.types <<EOF |
---|
53 | # This file was generated by the cups package. You may change it, or |
---|
54 | # reconfigure this file with dpkg-reconfigure. If it is removed, it |
---|
55 | # will be regenerated by the package scripts. |
---|
56 | |
---|
57 | application/octet-stream |
---|
58 | EOF |
---|
59 | fi |
---|
60 | if [ ! -e /etc/cups/raw.convs ]; then |
---|
61 | cat >/etc/cups/raw.convs <<EOF |
---|
62 | # This file was generated by the cups package. You may change it, or |
---|
63 | # reconfigure this file with dpkg-reconfigure. If it is removed, it |
---|
64 | # will be regenerated by the package scripts. |
---|
65 | |
---|
66 | application/octet-stream application/vnd.cups-raw 0 - |
---|
67 | EOF |
---|
68 | fi |
---|
69 | |
---|
70 | # Set up raw printing of application/octet-stream if desired. |
---|
71 | db_fget cupsys/raw-print changed |
---|
72 | if [ "$RET" = "true" ]; then |
---|
73 | mv /etc/cups/raw.convs /etc/cups/raw.convs-convert |
---|
74 | db_get cupsys/raw-print |
---|
75 | if [ "$RET" = "true" ]; then |
---|
76 | sed 's/^\s*#\s*application/application/' \ |
---|
77 | < /etc/cups/raw.convs-convert > /etc/cups/raw.convs |
---|
78 | else |
---|
79 | sed 's/^application/#application/' \ |
---|
80 | < /etc/cups/raw.convs-convert > /etc/cups/raw.convs |
---|
81 | fi |
---|
82 | rm -f /etc/cups/raw.convs-convert |
---|
83 | db_fset cupsys/raw-print changed false |
---|
84 | fi |
---|
85 | # Set up backends |
---|
86 | db_get cupsys/backend && SELECTED=$RET |
---|
87 | list=`echo $SELECTED | sed -e 's/, /,/g'` |
---|
88 | save_IFS=$IFS |
---|
89 | IFS=, |
---|
90 | (cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp dnssd) |
---|
91 | for module in $list; do |
---|
92 | ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module |
---|
93 | if [ "$module" = "ipp" ]; then |
---|
94 | ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http |
---|
95 | fi |
---|
96 | done |
---|
97 | IFS=$save_IFS |
---|
98 | |
---|
99 | # activate new backends on upgrades |
---|
100 | db_fset cupsys/backend changed false |
---|
101 | |
---|
102 | # Resync Debconf database with real state |
---|
103 | list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp dnssd; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'` |
---|
104 | db_set cupsys/backend $list; |
---|
105 | |
---|
106 | if [ -f /etc/cups/classes.conf ]; then |
---|
107 | chown root:lp /etc/cups/classes.conf ; chmod 600 /etc/cups/classes.conf |
---|
108 | fi |
---|
109 | if [ -f /etc/cups/printers.conf ]; then |
---|
110 | chown root:lp /etc/cups/printers.conf ; chmod 600 /etc/cups/printers.conf |
---|
111 | fi |
---|
112 | |
---|
113 | # symlink snakeoil SSL certificate if present |
---|
114 | if [ -e /etc/ssl/certs/ssl-cert-snakeoil.pem -a \ |
---|
115 | -e /etc/ssl/private/ssl-cert-snakeoil.key -a \ |
---|
116 | -n "`getent group ssl-cert`" -a ! -e /etc/cups/ssl/server.crt \ |
---|
117 | -a ! -e /etc/cups/ssl/server.key -a ! -h /etc/cups/ssl/server.crt \ |
---|
118 | -a ! -h /etc/cups/ssl/server.key ]; then |
---|
119 | ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/cups/ssl/server.crt |
---|
120 | ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/cups/ssl/server.key |
---|
121 | fi |
---|
122 | |
---|
123 | APP_PROFILE=/etc/apparmor.d/usr.sbin.cupsd |
---|
124 | if [ -f "$APP_PROFILE" ]; then |
---|
125 | # Add the local/ include |
---|
126 | LOCAL_APP_PROFILE=/etc/apparmor.d/local/usr.sbin.cupsd |
---|
127 | |
---|
128 | test -e "$LOCAL_APP_PROFILE" || { |
---|
129 | tmp=`mktemp` |
---|
130 | cat <<EOM > "$tmp" |
---|
131 | # Site-specific additions and overrides for usr.sbin.cupsd. |
---|
132 | # For more details, please see /etc/apparmor.d/local/README. |
---|
133 | EOM |
---|
134 | mkdir `dirname $LOCAL_APP_PROFILE` 2>/dev/null || true |
---|
135 | mv -f "$tmp" "$LOCAL_APP_PROFILE" |
---|
136 | chmod 644 "$LOCAL_APP_PROFILE" |
---|
137 | } |
---|
138 | |
---|
139 | # Reload the profile, including any abstraction updates |
---|
140 | if aa-status --enabled 2>/dev/null; then |
---|
141 | apparmor_parser -r -T -W "$APP_PROFILE" || true |
---|
142 | fi |
---|
143 | fi |
---|
144 | |
---|
145 | # init.d priority transition |
---|
146 | if dpkg --compare-versions "$2" le-nl "1.3.9-15"; then |
---|
147 | for l in 2 3 4 5; do |
---|
148 | old=/etc/rc${l}.d/S20cups |
---|
149 | new=/etc/rc${l}.d/S50cups |
---|
150 | if [ -e "$old" ] && [ ! -e "$new" ]; then |
---|
151 | mv "$old" "$new" |
---|
152 | fi |
---|
153 | done |
---|
154 | fi |
---|
155 | |
---|
156 | # Clear cache if we upgrade to 1.4.x |
---|
157 | if dpkg --compare-versions "$2" lt-nl "1.4.1-5"; then |
---|
158 | rm /var/cache/cups/* 2> /dev/null || : |
---|
159 | fi |
---|
160 | |
---|
161 | # Manage printcap file and associated symlinks |
---|
162 | if [ -e /etc/cups/cupsd.conf ]; then |
---|
163 | if [ -e /etc/printcap.cups ]; then |
---|
164 | rm -f /etc/printcap.cups |
---|
165 | fi |
---|
166 | if [ -L /etc/printcap -a ! -e /etc/printcap ]; then |
---|
167 | rm -f /etc/printcap |
---|
168 | fi |
---|
169 | |
---|
170 | printcap_file=`egrep '^Printcap ' /etc/cups/cupsd.conf | awk '{print $2}' | tail -n 1` |
---|
171 | if [ -z "$printcap_file" ]; then |
---|
172 | printcap_file=/var/run/cups/printcap |
---|
173 | fi |
---|
174 | if [ ! -e /etc/printcap -a -e $printcap_file ]; then |
---|
175 | ln -s $printcap_file /etc/printcap |
---|
176 | fi |
---|
177 | fi |
---|
178 | |
---|
179 | # Clean up after some broken cups-pdf versions |
---|
180 | if dpkg --compare-versions "$2" lt-nl "1.4.4-1"; then |
---|
181 | chmod 755 /usr/lib/cups/backend /usr/lib/cups/backend-available |
---|
182 | fi |
---|
183 | fi |
---|
184 | |
---|
185 | # Automatically added by dh_installinit |
---|
186 | if [ -e "/etc/init/cups.conf" ]; then |
---|
187 | # start fails if already running |
---|
188 | start cups || : |
---|
189 | fi |
---|
190 | # End automatically added section |
---|
191 | # Automatically added by dh_usrlocal |
---|
192 | if [ "$1" = configure ]; then |
---|
193 | ( |
---|
194 | while read line; do |
---|
195 | set -- $line |
---|
196 | dir="$1"; mode="$2"; user="$3"; group="$4" |
---|
197 | if [ ! -e "$dir" ]; then |
---|
198 | if mkdir "$dir" 2>/dev/null; then |
---|
199 | chown "$user":"$group" "$dir" |
---|
200 | chmod "$mode" "$dir" |
---|
201 | fi |
---|
202 | fi |
---|
203 | done |
---|
204 | ) << DATA |
---|
205 | /usr/local/share 2775 root staff |
---|
206 | /usr/local/share/ppd 2775 root staff |
---|
207 | DATA |
---|
208 | fi |
---|
209 | # End automatically added section |
---|
210 | |
---|
211 | |
---|
212 | # Do the following only if CUPS is running and the needed CUPS tools |
---|
213 | # are available |
---|
214 | if [ "$1" = configure ] && \ |
---|
215 | which lpstat > /dev/null 2>&1 && \ |
---|
216 | which lpinfo > /dev/null 2>&1 && \ |
---|
217 | which lpadmin > /dev/null 2>&1 && \ |
---|
218 | LC_ALL=C lpstat -h /var/run/cups/cups.sock -r | grep -v not > /dev/null 2>&1; then |
---|
219 | # Update the PPD files of all already installed print queues |
---|
220 | driverregexp='lsb/usr/cups-included/|drv:///sample.drv/' |
---|
221 | gennicknameregexp='s/,\s*\d+\.\d+[\d\.]*$//i' |
---|
222 | [ ! -z "$gennicknameregexp" ] && \ |
---|
223 | gennicknameregexp="; $gennicknameregexp" |
---|
224 | gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp" |
---|
225 | tempfiles= |
---|
226 | trap 'rm -f $tempfiles; exit 0' 0 HUP INT QUIT ILL ABRT PIPE TERM |
---|
227 | tmpfile1=`mktemp -t updateppds.XXXXXX` |
---|
228 | tempfiles="$tempfiles $tmpfile1" |
---|
229 | lpinfo -h /var/run/cups/cups.sock -m | grep -E $driverregexp > $tmpfile1 |
---|
230 | cd /etc/cups/ppd |
---|
231 | for ppd in *.ppd; do |
---|
232 | [ -r "$ppd" ] || continue |
---|
233 | queue=${ppd%.ppd} |
---|
234 | lpstat -h /var/run/cups/cups.sock -p "$queue" >/dev/null 2>&1 || continue |
---|
235 | nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'` |
---|
236 | lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'` |
---|
237 | ppdfound="0" |
---|
238 | englishppduri="" |
---|
239 | tmpfile2=`mktemp -t updateppds.XXXXXX` |
---|
240 | tempfiles="$tempfiles $tmpfile2" |
---|
241 | cat $tmpfile1 | perl -p -e "$gennicknameregexp" | grep -i "$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2 |
---|
242 | while read newppduri; do |
---|
243 | [ "$ppdfound" = "0" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $newppduri 2>/dev/null || continue |
---|
244 | newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'` |
---|
245 | [ "$newlang" = "$lang" ] && ppdfound="1" |
---|
246 | [ "$newlang" = "english" ] && englishppduri="$newppduri" |
---|
247 | done < $tmpfile2 |
---|
248 | [ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1" |
---|
249 | [ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2 |
---|
250 | done |
---|
251 | fi |
---|
252 | |
---|
253 | db_stop |
---|
254 | exit 0 |
---|