[417] | 1 | # copyright koumbit.org |
---|
| 2 | # Licence: GPL |
---|
| 3 | |
---|
[471] | 4 | class cups { |
---|
[473] | 5 | } |
---|
[471] | 6 | |
---|
[572] | 7 | ## |
---|
| 8 | ## cups (browse) - to see other printers |
---|
| 9 | ## |
---|
| 10 | |
---|
[737] | 11 | class 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 | |
---|
[572] | 26 | class 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 | } |
---|
[744] | 50 | |
---|
[572] | 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
[744] | 54 | define 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 | |
---|
[478] | 82 | define cups::saned::client ($remotescanner) |
---|
| 83 | { |
---|
| 84 | package { "xsane": ensure => "installed" } |
---|
[514] | 85 | package { "gocr-tk": ensure => "installed" } |
---|
[478] | 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 | |
---|
[473] | 100 | class cups::saned { |
---|
| 101 | |
---|
| 102 | package { "sane-utils": ensure => "installed" } |
---|
| 103 | |
---|
[476] | 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 | |
---|
[473] | 119 | file { "/etc/default/saned": |
---|
| 120 | ensure => present, |
---|
| 121 | require => Package["sane-utils"], |
---|
| 122 | owner => "root", group => "root", mode => "644", |
---|
| 123 | } |
---|
| 124 | |
---|
[478] | 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 | |
---|
[472] | 139 | service { "saned": |
---|
[473] | 140 | enable => true, |
---|
| 141 | ensure => running, |
---|
[476] | 142 | provider => "debian", |
---|
[473] | 143 | subscribe => [ Package["sane-utils"], File["/etc/default/saned"] ], |
---|
[472] | 144 | } |
---|
[474] | 145 | |
---|
| 146 | @user { "saned": |
---|
| 147 | ensure => "present", |
---|
| 148 | groups => "lp", |
---|
| 149 | require => Package["sane-utils"], |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | realize( |
---|
| 153 | User["saned"] |
---|
| 154 | ) |
---|
| 155 | |
---|
[471] | 156 | } |
---|
| 157 | |
---|
[463] | 158 | class cups::server { |
---|
[417] | 159 | |
---|
| 160 | package { "cupsys": ensure => "installed" } |
---|
[469] | 161 | package { [ "hplip", "hpijs-ppds" ]: ensure => installed; } |
---|
[417] | 162 | |
---|
[443] | 163 | file { "/etc/cups/cupsd.conf": |
---|
[464] | 164 | source => "puppet:///cups/cupsd.conf", |
---|
[419] | 165 | ensure => present, |
---|
| 166 | require => Package["cupsys"], |
---|
| 167 | owner => "root", group => "root", mode => "644", |
---|
| 168 | } |
---|
| 169 | |
---|
[469] | 170 | file { "/etc/cups/printers.conf": |
---|
| 171 | ensure => present, |
---|
| 172 | require => Package["cupsys"], |
---|
| 173 | owner => "root", group => "lp", mode => "600", |
---|
| 174 | } |
---|
[475] | 175 | |
---|
| 176 | service { "cups": |
---|
| 177 | enable => true, |
---|
| 178 | ensure => running, |
---|
[476] | 179 | provider => "debian", |
---|
[475] | 180 | subscribe => [ Package["cupsys"], File["/etc/cups/cupsd.conf"] ], |
---|
| 181 | } |
---|
[417] | 182 | } |
---|
[419] | 183 | |
---|
[471] | 184 | define cups::printer ($printer, $p_deviceuri, $p_description, $p_location, $p_pathppd = "", $p_ppd = "", $p_filter = "", $p_accept = "", $p_enable = "", $p_scan = "" ) |
---|
[463] | 185 | { |
---|
| 186 | include cups::server |
---|
| 187 | |
---|
[469] | 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", |
---|
[476] | 193 | require => [Package["cupsys"], Package["hplip"], Package["hpijs-ppds"], Service["cups"]], |
---|
[469] | 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 | } |
---|
[463] | 210 | } |
---|
| 211 | |
---|
[469] | 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 | |
---|
[468] | 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 { |
---|
[477] | 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 | } |
---|
[468] | 237 | debug ("'$printer' will not accept print jobs") |
---|
[464] | 238 | } |
---|
| 239 | |
---|
[468] | 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 { |
---|
[477] | 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 | } |
---|
[468] | 254 | debug ("'$printer' is disabled") |
---|
[464] | 255 | } |
---|
| 256 | |
---|
[471] | 257 | if $p_scan { |
---|
[473] | 258 | include cups::saned |
---|
[471] | 259 | } else { |
---|
| 260 | debug ("'$printer' cannot scan on the network") |
---|
| 261 | } |
---|
| 262 | |
---|
[463] | 263 | } |
---|
| 264 | |
---|