home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / dpkg / info / cups.postinst < prev    next >
Encoding:
Text File  |  2009-06-18  |  8.3 KB  |  250 lines

  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. case "$1" in
  34.     configure)
  35.     # Set up lpadmin group.
  36.     if [ -z "`getent group lpadmin`" ]; then 
  37.         addgroup --system lpadmin
  38.     fi
  39.  
  40.     if [ -L /usr/share/ppd/cups-transitional-dir ]; then
  41.         rm -f /usr/share/ppd/cups-transitional-dir
  42.     fi
  43.     if [ -L /usr/share/cups/model/cups-included ]; then
  44.         rm -f /usr/share/cups/model/cups-included
  45.     fi
  46.  
  47.     # Generate raw MIME handling files if they don't already exist.
  48.     if [ ! -e /etc/cups/raw.types ]; then
  49.         cat >/etc/cups/raw.types <<EOF
  50. # This file was generated by the cups package.  You may change it, or
  51. # reconfigure this file with dpkg-reconfigure.  If it is removed, it
  52. # will be regenerated by the package scripts.
  53.  
  54. application/octet-stream
  55. EOF
  56.     fi
  57.     if [ ! -e /etc/cups/raw.convs ]; then
  58.         cat >/etc/cups/raw.convs <<EOF
  59. # This file was generated by the cups package.  You may change it, or
  60. # reconfigure this file with dpkg-reconfigure.  If it is removed, it
  61. # will be regenerated by the package scripts.
  62.  
  63. application/octet-stream    application/vnd.cups-raw    0    -
  64. EOF
  65.     fi
  66.  
  67.     # Set up raw printing of application/octet-stream if desired.
  68.     db_fget cupsys/raw-print changed
  69.     if [ "$RET" = "true" ]; then
  70.         mv /etc/cups/raw.convs /etc/cups/raw.convs-convert
  71.         db_get cupsys/raw-print
  72.         if [ "$RET" = "true" ]; then
  73.         sed 's/^\s*#\s*application/application/' \
  74.             < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
  75.         else
  76.         sed 's/^application/#application/' \
  77.             < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
  78.         fi
  79.         rm -f /etc/cups/raw.convs-convert
  80.         db_fset cupsys/raw-print changed false
  81.     fi
  82.     # Set up backends
  83.     db_get cupsys/backend && SELECTED=$RET
  84.     list=`echo $SELECTED | sed -e 's/, /,/g'`
  85.     save_IFS=$IFS
  86.     IFS=,
  87.     (cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp dnssd)
  88.     for module in $list; do
  89.       ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
  90.       if [ "$module" = "ipp" ]; then
  91.             ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http
  92.       fi
  93.     done
  94.     IFS=$save_IFS
  95.  
  96.     # activate new backends on upgrades
  97.     db_fset cupsys/backend changed false
  98.     
  99.     if dpkg --compare-versions "$2" lt-nl "1.3.4-2"; then
  100.         for module in snmp scsi serial dnssd; do
  101.             [ -e /usr/lib/cups/backend/$module ] || \
  102.             ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
  103.         done
  104.     fi
  105.     
  106.     # Resync Debconf database with real state
  107.     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/, $//'`
  108.     db_set cupsys/backend $list;
  109.  
  110.     if [ -f /etc/cups/classes.conf ]; then
  111.       chown root:lp /etc/cups/classes.conf ; chmod 600 /etc/cups/classes.conf
  112.     fi
  113.     if [ -f /etc/cups/printers.conf ]; then
  114.       chown root:lp /etc/cups/printers.conf ; chmod 600 /etc/cups/printers.conf
  115.     fi
  116.     # Add symlink to local files required by LSB
  117.     if [ ! -e /usr/share/ppd/1-local-admin -a ! -L /usr/share/ppd/1-local-admin ]; then
  118.       ln -s /usr/local/share/ppd /usr/share/ppd/1-local-admin
  119.     fi
  120.     if [ ! -e /usr/share/ppd/2-third-party -a ! -L /usr/share/ppd/2-third-party ]; then
  121.       ln -s /opt/share/ppd /usr/share/ppd/2-third-party
  122.     fi
  123.  
  124.         # symlink snakeoil SSL certificate if present
  125.         if [ -e /etc/ssl/certs/ssl-cert-snakeoil.pem -a \
  126.               -e /etc/ssl/private/ssl-cert-snakeoil.key -a \
  127.               -n "`getent group ssl-cert`" -a ! -e /etc/cups/ssl/server.crt -a \
  128.               ! -e /etc/cups/ssl/server.key ]; then
  129.              ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/cups/ssl/server.crt
  130.              ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/cups/ssl/server.key
  131.         fi 
  132.  
  133.         # Remove shutdown and reboot links; this init script does not need them.
  134.         if dpkg --compare-versions "$2" lt-nl "1.3.6-2"; then
  135.             rm -f /etc/rc0.d/K??cups /etc/rc6.d/K??cups
  136.         fi
  137.  
  138.         # Reload AppArmor profile if present
  139.         if [ -e /etc/apparmor.d/usr.sbin.cupsd ] && [ -x /etc/init.d/apparmor ]; then
  140.             invoke-rc.d apparmor force-reload || true
  141.         fi
  142.  
  143.     # init.d priority transition
  144.     if dpkg --compare-versions "$2" le-nl "1.3.9-15"; then
  145.         for l in 2 3 4 5; do
  146.         old=/etc/rc${l}.d/S20cups
  147.         new=/etc/rc${l}.d/S50cups
  148.         if [ -e "$old" ] && [ ! -e "$new" ]; then
  149.             mv "$old" "$new"
  150.         fi
  151.         done
  152.     fi
  153.     ;;
  154.  
  155.     abort-upgrade|abort-remove|abort-deconfigure)
  156.  
  157.     ;;
  158.  
  159.     *)
  160.         echo "postinst called with unknown argument \`$1'" >&2
  161.         exit 0
  162.     ;;
  163. esac
  164.  
  165. # dh_installdeb will replace this with shell code automatically
  166. # generated by other debhelper scripts.
  167.  
  168. # Automatically added by dh_installdocs
  169. if [ "$1" = configure ] && which install-docs >/dev/null 2>&1; then
  170.     install-docs -i /usr/share/doc-base/cups
  171. fi
  172. # End automatically added section
  173. # Automatically added by dh_installinit
  174. if [ -x "/etc/init.d/cups" ]; then
  175.     update-rc.d cups start 50 2 3 4 5 . stop 80 1 . >/dev/null
  176.     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  177.         invoke-rc.d cups start || exit $?
  178.     else
  179.         /etc/init.d/cups start || exit $?
  180.     fi
  181. fi
  182. # End automatically added section
  183. # Automatically added by dh_usrlocal
  184. if [ "$1" = configure ]; then
  185. (
  186.     while read line; do
  187.         set -- $line
  188.         dir="$1"; mode="$2"; user="$3"; group="$4"
  189.         if [ ! -e "$dir" ]; then
  190.             if mkdir "$dir" 2>/dev/null; then
  191.                 chown "$user":"$group" "$dir"
  192.                 chmod "$mode" "$dir"
  193.             fi
  194.         fi
  195.     done
  196. ) << DATA
  197. /usr/local/share 2775 root staff
  198. /usr/local/share/ppd 2775 root staff
  199. DATA
  200. fi
  201. # End automatically added section
  202.  
  203.  
  204. if [ "$1" = configure ]; then
  205.     # Do the following only if CUPS is running and the needed CUPS tools
  206.     # are available
  207.     if which lpstat > /dev/null 2>&1 && \
  208.     which lpinfo > /dev/null 2>&1 && \
  209.     which lpadmin > /dev/null 2>&1 && \
  210.     lpstat -r > /dev/null 2>&1; then
  211.      # Update the PPD files of all already installed print queues
  212.     driverregexp='^lsb/usr/cups-included/'
  213.     gennicknameregexp='s/,\s*\d+\.\d+[\d\.]*$//i'
  214.     [ ! -z "$gennicknameregexp" ] && \
  215.         gennicknameregexp="; $gennicknameregexp"
  216.     gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp"
  217.     tempfiles=
  218.     trap 'rm -f $tempfiles; exit 0' 0 1 2 13 15
  219.     tmpfile1=`mktemp -t updateppds.XXXXXX`
  220.     tempfiles="$tempfiles $tmpfile1"
  221.     lpinfo -m | grep -E $driverregexp > $tmpfile1
  222.     cd /etc/cups/ppd
  223.     for ppd in *.ppd; do
  224.         [ -r "$ppd" ] || continue
  225.         queue=${ppd%.ppd}
  226.         lpstat -p "$queue" >/dev/null 2>&1 || continue
  227.         nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'`
  228.         lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
  229.         ppdfound="0"
  230.         englishppduri=""
  231.         tmpfile2=`mktemp -t updateppds.XXXXXX`
  232.         tempfiles="$tempfiles $tmpfile2"
  233.         cat $tmpfile1 | perl -p -e "$gennicknameregexp" | grep -E '^\S+\s+.*'"$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2
  234.         while read newppduri; do
  235.         [ "$ppdfound" = "0" ] && lpadmin -p "$queue" -m $newppduri 2>/dev/null || continue
  236.         newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
  237.         [ "$newlang" = "$lang" ] && ppdfound="1"
  238.         [ "$newlang" = "english" ] && englishppduri="$newppduri"
  239.         done < $tmpfile2
  240.         [ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1"
  241.         [ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2
  242.     done
  243.     fi
  244. fi
  245.  
  246. db_stop
  247. exit 0
  248.  
  249.  
  250.