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