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