source: trunk/puppet/modules/puppet-cups/manifests/init.pp @ 572

Last change on this file since 572 was 572, checked in by sebas@…, 12 years ago

agrego aca la class cups::browse para los clientes que tiene que ver la impresoras remotas

File size: 5.9 KB
Line 
1# copyright koumbit.org
2# Licence: GPL
3
4class cups {
5}
6
7##
8## cups (browse) - to see other printers
9##
10
11class cups::browse {
12
13    package { [ 'cups' ]: ensure => installed }
14
15    file { "/etc/cups/cupsd.conf": ensure => present, checksum => mtime }
16   
17    line { cupsbrowseoff:
18       file => "/etc/cups/cupsd.conf",
19       line => 'Browsing Off',
20       ensure => absent,
21       require => Package["cups"]
22    }
23    line { cupsbrowseon:
24       file => "/etc/cups/cupsd.conf",
25       line => 'Browsing On',
26       ensure => present,
27       require => Package["cups"]
28    }
29
30    service { "cups":
31       enable => true,
32       ensure => running,
33       subscribe => [ Package["cups"], File["/etc/cups/cupsd.conf"] ],
34    }
35}
36
37
38define cups::saned::client ($remotescanner)
39  {
40   package { "xsane": ensure => "installed" }
41   package { "gocr-tk": ensure => "installed" }
42
43   file { "/etc/sane.d/net.conf":
44      ensure => present,
45      require => Package["xsane"],
46      owner => "root", group => "root", mode => "644",
47   }
48    line { saned_remotescanner:
49      file => "/etc/sane.d/net.conf",
50      line => $remotescanner,
51      ensure => present,
52      require => Package["xsane"],
53    }
54  }
55
56class cups::saned {
57
58   package { "sane-utils": ensure => "installed" }
59
60    line { saned_activate_off:
61      file => "/etc/default/saned",
62      line => 'RUN=no',
63      ensure => absent,
64      require => Package["sane-utils"],
65      notify  => Service["saned"],
66    }
67    line { saned_activate_on:
68      file => "/etc/default/saned",
69      line => 'RUN=yes',
70      ensure => present,
71      require => Package["sane-utils"],
72      notify  => Service["saned"],
73    }
74
75   file { "/etc/default/saned":
76      ensure => present,
77      require => Package["sane-utils"],
78      owner => "root", group => "root", mode => "644",
79   }
80
81    line { saned_allow:
82      file => "/etc/sane.d/saned.conf",
83      line => $sanedallow,
84      ensure => present,
85      require => Package["sane-utils"],
86      notify  => Service["saned"],
87    }
88
89   file { "/etc/sane.d/saned.conf":
90      ensure => present,
91      require => Package["sane-utils"],
92      owner => "root", group => "root", mode => "644",
93   }
94
95   service { "saned":
96      enable => true,
97      ensure => running,
98      provider => "debian",
99      subscribe => [ Package["sane-utils"], File["/etc/default/saned"] ],
100   }
101
102   @user { "saned":
103        ensure  => "present",
104        groups  => "lp",
105        require => Package["sane-utils"],
106   }
107
108   realize(
109        User["saned"]
110   )
111
112}
113
114class cups::server {
115
116   package { "cupsys": ensure => "installed" }
117   package { [ "hplip", "hpijs-ppds" ]: ensure => installed; }
118
119   file { "/etc/cups/cupsd.conf":
120      source => "puppet:///cups/cupsd.conf",
121      ensure => present,
122      require => Package["cupsys"],
123      owner => "root", group => "root", mode => "644",
124   }
125
126   file { "/etc/cups/printers.conf":
127      ensure => present,
128      require => Package["cupsys"],
129      owner => "root", group => "lp", mode => "600",
130   }
131
132   service { "cups":
133      enable => true,
134      ensure => running,
135      provider => "debian",
136      subscribe => [ Package["cupsys"], File["/etc/cups/cupsd.conf"] ],
137   }
138}
139
140define cups::printer ($printer, $p_deviceuri, $p_description, $p_location, $p_pathppd = "", $p_ppd = "", $p_filter = "", $p_accept = "", $p_enable = "", $p_scan = "" )
141 {
142   include cups::server
143
144  if $p_pathppd {
145    exec { "cups_create_printer_$name":
146      command => "lpadmin -p $printer -v $p_deviceuri -D '$p_description' -L '$p_location' -P $p_pathppd",
147      path => "/bin:/sbin:/usr/sbin:/usr/bin",
148      unless => "/bin/grep $printer /etc/cups/printers.conf",
149      require => [Package["cupsys"], Package["hplip"], Package["hpijs-ppds"], Service["cups"]],
150    }
151  } else {
152     file { "/etc/cups/ppd/$p_ppd":
153     ensure => present,
154     owner => "root", group => "root", mode => "644",
155     source  => "puppet:///files/cups/$name/$p_ppd",
156     require => [Package["cupsys"], Package["hplip"], Package["hpijs-ppds"]],
157    }
158    $p_pathppdd = "/etc/cups/ppd/"
159
160    exec { "cups_create_printer_$name":
161      command => "lpadmin -p $printer -v $p_deviceuri -D '$p_description' -L '$p_location' -P $p_pathppdd$p_ppd",
162      path => "/bin:/sbin:/usr/sbin:/usr/bin",
163      unless => "/bin/grep $printer /etc/cups/printers.conf",
164      require => [Package["cupsys"], Package["hplip"], Package["hpijs-ppds"]],
165    }
166  }
167
168  if $p_filter {
169     file { "/usr/lib/cups/filter/$p_filter":
170     ensure => present,
171     owner => "root", group => "root", mode => "755",
172     source  => "puppet:///files/cups/$name/$p_filter",
173     require => exec["cups_create_printer_$name"],
174    }
175  } else {
176    debug ("'$printer' doesn't need a special filter")
177  }
178
179  if $p_accept {
180    exec { "cupsaccept_$name":
181      command => "cupsaccept $printer",
182      path => "/bin:/sbin:/usr/sbin:/usr/bin",
183      unless => "grep -A8 $printer /etc/cups/printers.conf | grep 'Accepting Yes'",
184      require => exec["cups_create_printer_$name"],
185    }
186  } else {
187    exec { "cupsreject_$name":
188      command => "cupsreject $printer",
189      path => "/bin:/sbin:/usr/sbin:/usr/bin",
190      unless => "grep -A8 $printer /etc/cups/printers.conf | grep 'Accepting No'",
191      require => exec["cups_create_printer_$name"],
192    }
193    debug ("'$printer' will not accept print jobs")
194  }
195
196  if $p_enable {
197    exec { "cupsenable_$name":
198      command => "cupsenable $printer",
199      path => "/bin:/sbin:/usr/sbin:/usr/bin",
200      unless => "grep -A5 $printer /etc/cups/printers.conf | grep 'State Idle'",
201      require => exec["cups_create_printer_$name"],
202    }
203  } else {
204    exec { "cupsdisable_$name":
205      command => "cupsdisable $printer",
206      path => "/bin:/sbin:/usr/sbin:/usr/bin",
207      unless => "grep -A5 $printer /etc/cups/printers.conf | grep 'State Stopped'",
208      require => exec["cups_create_printer_$name"],
209    }
210    debug ("'$printer' is disabled")
211  }
212
213  if $p_scan {
214    include cups::saned
215  } else {
216    debug ("'$printer' cannot scan on the network")
217  }
218
219}
220
Note: See TracBrowser for help on using the repository browser.