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

mcore-src/trunk/mcore-tools/daemon/client/include/printing.client.class revision 1248 by niro, Wed Feb 2 20:20:24 2011 UTC mcore-src/trunk/mcore-tools/src/modules/lprng/printing.client.class.in revision 2174 by niro, Fri Jan 10 14:13:09 2014 UTC
# Line 2  Line 2 
2    
3  provide lprng  provide lprng
4    
5  help_printing_addprinter()  help_printing_printer()
6  {  {
7   mecho "set printing.addprinter [name] [port] [ip] [share]"   mecho "get printing.printer"
8   mecho " adds a new printer"   mecho " Shows all configured printers."
9     mecho
10     mecho "set printing.addprinter [action] [name] [port] [ip] [share]"
11     mecho " Adds or deletes a printer."
12     mecho " Actions:"
13     mecho "   add   - adds given printer"
14     mecho "   del   - deletes given printer"
15     mecho
16   mecho "   name  - name of the printer"   mecho "   name  - name of the printer"
17   mecho "   port  - printing port (lpt1, usb1, com1 ... lptN, usbN, comN"   mecho "   port  - printing port (lpt1, usb1, com1 ... lptN, usbN, comN"
18   mecho "   ip    - ip of the remote printer - optional"   mecho "   ip    - ip of the remote printer - optional"
19   mecho "   share - share/port name of the remote printer - optional"   mecho "   share - share/port name of the remote printer - optional"
20  }  }
21    
22  set_printing_addprinter()  helper_addprinter()
23  {  {
24   local name="$1"   local name="$1"
25   local port="$2"   local port="$2"
26   local ip="$3"   local ip="$3"
27   local share="$4"   local share="$4"
28    
29   [[ -z ${name} ]] && help_printing_addprinter && return 1   [[ -z ${name} ]] && help_printing_printer && return 1
30   [[ -z ${port} ]] && help_printing_addprinter && return 1   [[ -z ${port} ]] && help_printing_printer && return 1
31    
32   [[ ! -d /etc/printcap.d ]] && install -d /etc/printcap.d   [[ ! -d ${MROOT}/etc/printcap.d ]] && install -d ${MROOT}/etc/printcap.d
33    
34   case ${port} in   case ${port} in
35   lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;;   lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;;
# Line 32  set_printing_addprinter() Line 39  set_printing_addprinter()
39   #socket) port="socket://${ip}:${share}" ;;   #socket) port="socket://${ip}:${share}" ;;
40   esac   esac
41    
42   CONFIG="/etc/printcap.d/${name}.conf"   CONFIG="${MROOT}/etc/printcap.d/${name}.conf"
43     clearconfig
44   addconfig "${name}|${name}"   addconfig "${name}|${name}"
45   addconfig " :lp=${port}"   addconfig " :lp=${port}"
46   addconfig " :sd=/var/spool/lpd/${name}"   addconfig " :sd=/var/spool/lpd/${name}"
47     addconfig " :sd=/var/spool/lpd/${name}"
48     addconfig " :lf=/var/log/lprng/${name}"
49    
50   # regenerate printcap   # regenerate printcap
51   helper_generate_printcap   helper_generate_printcap
52  }  }
53    
54  help_printing_delprinter()  helper_delprinter()
 {  
  mecho "set printing.delprinter [name]"  
  mecho " deletes given printer"  
 }  
   
 set_printing_delprinter()  
55  {  {
56   local name="$1"   local name="$1"
57    
58   [[ -z ${name} ]] && help_printing_addprinter && return 1   [[ -z ${name} ]] && help_printing_printer && return 1
59    
60   if [[ -f /etc/printcap.d/${name}.conf ]]   if [[ -f ${MROOT}/etc/printcap.d/${name}.conf ]]
61   then   then
62   rm /etc/printcap.d/${name}.conf   rm ${MROOT}/etc/printcap.d/${name}.conf
63   fi   fi
64    
65   if [[ -d /var/spool/lpd/${name} ]]   if [[ -d ${MROOT}/var/spool/lpd/${name} ]]
66   then   then
67   rm -rf /var/spool/lpd/${name}   rm -rf ${MROOT}/var/spool/lpd/${name}
68   fi   fi
69    
70     if [[ -d ${MROOT}/var/log/lprng/${name} ]]
71     then
72     rm -rf ${MROOT}/var/log/lprng/${name}
73     fi
74    
75   # regenerate printcap   # regenerate printcap
76   helper_generate_printcap   helper_generate_printcap
77  }  }
78    
79  help_printing_printer()  set_printing_printer()
80  {  {
81   mecho "get printing.printer"   local action="$1"
82   mecho " shows all config/var/spool/lpd/ured printer"   local name="$2"
83     local port="$3"
84     local ip="$4"
85     local share="$5"
86    
87     case "${action}" in
88     add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;;
89     del) helper_delprinter "${name}" ;;
90     *) help_printing_printer && return 1 ;;
91     esac
92  }  }
93    
94  get_printing_printer()  get_printing_printer()
95  {  {
96   local i   list_files_in_directory ${MROOT}/etc/printcap.d
  local printer  
   
  for i in $(find /etc/printcap.d -type f -name \*.conf)  
  do  
  printer="${printer} $(basename ${i} .conf)"  
  done  
   
  mecho ${printer}  
97  }  }
98    
99  helper_generate_printcap()  helper_generate_printcap()
100  {  {
101   local i   local i
102     local prn
103    
104   CONFIG="/etc/printcap"   CONFIG="${MROOT}/etc/printcap"
105   clearconfig   clearconfig
106    
107   for i in $(find /etc/printcap.d -type f -name \*.conf)   for i in $(find ${MROOT}/etc/printcap.d -type f -name \*.conf)
108   do   do
109   mecho "adding ${i}"   mecho "adding ${i}"
110   addconfig "#--- added by mcored ---"   addconfig "#--- added by mcored ---"
# Line 101  helper_generate_printcap() Line 112  helper_generate_printcap()
112   addconfig "#-----------------------"   addconfig "#-----------------------"
113   addconfig   addconfig
114    
115     prn=$(basename ${i} .conf)
116    
117   # install spooler directories   # install spooler directories
118   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}
119    
120     # create empty log files
121     install -d ${MROOT}/var/log/lprng
122     touch ${MROOT}/var/log/lprng/${prn}
123     chown lp:lp ${MROOT}/var/log/lprng/${prn}
124     chmod 0600 ${MROOT}/var/log/lprng/${prn}
125   done   done
126  }  }

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