On Sat, Jun 13, 2015 at 08:18:41PM +0100, Craig Skinner wrote:
> Hi there,
> 
> Here's an update that enables CUPS to run on boxes which
> usually read-only mount both /usr & /usr/local
> 
> The current rc script alters /usr, /etc & /dev on each start/stop.
> 
> Inspiration taken from the postfix-{en,dis}able,install scripts:
> Much moved out of the rc script and into 'cups-toggle (enable|disable)'.
> 
> Freely adjust to your better experience!
> 
> I'm not sure if the script needs a copyright notice or not, here anyway.

I prefer the way it's done now.
It's automatic -- I don't want to have to remember to run yet another command 
each time I update (which is very often).


> ? files
> ? pkg/MESSAGE-main
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/print/cups/Makefile,v
> retrieving revision 1.197
> diff -u -p -r1.197 Makefile
> --- Makefile  9 Jun 2015 08:01:13 -0000       1.197
> +++ Makefile  13 Jun 2015 18:24:58 -0000
> @@ -10,7 +10,7 @@ EXTRACT_SUFX=               .tar.bz2
>  PKGNAME-main=                cups-${VERSION}
>  PKGNAME-libs=                cups-libs-${VERSION}
>  
> -REVISION-main=               0
> +REVISION-main=               1
>  REVISION-libs=               0
>  
>  CATEGORIES=          print sysutils
> @@ -124,6 +124,8 @@ post-install:
>  # Remove files now part of cups-filters
>       rm -f ${PREFIX}/share/cups/banners/*
>       rm -f ${PREFIX}/share/cups/data/testprint
> +     ${SUBST_CMD} -c -g ${BINGRP} -o ${BINOWN} -m ${BINMODE} 
> ${FILESDIR}/cups-toggle ${PREFIX}/sbin/cups-toggle
> +
>  
>  # Remove desktop file and icons; we don't really need them (it's just a
>  # launcher for http://localhost:631 and we may actually want to
> Index: pkg/PLIST-main
> ===================================================================
> RCS file: /cvs/ports/print/cups/pkg/PLIST-main,v
> retrieving revision 1.18
> diff -u -p -r1.18 PLIST-main
> --- pkg/PLIST-main    9 Jun 2015 07:39:14 -0000       1.18
> +++ pkg/PLIST-main    13 Jun 2015 18:24:58 -0000
> @@ -2,6 +2,7 @@
>  @conflict LPRng-*
>  @pkgpath print/cups
>  @pkgpath print/cups,ldap
> +@extraunexec ${TRUEPREFIX}/sbin/cups-toggle disable
>  @extraunexec rm -rf ${SYSCONFDIR}/cups/*.conf.O /var/log/cups
>  @bin bin/cancel
>  @bin bin/cupstestdsc
> @@ -118,6 +119,7 @@ sbin/accept
>  @bin sbin/cupsaccept
>  @bin sbin/cupsaddsmb
>  @bin sbin/cupsctl
> +sbin/cups-toggle
>  @mode 0500
>  @bin sbin/cupsd
>  @mode
> Index: pkg/cupsd.rc
> ===================================================================
> RCS file: /cvs/ports/print/cups/pkg/cupsd.rc,v
> retrieving revision 1.21
> diff -u -p -r1.21 cupsd.rc
> --- pkg/cupsd.rc      6 Dec 2014 11:12:44 -0000       1.21
> +++ pkg/cupsd.rc      13 Jun 2015 18:24:58 -0000
> @@ -4,75 +4,27 @@
>  
>  daemon="${TRUEPREFIX}/sbin/cupsd"
>  
> -. /etc/rc.d/rc.subr
> +. ${RCDIR}/rc.subr
>  
>  pexp="${daemon}"
>  
> -_lpfiles="/usr/bin/lpq /usr/bin/lpr /usr/bin/lprm /usr/sbin/lpc \
> -       /usr/sbin/lpd /usr/share/man/man1/lpq.1 /usr/share/man/man1/lpr.1 \
> -       /usr/share/man/man1/lprm.1 /usr/share/man/man8/lpc.8 \
> -       /usr/share/man/man8/lpd.8"
>  
> -rc_pre() {
> -     # rcexec is needed if openfiles limits are bumped and cupsd(8)
> -     # runs in debug mode to prevent MaxClients warnings in logs
> -     ${rcexec} "${daemon} ${daemon_flags} -t" || return 1
> -     [ -e /dev/lpt0 ] && chown _cups /dev/lp[a,t][0-2]
> -     # XXX cups-driverd(8) can crash when setting up a printer driver
> -     rm -f /var/cache/cups/*
> -
> -     if [ -e /usr/sbin/lpd.pre-cups -a ! -f /usr/sbin/lpd -a -L 
> /usr/sbin/lpc ]; then
> -             return
> -     elif [ ! -e /usr/sbin/lpd ]; then
> -             return
> -     else
> -             for i in ${_lpfiles}; do
> -                     if [ -f $i -a ! -L $i ]; then
> -                             mv -f $i $i.pre-cups
> -                     fi
> -             done
> -     fi
> -     if [ -e /etc/printcap ]; then
> -             if [ ! -e /etc/printcap.pre-cups ]; then
> -                     mv /etc/printcap /etc/printcap.pre-cups
> -                     ln -s ${SYSCONFDIR}/cups/printcap /etc/printcap
> -             fi
> -     else
> -             ln -s ${SYSCONFDIR}/cups/printcap /etc/printcap
> -     fi
> -     for i in lpq lpr lprm; do
> -             rm -f /usr/bin/$i
> -             ln -s ${TRUEPREFIX}/bin/$i /usr/bin/$i
> +rc_pre()
> +{
> +     for _lpfile in /usr/bin/lp{q,r,rm} /usr/sbin/lp{c,d} 
> ${SYSCONFDIR}/printcap
> +     do
> +             [[ -h ${_lpfile} ]] && continue
> +             print -u2 "${_lpfile} isn't a symlink - run 'cups-toggle 
> enable'"
> +             return 1
>       done
> -     rm -f /usr/sbin/lpc
> -     ln -s ${TRUEPREFIX}/sbin/lpc /usr/sbin/lpc
> -}
>  
> -rc_post() {
> -     if [ ! -L /usr/sbin/lpc ]; then
> -             return
> -     else
> -             for i in lpq lpr lprm; do
> -                     rm -f /usr/bin/$i
> -             done
> -
> -             rm -f /usr/sbin/lpc
> -
> -             if [ ! -e /usr/sbin/lpd.pre-cups ]; then
> -                     return
> -             else
> -                     if [ -L /etc/printcap ]; then
> -                             rm /etc/printcap
> -                     fi
> -                     for i in ${_lpfiles} /etc/printcap; do
> -                             if [ -e $i.pre-cups ]; then
> -                                     mv -f $i.pre-cups $i
> -                             fi
> -                     done
> -             fi
> -     fi
> +     # XXX cups-driverd(8) can crash when setting up a printer driver
> +     # find /var/cache/cups -type f -name ppds.dat -exec rm -- {} \;
>  
> -     [ -e /dev/lpt0 ] && chown root /dev/lp[a,t][0-2]
> +     # rcexec is needed if openfiles limits are bumped and cupsd(8)
> +     # runs in debug mode to prevent MaxClients warnings in logs
> +     ${rcexec} "${daemon} ${daemon_flags} -t"
>  }
> +
>  
>  rc_cmd $1
> --- /dev/null Sat Jun 13 19:28:37 2015
> +++ pkg/MESSAGE-main  Sat Jun 13 16:41:13 2015
> @@ -0,0 +1,10 @@
> +CUPS can be set up to replace lpd entirely.
> +
> +To backup the lp* tools and symlink in the CUPS replacements, do:
> +
> +    ${PREFIX}/sbin/cups-toggle enable
> +
> +To revert to the base lp* tools, do:
> +
> +    ${PREFIX}/sbin/cups-toggle disable
> +    
> --- /dev/null Sat Jun 13 19:29:04 2015
> +++ files/cups-toggle Sat Jun 13 19:17:39 2015
> @@ -0,0 +1,161 @@
> +#!/bin/ksh
> +#
> +# $OpenBSD$
> +#
> +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> +#
> +# Copyright (c) 2015 Craig Skinner <skin...@britvault.co.uk>
> +#
> +# Permission to use, copy, modify, and distribute this software for any
> +# purpose with or without fee is hereby granted, provided that the above
> +# copyright notice and this permission notice appear in all copies.
> +#
> +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> +#
> +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> +#
> +
> +
> +EX_USAGE='64'
> +BINARIES='/usr/bin/lp{q,r,rm} /usr/sbin/lp{c,d}'
> +MAN_PAGES='/usr/share/man/man1/lp{q,r,rm}.1 /usr/share/man/man8/lp{c,d}.8'
> +
> +readonly EX_USAGE BINARIES MAN_PAGES
> +
> +
> +function enable
> +{
> +     print "$0()"
> +
> +     ${RCDIR}/lpd check &&
> +     {
> +             ${RCDIR}/lpd stop || return
> +     }
> +
> +     print -n 'Backing up:'
> +     for _lpfile in ${BINARIES} ${MAN_PAGES} ${SYSCONFDIR}/printcap
> +     do
> +             [[ -f ${_lpfile} ]] || continue
> +             [[ -h ${_lpfile} ]] && continue
> +             [[ -f ${_lpfile}.pre-cups ]] && continue
> +             print -n " ${_lpfile##*/}"
> +             mv ${_lpfile} ${_lpfile}.pre-cups || return
> +     done
> +     print '.'
> +
> +     [[ -h ${SYSCONFDIR}/printcap ]] ||
> +     {
> +             print -n 'Symlinking ${SYSCONFDIR}/printcap'
> +             ln -s ${SYSCONFDIR}/cups/printcap ${SYSCONFDIR}/printcap || 
> return
> +             print '.'
> +     }
> +
> +     print -n 'Symlinking binaries:'
> +     for binary in ${BINARIES}
> +     do
> +             [[ -h ${binary} ]] && continue
> +             [[ -f ${TRUEPREFIX}/bin/${binary##*/} ]] &&
> +             {
> +                     print -n " ${binary##*/}"
> +                     ln -s ${TRUEPREFIX}/bin/${binary##*/} ${binary} || 
> return
> +                     continue
> +             }
> +             [[ -f ${TRUEPREFIX}/sbin/${binary##*/} ]] &&
> +             {
> +                     print -n " ${binary##*/}"
> +                     ln -s ${TRUEPREFIX}/sbin/${binary##*/} ${binary} || 
> return
> +                     continue
> +             }
> +             print -n " ${binary##*/}"
> +             ln -s /usr/bin/false ${binary} || return
> +     done
> +     print '.'
> +
> +     chown_lp_devs _cups
> +}
> +
> +
> +function disable
> +{
> +     print "$0()"
> +
> +     ${RCDIR}/cups_browsed check &&
> +     {
> +             ${RCDIR}/cups_browsed stop || return
> +     }
> +     ${RCDIR}/cupsd check &&
> +     {
> +             ${RCDIR}/cupsd stop || return
> +     }
> +
> +     print -n 'Reverting to base:'
> +     for _lpfile in ${BINARIES} ${MAN_PAGES} ${SYSCONFDIR}/printcap
> +     do
> +             [[ -h ${_lpfile} ]] &&
> +             {
> +                     rm ${_lpfile} || return
> +             }
> +             [[ -f ${_lpfile}.pre-cups ]] || continue
> +             print -n " ${_lpfile##*/}"
> +             mv ${_lpfile}.pre-cups ${_lpfile} || return
> +     done
> +     print '.'
> +
> +     chown_lp_devs root
> +}
> +
> +
> +function usage
> +{
> +     print -u2 "usage: ${0##*/} (enable|disable)"
> +     exit ${EX_USAGE}
> +}
> +
> +
> +function chown_lp_devs
> +{
> +     print "$0() $1"
> +     userinfo -e $1 || return
> +
> +     lp_devs='/dev/lp[a,t][0-2]'
> +     log_devs_are=$(mktemp)
> +     ls -l ${lp_devs} > ${log_devs_are}
> +
> +     for lp_dev in ${lp_devs}
> +     do
> +             [[ -c ${lp_dev} ]] || continue
> +             [[ $(stat -f "%Su" ${lp_dev}) == $1 ]] && continue
> +             chown $1 ${lp_dev} || return
> +     done
> +
> +     log_devs_now=$(mktemp)
> +     ls -l ${lp_devs} > ${log_devs_now}
> +     cmp -s ${log_devs_are} ${log_devs_now} ||
> +     {
> +             print 'devices are:'
> +             cat ${log_devs_are}
> +             print 'devices now:'
> +             cat ${log_devs_now}
> +     }
> +     rm ${log_devs_are} ${log_devs_now}
> +}
> +
> +
> +[[ $# -eq 1 ]] || usage
> +[[ $1 == 'enable' || $1 == 'disable' ]] || usage
> +
> +
> +$1 || exit
> +
> +for _lpfile in ${BINARIES} ${MAN_PAGES} ${SYSCONFDIR}/printcap
> +do
> +     _lpfiles="${_lpfiles} ${_lpfile}*"
> +done
> +ls -lF ${_lpfiles}
> +
> 

-- 
Antoine

Reply via email to