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

Last change on this file since 765 was 744, checked in by sebas@…, 14 years ago

Se agrega la posibilidad de poner opciones de job a cups (aun no esta siendo usado)

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