[417] | 1 | # copyright koumbit.org |
---|
| 2 | # Licence: GPL |
---|
| 3 | |
---|
[471] | 4 | class cups { |
---|
[473] | 5 | } |
---|
[471] | 6 | |
---|
[473] | 7 | class cups::saned { |
---|
| 8 | |
---|
| 9 | package { "sane-utils": ensure => "installed" } |
---|
| 10 | |
---|
| 11 | file { "/etc/default/saned": |
---|
| 12 | ensure => present, |
---|
| 13 | require => Package["sane-utils"], |
---|
| 14 | owner => "root", group => "root", mode => "644", |
---|
| 15 | } |
---|
| 16 | |
---|
[472] | 17 | service { "saned": |
---|
[473] | 18 | enable => true, |
---|
| 19 | ensure => running, |
---|
| 20 | subscribe => [ Package["sane-utils"], File["/etc/default/saned"] ], |
---|
[472] | 21 | } |
---|
[474] | 22 | |
---|
| 23 | @user { "saned": |
---|
| 24 | ensure => "present", |
---|
| 25 | groups => "lp", |
---|
| 26 | require => Package["sane-utils"], |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | realize( |
---|
| 30 | User["saned"] |
---|
| 31 | ) |
---|
| 32 | |
---|
[471] | 33 | } |
---|
| 34 | |
---|
[463] | 35 | class cups::server { |
---|
[417] | 36 | |
---|
| 37 | package { "cupsys": ensure => "installed" } |
---|
[469] | 38 | package { [ "hplip", "hpijs-ppds" ]: ensure => installed; } |
---|
[417] | 39 | |
---|
[443] | 40 | file { "/etc/cups/cupsd.conf": |
---|
[464] | 41 | source => "puppet:///cups/cupsd.conf", |
---|
[419] | 42 | ensure => present, |
---|
| 43 | require => Package["cupsys"], |
---|
| 44 | owner => "root", group => "root", mode => "644", |
---|
| 45 | } |
---|
| 46 | |
---|
[469] | 47 | file { "/etc/cups/printers.conf": |
---|
| 48 | ensure => present, |
---|
| 49 | require => Package["cupsys"], |
---|
| 50 | owner => "root", group => "lp", mode => "600", |
---|
| 51 | } |
---|
[475] | 52 | |
---|
| 53 | service { "cups": |
---|
| 54 | enable => true, |
---|
| 55 | ensure => running, |
---|
| 56 | subscribe => [ Package["cupsys"], File["/etc/cups/cupsd.conf"] ], |
---|
| 57 | } |
---|
[417] | 58 | } |
---|
[419] | 59 | |
---|
[471] | 60 | define cups::printer ($printer, $p_deviceuri, $p_description, $p_location, $p_pathppd = "", $p_ppd = "", $p_filter = "", $p_accept = "", $p_enable = "", $p_scan = "" ) |
---|
[463] | 61 | { |
---|
| 62 | include cups::server |
---|
| 63 | |
---|
[469] | 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 | } |
---|
[463] | 86 | } |
---|
| 87 | |
---|
[469] | 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 | |
---|
[468] | 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") |
---|
[464] | 108 | } |
---|
| 109 | |
---|
[468] | 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") |
---|
[464] | 119 | } |
---|
| 120 | |
---|
[471] | 121 | if $p_scan { |
---|
[473] | 122 | include cups::saned |
---|
[471] | 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: |
---|
[472] | 131 | file => "/etc/default/saned", |
---|
[471] | 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 | |
---|
[463] | 141 | } |
---|
| 142 | |
---|