--- mcore-src/trunk/mcore-tools/daemon/client/include/printing.client.class 2011/02/02 20:20:24 1248 +++ mcore-src/trunk/mcore-tools/daemon/client/include/printing.client.class 2012/08/13 09:52:58 2011 @@ -2,27 +2,34 @@ provide lprng -help_printing_addprinter() +help_printing_printer() { - mecho "set printing.addprinter [name] [port] [ip] [share]" - mecho " adds a new printer" + mecho "get printing.printer" + mecho " Shows all configured printers." + mecho + mecho "set printing.addprinter [action] [name] [port] [ip] [share]" + mecho " Adds or deletes a printer." + mecho " Actions:" + mecho " add - adds given printer" + mecho " del - deletes given printer" + mecho mecho " name - name of the printer" mecho " port - printing port (lpt1, usb1, com1 ... lptN, usbN, comN" mecho " ip - ip of the remote printer - optional" mecho " share - share/port name of the remote printer - optional" } -set_printing_addprinter() +helper_addprinter() { local name="$1" local port="$2" local ip="$3" local share="$4" - [[ -z ${name} ]] && help_printing_addprinter && return 1 - [[ -z ${port} ]] && help_printing_addprinter && return 1 + [[ -z ${name} ]] && help_printing_printer && return 1 + [[ -z ${port} ]] && help_printing_printer && return 1 - [[ ! -d /etc/printcap.d ]] && install -d /etc/printcap.d + [[ ! -d ${MROOT}/etc/printcap.d ]] && install -d ${MROOT}/etc/printcap.d case ${port} in lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;; @@ -32,45 +39,56 @@ #socket) port="socket://${ip}:${share}" ;; esac - CONFIG="/etc/printcap.d/${name}.conf" + CONFIG="${MROOT}/etc/printcap.d/${name}.conf" + clearconfig addconfig "${name}|${name}" addconfig " :lp=${port}" addconfig " :sd=/var/spool/lpd/${name}" + addconfig " :sd=/var/spool/lpd/${name}" + addconfig " :lf=/var/log/lprng/${name}" # regenerate printcap helper_generate_printcap } -help_printing_delprinter() -{ - mecho "set printing.delprinter [name]" - mecho " deletes given printer" -} - -set_printing_delprinter() +helper_delprinter() { local name="$1" - [[ -z ${name} ]] && help_printing_addprinter && return 1 + [[ -z ${name} ]] && help_printing_printer && return 1 - if [[ -f /etc/printcap.d/${name}.conf ]] + if [[ -f ${MROOT}/etc/printcap.d/${name}.conf ]] then - rm /etc/printcap.d/${name}.conf + rm ${MROOT}/etc/printcap.d/${name}.conf fi - if [[ -d /var/spool/lpd/${name} ]] + if [[ -d ${MROOT}/var/spool/lpd/${name} ]] then - rm -rf /var/spool/lpd/${name} + rm -rf ${MROOT}/var/spool/lpd/${name} fi + if [[ -d ${MROOT}/var/log/lprng/${name} ]] + then + rm -rf ${MROOT}/var/log/lprng/${name} + fi + # regenerate printcap helper_generate_printcap } -help_printing_printer() +set_printing_printer() { - mecho "get printing.printer" - mecho " shows all config/var/spool/lpd/ured printer" + local action="$1" + local name="$2" + local port="$3" + local ip="$4" + local share="$5" + + case "${action}" in + add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;; + del) helper_delprinter "${name}" ;; + *) help_printing_printer && return 1 ;; + esac } get_printing_printer() @@ -83,17 +101,18 @@ printer="${printer} $(basename ${i} .conf)" done - mecho ${printer} + rvecho ${printer} } helper_generate_printcap() { local i + local prn - CONFIG="/etc/printcap" + CONFIG="${MROOT}/etc/printcap" clearconfig - for i in $(find /etc/printcap.d -type f -name \*.conf) + for i in $(find ${MROOT}/etc/printcap.d -type f -name \*.conf) do mecho "adding ${i}" addconfig "#--- added by mcored ---" @@ -101,7 +120,15 @@ addconfig "#-----------------------" addconfig + prn=$(basename ${i} .conf) + # install spooler directories - install -o lp -g lp -m0700 -d /var/spool/lpd/$(basename ${i} .conf) + install -o lp -g lp -m0700 -d ${MROOT}/var/spool/lpd/${prn} + + # create empty log files + install -d ${MROOT}/var/log/lprng + touch ${MROOT}/var/log/lprng/${prn} + chown lp:lp ${MROOT}/var/log/lprng/${prn} + chmod 0600 ${MROOT}/var/log/lprng/${prn} done }