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