# -*- 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 83226 2011-08-29 04:50:53Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               xcode 1.0

name                    sleepwatcher
version                 2.2
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               rmd160  4e1ff469e59ae992ee297cb16a96a74e9993d4bb \
                        sha256  c04ac1c49e2b5785ed5d5c375854c9c0b9e959affa46adab57985e4123e8b6be

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.\
"
