# $Id: Portfile 57375 2009-09-10 08:16:41Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               xcode 1.0

name                    sleepwatcher
version                 2.0.5
categories              sysutils
maintainers             ryandesign
homepage                http://www.bernhard-baehr.de/
master_sites            ${homepage}
distname                ${name}_${version}_src
extract.suffix          .tgz
xcode.destroot.path     ${prefix}/sbin

description \
    monitors sleep, wakeup and idleness of a Mac

long_description \
    SleepWatcher monitors sleep, wakeup and idleness of a Mac. It can be \
    used to execute a Unix command when the Mac or the display of the Mac \
    goes to sleep mode or wakes up or after a given time without user \
    interaction. It also can send the Mac to sleep mode or retrieve the \
    time since last user activity.

checksums \
    md5 886fd37f9ae2941e99eb507b312ba236 \
    sha1 4c1ca64d94768e0ccffb085d65632b4e37330882 \
    rmd160 f2b3a362b71a3b31e3c3774122fb282327e5151e

post-extract {
    reinplace "s|/usr/|${prefix}/|" ${worksrcpath}/sleepwatcher.xcodeproj/project.pbxproj
    reinplace "s|man/man1|man/man8|" ${worksrcpath}/sleepwatcher.xcodeproj/project.pbxproj
}

variant server {
    startupitem.create  yes
    startupitem.start   "${prefix}/sbin/sleepwatcher --verbose --daemon --pidfile ${prefix}/var/run/${name}.pid --sleep ${prefix}/etc/rc.sleep --wakeup ${prefix}/etc/rc.wakeup"
    startupitem.stop    "kill `cat ${prefix}/var/run/${name}.pid`"
    
    post-destroot {
        xinstall -m 755 -d ${prefix}/etc
        xinstall -m 755 "${worksrcpath}/SleepWatcher StartupItem.package/packagemaker.files/private/etc/rc.sleep" ${destroot}${prefix}/etc
        xinstall -m 755 "${worksrcpath}/SleepWatcher StartupItem.package/packagemaker.files/private/etc/rc.wakeup" ${destroot}${prefix}/etc
    }
    
    post-install {
        ui_msg "###########################################################"
        ui_msg "# Now each user can create scripts called .sleep and"
        ui_msg "# .wakeup in their home directories, and the ${name}"
        ui_msg "# daemon will run them at the appropriate times."
        ui_msg "###########################################################"
    }
}

default_variants +universal
variant universal {}
pre-fetch {
    if {![variant_isset universal]} {
        return -code error "${name} is only available in a universal version"
    }
}

livecheck.type          regex
livecheck.regex         ${name}_(\[0-9.\]+)\\.dmg
