# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 75749 2011-02-07 02:47:30Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               xcode 1.0

name                    sleepwatcher
version                 2.1.1
categories              sysutils
maintainers             ryandesign
license                 GPL-3+
homepage                http://www.bernhard-baehr.de/
master_sites            ${homepage}
distname                ${name}_${version}
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               sha1    3c199f4bffc4ecf8a774119ff370500454bd49bc \
                        rmd160  e12f555e4b4970ca17a302d0d4fa84f1024d048c

pre-fetch {
    if {${os.major} < 9} {
        ui_error "${name} ${version} requires Mac OS X 10.5 or greater."
        return -code error "incompatible Mac OS X version"
    }
}

build.dir               ${worksrcpath}/sources

post-patch {
    reinplace "s|/usr/local/|${prefix}/|" ${build.dir}/sleepwatcher.xcodeproj/project.pbxproj
}

post-destroot {
    xinstall -m 755 -W ${worksrcpath}/config rc.sleep rc.wakeup ${destroot}${prefix}/etc
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} ReadMe.rtf ${docdir}
}

startupitem.create      yes
startupitem.executable  ${prefix}/sbin/sleepwatcher \
                        --verbose \
                        --sleep ${prefix}/etc/rc.sleep \
                        --wakeup ${prefix}/etc/rc.wakeup

livecheck.type          regex
livecheck.regex         (?i)>${name} (\[0-9.\]+)<

notes "\
The included system-wide launchd plist starts a ${name} daemon which calls\
the scripts \".sleep\" and \".wakeup\" in your home directory when the\
computer goes to sleep and wakes up, respectively.\
For more control, and to be able to respond to display sleep, idle, and\
power manager events, ignore the system-wide launchd plist and write your\
own user-specific plist.\
Consult the manpage for the full range of possibilities.\
"
