This file is indexed.

postinst is in cups 1.7.2-0ubuntu1.11.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#! /bin/sh
# postinst script for cups
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see /usr/doc/packaging-manual/
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

# Debconf
. /usr/share/debconf/confmodule

# Default Configuration file
if [ -e /etc/default/cups ]; then
	. /etc/default/cups
fi

if [ "$1" = configure ]; then
    # set up custom PPD directory
    chown root:lpadmin /usr/share/ppd/custom 2>/dev/null || true
    chmod 3775 /usr/share/ppd/custom 2>/dev/null || true

    # Generate raw MIME handling files if they don't already exist.
    if [ ! -e /etc/cups/raw.types ]; then
	cat >/etc/cups/raw.types <<EOF
# This file was generated by the cups package.  You may change it, or
# reconfigure this file with dpkg-reconfigure.  If it is removed, it
# will be regenerated by the package scripts.

application/octet-stream
EOF
    fi
    if [ ! -e /etc/cups/raw.convs ]; then
	cat >/etc/cups/raw.convs <<EOF
# This file was generated by the cups package.  You may change it, or
# reconfigure this file with dpkg-reconfigure.  If it is removed, it
# will be regenerated by the package scripts.

application/octet-stream	application/vnd.cups-raw	0	-
EOF
    fi

    # Set up raw printing of application/octet-stream if desired.
    db_fget cupsys/raw-print changed
    if [ "$RET" = "true" ]; then
	mv /etc/cups/raw.convs /etc/cups/raw.convs-convert
	db_get cupsys/raw-print
	if [ "$RET" = "true" ]; then
	    sed 's/^\s*#\s*application/application/' \
		< /etc/cups/raw.convs-convert > /etc/cups/raw.convs
	else
	    sed 's/^application/#application/' \
		< /etc/cups/raw.convs-convert > /etc/cups/raw.convs
	fi
	rm -f /etc/cups/raw.convs-convert
	db_fset cupsys/raw-print changed false
    fi
    # Set up backends
    db_get cupsys/backend && SELECTED=$RET
    # We remove the scsi backend from the output as it got removed in CUPS 1.5.0
    # We also remove the IPP backends as they are statically in cups-daemon now
    list=`echo $SELECTED | sed -e 's/, /,/g' | sed -e 's/scsi,*\b//g' | sed -e 's/ipp,*\b//g' | sed -e 's/ipps,*\b//g' | sed -e 's/ipp14,*\b//g' | sed -e 's/parallel,*\b//g' | sed -e 's/serial,*\b//g'`
     if dpkg --compare-versions "$2" lt-nl "1.5.3-2.1"; then
        # Make sure the above dropped backends are effectively away
 	for i in scsi parallel serial; do
		# Drop the file if it doesn't belong to any package.
		dpkg -S /usr/lib/cups/backend/$i 2>/dev/null 1>&2 || rm -f /usr/lib/cups/backend/$i 
	done
	if ! echo $list | grep -q "\bipp14\b"; then
	    list=`echo $list | sed -e 's/\bipp\b/ipp,ipp14/g'`
	fi
    fi
    save_IFS=$IFS
    IFS=,
    (cd /usr/lib/cups/backend && rm -f lpd socket usb snmp dnssd mdns)
    for module in $list; do
      ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
      if [ "$module" = "dnssd" ]; then
	ln /usr/lib/cups/backend/dnssd /usr/lib/cups/backend/mdns
      fi
    done
    IFS=$save_IFS

    # activate new backends on upgrades
    db_fset cupsys/backend changed false

    # Resync Debconf database with real state
    list=`( cd /usr/lib/cups/backend && for f in lpd socket usb snmp dnssd; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'`
    db_set cupsys/backend $list;

    if dpkg --compare-versions "$2" lt "1.5.3-2.1"; then
        modprobe -b usblp >/dev/null 2>&1 || :
    fi
fi

# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/cups/acroread.conf 1.6.2-9~ -- "$@"
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/cups/pdftops.conf 1.6.2-9~ -- "$@"
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/modprobe.d/blacklist-cups-usblp.conf 1.5.3-2.1~ -- "$@"
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper mv_conffile /etc/pam.d/cups /etc/pam.d/cups-daemon 1.6.1~ -- "$@"
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper mv_conffile /etc/logrotate.d/cups /etc/logrotate.d/cups-daemon 1.6.1~ -- "$@"
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/logrotate.d/cups 1.6.2-3~ -- "$@"
# End automatically added section


