# Install AbuseSA.
#
# === Global variables
#
#   $abusesa_datadir
#       AbuseSA home directory. Defaults to /var/lib/abusesa.
#
#   $abusesa_botnets
#       Array of botnet paths to start at boot.
#
class abusesa {

    case $::operatingsystem {
        "centos","redhat": {
            case $::operatingsystemrelease {
                /^5/: {
                    package { "python26":
                        ensure => installed,
                    }
                    Python::Setup::Install["/usr/local/src/abusesa"] {
                        python  => "python2.6",
                        require => Package["python26"],
                    }
                }
            }
        }
    }

    if !$abusesa_package {
        if $abusesa_package_latest {
            $abusesa_package = $abusesa_package_latest
        } else {
            fail("Must define \$abusesa_package or \$abusesa_package_latest")
        }
    }

    include user::system
    realize(User["abusesa"], Group["abusesa"])

    if $abusesa_datadir {
        file { $abusesa_datadir:
            ensure  => directory,
            mode    => "2770",
            owner   => "abusesa",
            group   => "abusesa",
            require => User["abusesa"],
        }
        file { "/var/lib/abusesa":
            ensure  => link,
            target  => $abusesa_datadir,
            require => File[$abusesa_datadir],
        }
    } else {
        file { "/var/lib/abusesa":
            ensure  => directory,
            mode    => "2770",
            owner   => "abusesa",
            group   => "abusesa",
            require => User["abusesa"],
        }
    }

    file { "/usr/local/src/abusesa.tar.gz":
        ensure => present,
        mode   => "0644",
        owner  => "root",
        group  => $::operatingsystem ? {
            "openbsd" => "wheel",
            default   => "root",
        },
        source => "puppet:///files/packages/${abusesa_package}",
    }
    util::extract::tar { "/usr/local/src/abusesa":
        ensure  => latest,
        strip   => 1,
        source  => "/usr/local/src/abusesa.tar.gz",
        require => File["/usr/local/src/abusesa.tar.gz"],
        before  => Python::Setup::Install["/usr/local/src/abusesa"],
    }
    python::setup::install { "/usr/local/src/abusesa": }

    if $abusesa_botnets {
        $abusehelper_botnets = $abusesa_botnets
        $abusehelper_user = "abusesa"
        include abusehelper::init
    }

}
