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