Merge pull request #23 from fraenki/freebsd

add FreeBSD support
diff --git a/README.md b/README.md
index 53997e9..be2d8cc 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
 
 ## Overview
 
-This module is meant for Red Hat Enterprise Linux and clones. It still requires
-some major clean up, but is currently fully functional.
+This module is meant for Red Hat Enterprise Linux, its clones and FreeBSD. It
+still requires some major clean up, but is currently fully functional.
 
 * `postfix::dbfile` : Manage Postfix DB configuration files
 * `postfix::file` : Manage flat text Postfix configuration files
diff --git a/manifests/dbfile.pp b/manifests/dbfile.pp
index c2120c1..fd97201 100644
--- a/manifests/dbfile.pp
+++ b/manifests/dbfile.pp
@@ -28,7 +28,8 @@
   $mode       = '0644',
   $content    = undef,
   $source     = undef,
-  $ensure     = undef
+  $ensure     = undef,
+  $postmap    = $::postfix::params::postmap
 ) {
 
   file { "${postfixdir}/${title}":
@@ -46,7 +47,7 @@
 
   } else {
 
-    exec { "/usr/sbin/postmap ${title}":
+    exec { "${postmap} ${title}":
       cwd         => $postfixdir,
       subscribe   => File["${postfixdir}/${title}"],
       refreshonly => true,
diff --git a/manifests/params.pp b/manifests/params.pp
index c3bff97..6ba2802 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -2,13 +2,68 @@
 #
 class postfix::params {
   if $::osfamily == 'Debian' {
+    $command_directory = '/usr/sbin'
+    $config_directory = '/etc/postfix'
     $daemon_directory = '/usr/lib/postfix'
+    $data_directory = '/var/lib/postfix'
+    $manpage_directory = '/usr/share/man'
+    $readme_directory = '/usr/share/doc/postfix'
+    $sample_directory = '/usr/share/doc/postfix/examples'
     $service_restart = '/usr/sbin/service postfix reload'
     $dovecot_directory = '/usr/lib/dovecot'
+    $postfix_package = 'postfix'
+    $postfix_mysql_package = 'postfix-mysql'
+    $postgrey_package = 'postgrey'
+    $spamassassin_package = 'spamassassin'
+    $spampd_package = 'spampd'
+    $root_group = 'root'
+    $setgid_group = 'postdrop'
+    $mailq_path = '/usr/bin/mailq.postfix'
+    $newaliases_path = '/usr/bin/newaliases.postfix'
+    $sendmail_path = '/usr/sbin/sendmail.postfix'
+    $postmap = '/usr/sbin/postmap'
+  } elsif  $::osfamily == 'FreeBSD' {
+    $command_directory = '/usr/local/sbin'
+    $config_directory = '/usr/local/etc/postfix'
+    $daemon_directory = '/usr/local/libexec/postfix'
+    $data_directory = '/var/db/postfix'
+    $manpage_directory = '/usr/local/man'
+    $readme_directory = '/usr/local/share/doc/postfix'
+    $sample_directory = '/usr/local/etc/postfix'
+    $service_restart = '/usr/sbin/service postfix reload'
+    $dovecot_directory = '/usr/local/libexec/dovecot'
+    $postfix_package = 'mail/postfix'
+    $postfix_mysql_package = 'mail/postfix'
+    $postgrey_package = 'mail/postgrey'
+    $spamassassin_package = 'mail/spamassassin'
+    $spampd_package = 'mail/spampd'
+    $root_group = 'wheel'
+    $setgid_group = 'maildrop'
+    $mailq_path = '/usr/local/bin/mailq'
+    $newaliases_path = '/usr/local/bin/newaliases'
+    $sendmail_path = '/usr/local/sbin/sendmail'
+    $postmap = '/usr/local/sbin/postmap'
   } else {
+    $command_directory = '/usr/sbin'
+    $config_directory = '/etc/postfix'
     $daemon_directory = '/usr/libexec/postfix'
+    $data_directory = '/var/lib/postfix'
+    $manpage_directory = '/usr/share/man'
+    $readme_directory = '/usr/share/doc/postfix/README_FILES'
+    $sample_directory = '/usr/share/doc/postfix/samples'
     $service_restart = '/sbin/service postfix reload'
     $dovecot_directory = '/usr/libexec/dovecot'
+    $postfix_package = 'postfix'
+    $postfix_mysql_package = 'postfix-mysql'
+    $postgrey_package = 'postgrey'
+    $spamassassin_package = 'spamassassin'
+    $spampd_package = 'spampd'
+    $root_group = 'root'
+    $setgid_group = 'postdrop'
+    $mailq_path = '/usr/bin/mailq.postfix'
+    $newaliases_path = '/usr/bin/newaliases.postfix'
+    $sendmail_path = '/usr/sbin/sendmail.postfix'
+    $postmap = '/usr/sbin/postmap'
   }
 }
 
diff --git a/manifests/server.pp b/manifests/server.pp
index 0fe984a..e43119d 100644
--- a/manifests/server.pp
+++ b/manifests/server.pp
@@ -34,7 +34,7 @@
   $mail_spool_directory = false,
   $mailbox_command = false,
   $smtpd_banner = '$myhostname ESMTP $mail_name',
-  $setgid_group = 'postdrop',
+  $setgid_group = $::postfix::params::setgid_group,
   $message_size_limit = false,
   $mail_name = false,
   $virtual_alias_domains = false,
@@ -96,8 +96,23 @@
   $postgrey            = false,
   $clamav              = false,
   # Parameters
-  $daemon_directory    = $::postfix::params::daemon_directory,
-  $service_restart     = $::postfix::params::service_restart
+  $command_directory     = $::postfix::params::command_directory,
+  $config_directory      = $::postfix::params::config_directory,
+  $daemon_directory      = $::postfix::params::daemon_directory,
+  $data_directory        = $::postfix::params::data_directory,
+  $manpage_directory     = $::postfix::params::manpage_directory,
+  $readme_directory      = $::postfix::params::readme_directory,
+  $sample_directory      = $::postfix::params::sample_directory,
+  $postfix_package       = $::postfix::params::postfix_package,
+  $postfix_mysql_package = $::postfix::params::postfix_mysql_package,
+  $postgrey_package      = $::postfix::params::postgrey_package,
+  $service_restart       = $::postfix::params::service_restart,
+  $spamassassin_package  = $::postfix::params::spamassassin_package,
+  $spampd_package        = $::postfix::params::spampd_package,
+  $root_group            = $::postfix::params::root_group,
+  $mailq_path            = $::postfix::params::mailq_path,
+  $newaliases_path       = $::postfix::params::newaliases_path,
+  $sendmail_path         = $::postfix::params::sendmail_path,
 ) inherits postfix::params {
 
   # Default has el5 files, for el6 a few defaults have changed
@@ -108,35 +123,39 @@
   }
 
   # Main package and service it provides
-  $package_name = $mysql ? { true  => 'postfix-mysql', false => 'postfix', }
+  if $mysql {
+    $package_name = $postfix_mysql_package
+  } else {
+    $package_name = $postfix_package
+  }
   package { $package_name: ensure => installed, alias => 'postfix' }
 
   service { 'postfix':
-    require   => Package['postfix'],
+    require   => Package[$package_name],
     enable    => true,
     ensure    => running,
     hasstatus => true,
     restart   => $service_restart,
   }
 
-  file { '/etc/postfix/master.cf':
+  file { "${config_directory}/master.cf":
     content => template("postfix/master.cf${filesuffix}.erb"),
     notify  => Service['postfix'],
-    require => Package['postfix'],
+    require => Package[$package_name],
   }
-  file { '/etc/postfix/main.cf':
+  file { "${config_directory}/main.cf":
     content => template("postfix/main.cf${filesuffix}.erb"),
     notify  => Service['postfix'],
-    require => Package['postfix'],
+    require => Package[$package_name],
   }
 
   # Optional Spamassassin setup (using spampd)
   if $spamassassin {
     # Main packages and service they provide
-    package { [ 'spamassassin', 'spampd' ]: ensure => installed }
+    package { [ $spamassassin_package, $spampd_package ]: ensure => installed }
     # Note that we don't want the normal spamassassin (spamd) service
     service { 'spampd':
-      require   => Package['spampd'],
+      require   => Package[$spampd_package],
       enable    => true,
       ensure    => running,
       hasstatus => true,
@@ -148,7 +167,7 @@
     }
     # Change the spamassassin options
     file { '/etc/mail/spamassassin/local.cf':
-      require => Package['spamassassin'],
+      require => Package[$spamassassin_package],
       content => template('postfix/spamassassin-local.cf.erb'),
       notify  => Service['spampd'],
     }
@@ -157,9 +176,9 @@
   # Optional Postgrey setup
   if $postgrey {
     # Main package and service it provides
-    package { 'postgrey': ensure => installed }
+    package { $postgrey_package: ensure => installed }
     service { 'postgrey':
-      require   => Package['postgrey'],
+      require   => Package[$postgrey_package],
       enable    => true,
       ensure    => running,
       # When stopped, status returns zero with 1.31-1.el5
@@ -176,11 +195,15 @@
   # Regex header_checks
   postfix::file { 'header_checks':
     content => template('postfix/header_checks.erb'),
+    group => $root_group,
+    postfixdir => $config_directory,
   }
 
   # Regex body_checks
   postfix::file { 'body_checks':
     content => template('postfix/body_checks.erb'),
+    group => $root_group,
+    postfixdir => $config_directory,
   }
 
 }
diff --git a/templates/main.cf-el5.erb b/templates/main.cf-el5.erb
index fdaf3aa..6a6224b 100644
--- a/templates/main.cf-el5.erb
+++ b/templates/main.cf-el5.erb
@@ -33,7 +33,7 @@
 # The command_directory parameter specifies the location of all
 # postXXX commands.
 #
-command_directory = /usr/sbin
+command_directory = <%= @command_directory %>
 
 # The daemon_directory parameter specifies the location of all Postfix
 # daemon programs (i.e. programs listed in the master.cf file). This
@@ -581,7 +581,7 @@
 #
 # For details, see "man header_checks".
 #
-header_checks = regexp:/etc/postfix/header_checks
+header_checks = regexp:<%= @config_directory %>/header_checks
 
 # FAST ETRN SERVICE
 #
@@ -680,17 +680,17 @@
 # sendmail_path: The full pathname of the Postfix sendmail command.
 # This is the Sendmail-compatible mail posting interface.
 # 
-sendmail_path = /usr/sbin/sendmail.postfix
+sendmail_path = <%= @sendmail_path %>
 
 # newaliases_path: The full pathname of the Postfix newaliases command.
 # This is the Sendmail-compatible command to build alias databases.
 #
-newaliases_path = /usr/bin/newaliases.postfix
+newaliases_path = <%= @newaliases_path %>
 
 # mailq_path: The full pathname of the Postfix mailq command.  This
 # is the Sendmail-compatible mail queue listing command.
 # 
-mailq_path = /usr/bin/mailq.postfix
+mailq_path = <%= @mailq_path %>
 
 # setgid_group: The group for mail submission and queue management
 # commands.  This must be a group name with a numerical group ID that
@@ -704,16 +704,16 @@
 
 # manpage_directory: The location of the Postfix on-line manual pages.
 #
-manpage_directory = /usr/share/man
+manpage_directory = <%= @manpage_directory %>
 
 # sample_directory: The location of the Postfix sample configuration files.
 # This parameter is obsolete as of Postfix 2.1.
 #
-sample_directory = /usr/share/doc/postfix-2.3.3/samples
+sample_directory = <%= @sample_directory %>
 
 # readme_directory: The location of the Postfix README files.
 #
-readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
+readme_directory = <%= @readme_directory %>
 
 <% if @ssl -%>
 # TLS stuff
@@ -819,7 +819,7 @@
 <% end -%>
 
 <% end -%>
-body_checks = regexp:/etc/postfix/body_checks
+body_checks = regexp:<%= @config_directory %>/body_checks
 
 <% if @sender_canonical_maps -%>
 sender_canonical_maps = <%= @sender_canonical_maps %>
diff --git a/templates/main.cf.erb b/templates/main.cf.erb
index 019d1c6..0820a53 100644
--- a/templates/main.cf.erb
+++ b/templates/main.cf.erb
@@ -33,7 +33,7 @@
 # The command_directory parameter specifies the location of all
 # postXXX commands.
 #
-command_directory = /usr/sbin
+command_directory = <%= @command_directory %>
 
 # The daemon_directory parameter specifies the location of all Postfix
 # daemon programs (i.e. programs listed in the master.cf file). This
@@ -45,7 +45,7 @@
 # data files (caches, random numbers). This directory must be owned
 # by the mail_owner account (see below).
 #
-data_directory = /var/lib/postfix
+data_directory = <%= @data_directory %>
 
 # QUEUE AND PROCESS OWNERSHIP
 #
@@ -590,7 +590,7 @@
 #
 # For details, see "man header_checks".
 #
-header_checks = regexp:/etc/postfix/header_checks
+header_checks = regexp:<%= @config_directory %>/header_checks
 
 # FAST ETRN SERVICE
 #
@@ -689,17 +689,17 @@
 # sendmail_path: The full pathname of the Postfix sendmail command.
 # This is the Sendmail-compatible mail posting interface.
 # 
-sendmail_path = /usr/sbin/sendmail.postfix
+sendmail_path = <%= @sendmail_path %>
 
 # newaliases_path: The full pathname of the Postfix newaliases command.
 # This is the Sendmail-compatible command to build alias databases.
 #
-newaliases_path = /usr/bin/newaliases.postfix
+newaliases_path = <%= @newaliases_path %>
 
 # mailq_path: The full pathname of the Postfix mailq command.  This
 # is the Sendmail-compatible mail queue listing command.
 # 
-mailq_path = /usr/bin/mailq.postfix
+mailq_path = <%= @mailq_path %>
 
 # setgid_group: The group for mail submission and queue management
 # commands.  This must be a group name with a numerical group ID that
@@ -713,16 +713,16 @@
 
 # manpage_directory: The location of the Postfix on-line manual pages.
 #
-manpage_directory = /usr/share/man
+manpage_directory = <%= @manpage_directory %>
 
 # sample_directory: The location of the Postfix sample configuration files.
 # This parameter is obsolete as of Postfix 2.1.
 #
-sample_directory = /usr/share/doc/postfix-2.6.6/samples
+sample_directory = <%= @sample_directory %>
 
 # readme_directory: The location of the Postfix README files.
 #
-readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
+readme_directory = <%= @readme_directory %>
 
 <% if @ssl -%>
 # TLS stuff
@@ -847,7 +847,7 @@
 <% end -%>
 
 <% end -%>
-body_checks = regexp:/etc/postfix/body_checks
+body_checks = regexp:<%= @config_directory %>/body_checks
 
 <% if @sender_canonical_maps -%>
 sender_canonical_maps = <%= @sender_canonical_maps %>