Magellan Linux

Diff of /mcore-src/trunk/mcore-tools/src/modules/lprng/printing.client.class.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2174 by niro, Fri Jan 10 14:13:09 2014 UTC revision 2658 by niro, Tue Nov 10 16:00:22 2015 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3  provide lprng  provide printing lprng
4    require basic-kernel
5    
6  help_printing_printer()  help_printing_printer()
7  {  {
# Line 15  help_printing_printer() Line 16  help_printing_printer()
16   mecho   mecho
17   mecho "   name  - name of the printer"   mecho "   name  - name of the printer"
18   mecho "   port  - printing port (lpt1, usb1, com1 ... lptN, usbN, comN"   mecho "   port  - printing port (lpt1, usb1, com1 ... lptN, usbN, comN"
19   mecho "   ip    - ip of the remote printer - optional"  # mecho "   ip    - ip of the remote printer - optional"
20   mecho "   share - share/port name of the remote printer - optional"  # mecho "   share - share/port name of the remote printer - optional"
21  }  }
22    
23  helper_addprinter()  helper_addprinter()
24  {  {
25   local name="$1"   local name="$1"
26   local port="$2"   local port="$2"
27   local ip="$3"  # local ip="$3"
28   local share="$4"  # local share="$4"
29    
30   [[ -z ${name} ]] && help_printing_printer && return 1   [[ -z ${name} ]] && help_printing_printer && return 1
31   [[ -z ${port} ]] && help_printing_printer && return 1   [[ -z ${port} ]] && help_printing_printer && return 1
32    
33   [[ ! -d ${MROOT}/etc/printcap.d ]] && install -d ${MROOT}/etc/printcap.d   [[ ! -d ${MROOT}@@SYSCONFDIR@@/printcap.d ]] && install -d ${MROOT}@@SYSCONFDIR@@/printcap.d
34    
35   case ${port} in   case ${port} in
36   lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;;   lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;;
37   com[0-9]*) port="/dev/ttyS$(( ${port/com/}-1 ))" ;;   com[0-9]*) port="/dev/ttyS$(( ${port/com/}-1 ))" ;;
38   usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;;   usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;;
39   #lpd) port="lpd://${ip}/${share}" ;;   #lpd) port="lpd://${ip}/${share}" ;;
40   #socket) port="socket://${ip}:${share}" ;;   #socket) port="socket://${ip}:${share}" ;;
41   esac   esac
42    
43   CONFIG="${MROOT}/etc/printcap.d/${name}.conf"   CONFIG="${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf"
44   clearconfig   clearconfig
45   addconfig "${name}|${name}"   addconfig "${name}|${name}"
46   addconfig " :lp=${port}"   addconfig " :lp=${port}"
47   addconfig " :sd=/var/spool/lpd/${name}"   addconfig " :sd=/var/spool/lpd/${name}"
  addconfig " :sd=/var/spool/lpd/${name}"  
48   addconfig " :lf=/var/log/lprng/${name}"   addconfig " :lf=/var/log/lprng/${name}"
49    
50   # regenerate printcap   # regenerate printcap
# Line 57  helper_delprinter() Line 57  helper_delprinter()
57    
58   [[ -z ${name} ]] && help_printing_printer && return 1   [[ -z ${name} ]] && help_printing_printer && return 1
59    
60   if [[ -f ${MROOT}/etc/printcap.d/${name}.conf ]]   if [[ -f ${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf ]]
61   then   then
62   rm ${MROOT}/etc/printcap.d/${name}.conf   rm ${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf
63   fi   fi
64    
65   if [[ -d ${MROOT}/var/spool/lpd/${name} ]]   if [[ -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${name} ]]
66   then   then
67   rm -rf ${MROOT}/var/spool/lpd/${name}   rm -rf ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${name}
68   fi   fi
69    
70   if [[ -d ${MROOT}/var/log/lprng/${name} ]]   if [[ -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${name} ]]
71   then   then
72   rm -rf ${MROOT}/var/log/lprng/${name}   rm -rf ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${name}
73   fi   fi
74    
75   # regenerate printcap   # regenerate printcap
76   helper_generate_printcap   helper_generate_printcap
77  }  }
78    
79  set_printing_printer()  set_printing_printer()
80  {  {
81   local action="$1"   local action="${CLASS_ARGV[0]}"
82   local name="$2"   local name="${CLASS_ARGV[1]}"
83   local port="$3"   local port="${CLASS_ARGV[2]}"
84   local ip="$4"  # local ip="${CLASS_ARGV[3]}"
85   local share="$5"  # local share="${CLASS_ARGV[4]}"
86    
87   case "${action}" in   case "${action}" in
88   add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;;  # add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;;
89     add) helper_addprinter "${name}" "${port}";;
90   del) helper_delprinter "${name}" ;;   del) helper_delprinter "${name}" ;;
91   *) help_printing_printer && return 1 ;;   *) help_printing_printer && return 1 ;;
92   esac   esac
# Line 93  set_printing_printer() Line 94  set_printing_printer()
94    
95  get_printing_printer()  get_printing_printer()
96  {  {
97   list_files_in_directory ${MROOT}/etc/printcap.d   list_files_in_directory ${MROOT}@@SYSCONFDIR@@/printcap.d
98  }  }
99    
100  helper_generate_printcap()  helper_generate_printcap()
# Line 101  helper_generate_printcap() Line 102  helper_generate_printcap()
102   local i   local i
103   local prn   local prn
104    
105   CONFIG="${MROOT}/etc/printcap"   # install required kernel modules as well
106     if is_provided basic-kernel
107     then
108     ${MCORE_LIBDIR}/mcore-kernel-modules --add --module lp
109     ${MCORE_LIBDIR}/mcore-kernel-modules --add --module usblp
110     fi
111    
112     CONFIG="${MROOT}@@SYSCONFDIR@@/printcap"
113   clearconfig   clearconfig
114    
115   for i in $(find ${MROOT}/etc/printcap.d -type f -name \*.conf)   for i in $(find ${MROOT}@@SYSCONFDIR@@/printcap.d -type f -name \*.conf)
116   do   do
117   mecho "adding ${i}"   mecho "adding ${i}"
118   addconfig "#--- added by mcored ---"   addconfig "#--- added by mcored ---"
# Line 115  helper_generate_printcap() Line 123  helper_generate_printcap()
123   prn=$(basename ${i} .conf)   prn=$(basename ${i} .conf)
124    
125   # install spooler directories   # install spooler directories
126   install -o lp -g lp -m0700 -d ${MROOT}/var/spool/lpd/${prn}   install -o @@LPRNG_SPOOLER_USER@@ -g @@LPRNG_SPOOLER_USER@@ -m0700 -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${prn}
127    
128   # create empty log files   # create empty log files
129   install -d ${MROOT}/var/log/lprng   install -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng
130   touch ${MROOT}/var/log/lprng/${prn}   touch ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn}
131   chown lp:lp ${MROOT}/var/log/lprng/${prn}   chown @@LPRNG_SPOOLER_USER@@:@@LPRNG_SPOOLER_USER@@ ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn}
132   chmod 0600 ${MROOT}/var/log/lprng/${prn}   chmod 0600 ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn}
133   done   done
134  }  }

Legend:
Removed from v.2174  
changed lines
  Added in v.2658