# ppd_updater is supposed to be launched only with a running CUPS.
ppd_updater () {
	driverregexp="$1"
	gennicknameregexp="$2"

	[ ! -z "$gennicknameregexp" ] && \
	    gennicknameregexp="; $gennicknameregexp"
	gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp"
	tmpfile1=`mktemp -t updateppds.XXXXXX`
	tempfiles="$tempfiles $tmpfile1"
	grep -E $driverregexp $tmpfile0 > $tmpfile1 || :
	cd /etc/cups/ppd
	for ppd in *.ppd; do
	    [ -r "$ppd" ] || continue
	    queue=${ppd%.ppd}
	    lpstat -h /var/run/cups/cups.sock -p "$queue" >/dev/null 2>&1 || continue
	    nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'`
	    lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
	    ppdfound="0"
	    englishppduri=""
	    tmpfile2=`mktemp -t updateppds.XXXXXX`
	    tempfiles="$tempfiles $tmpfile2"
	    cat $tmpfile1 | perl -p -e "$gennicknameregexp; s/\n*$/\n/s" | grep -E '^\S+\s+.*'"$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2
	    while read newppduri; do
		[ "$ppdfound" = "0" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $newppduri 2>/dev/null || continue
		newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
		[ "$newlang" = "$lang" ] && ppdfound="1"
		[ "$newlang" = "english" ] && englishppduri="$newppduri"
	    done < $tmpfile2
	    [ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1"
	    [ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2
	done
	return 0
}

# Do the following only if CUPS is running and the needed CUPS tools
# are available
if which lpstat > /dev/null 2>&1 && \
	which lpinfo > /dev/null 2>&1 && \
	which lpadmin > /dev/null 2>&1 && \
	LC_ALL=C lpstat -h /var/run/cups/cups.sock -r | grep -v not > /dev/null 2>&1; then

	tempfiles=
	trap 'rm -f $tempfiles; exit 0' 0 HUP INT QUIT ILL ABRT PIPE TERM
	tmpfile0=`mktemp -t updateppds.XXXXXX`
	tempfiles="$tempfiles $tmpfile0"

	lpinfo -h /var/run/cups/cups.sock -m > $tmpfile0

	if [ "$1" = configure ] ; then
		# Update CUPS included drivers' queues
		echo "Updating PPD files for cups ..."
		ppd_updater 'lsb/usr/cups-included/|drv:///sample.drv/' 's/,\s*\d+\.\d+[\d\.]*$//i'
	fi
	if [ "$1" = triggered ] || [ "$1" = configure ] ; then
		# Update external drivers' queues.
		# 
		# We log the modification dates of the file in 
		# /usr/share/cups/ppd-updaters/* after updating the PPDs 
		# according to them. These dates are more or less the creation
		# dates of the driver packages. Then we only update the PPDs of
		# packages, where the /usr/share/cups/ppd-updaters/* file has a
		# modification date different to the logged date as this means
		# that a fresh /usr/share/cups/ppd-updaters/* file and
		# therefore a fresh package got installed. This avoids updating
		# of PPDs when the corresponding package was not changed.
	        logfile=/var/cache/cups/ppd-updates
		touch $logfile
		for driverfile in `ls /usr/share/cups/ppd-updaters`; do
		        driver=`echo $driverfile | perl -p -e 's/\.ppd-updater$//' | perl -p -e 's/^printer-driver-//'`
			modtime=`ls -l --time-style=+%s /usr/share/cups/ppd-updaters/$driverfile | perl -p -e 's/^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s+(\S+)\s*$/$1\n/'`
			oldmodtime=`cat $logfile | grep " $driver$" | cut -d ' ' -f 1`
			if [ "$modtime" != "$oldmodtime" ]; then
				echo "Updating PPD files for $driver ..."
				. /usr/share/cups/ppd-updaters/${driverfile}
				ppd_updater "${DRIVER_REGEXP}" "${GENNICKNAME_REGEXP}"
				cat $logfile | grep -v " $driver$" > $logfile.new || touch $logfile.new
				echo "$modtime $driver" >> $logfile.new
				mv $logfile.new $logfile
			fi
		done
	fi
fi

db_stop
exit 0