# Install abusehelper from svn.
#
class abusehelper {

    case $operatingsystem {
        ubuntu: {
            package { [ "python-pyme", "python-tz" ]:
                ensure => installed,
            }
        }
        centos: {
            package { "python26":
                ensure => installed,
            }
        }
    }

    file { "/usr/local/src/abusehelper.tar.gz":
        ensure => present,
        mode   => 0644,
        owner  => root,
        group  => root,
        source => "puppet:///files/packages/abusehelper.tar.gz",
        links  => follow,
    }
    util::extract::tar { "/usr/local/src/abusehelper":
        strip   => 1,
        source  => "/usr/local/src/abusehelper.tar.gz",
        require => File["/usr/local/src/abusehelper.tar.gz"],
        before  => Python::Setup::Install["/usr/local/src/abusehelper"],
    }
    file { "/usr/local/src/idiokit.tar.gz":
        ensure => present,
        mode   => 0644,
        owner  => root,
        group  => root,
        source => "puppet:///files/packages/idiokit.tar.gz",
        links  => follow,
    }
    util::extract::tar { "/usr/local/src/idiokit":
        strip   => 1,
        source  => "/usr/local/src/idiokit.tar.gz",
        require => File["/usr/local/src/idiokit.tar.gz"],
        before  => Python::Setup::Install["/usr/local/src/idiokit"],
    }
    python::setup::install { [ "/usr/local/src/abusehelper",
                               "/usr/local/src/idiokit", ]:
        python  => $operatingsystem ? {
            centos  => "python2.6",
            default => "python",
        },
        require => $operatingsystem ? {
            centos  => Package["python26"],
            default => undef,
        },
    }

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

    if $abusehelper_datadir {
        file { "${abusehelper_datadir}":
            ensure  => directory,
            mode    => 0750,
            owner   => root,
            group   => abusehel,
            require => User["abusehel"],
        }

        file { "/var/lib/ah2":
            ensure  => link,
            target  => "${abusehelper_datadir}",
            require => File["${abusehelper_datadir}"],
        }
    } else {
        file { "/var/lib/ah2":
            ensure  => directory,
            mode    => 0750,
            owner   => root,
            group   => abusehel,
            require => User["abusehel"],
        }
    }

}
