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