# -*- 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 99027 2012-10-24 14:05:42Z pixilla@macports.org $

PortSystem          1.0
PortGroup           github 1.0

github.setup        MythTV mythweb 0.25.3 v
name                mythweb.25
categories          multimedia www
platforms           darwin
license             GPL-2 LGPL-2.1
maintainers         cogeco.ca:ctreleaven openmaintainer
supported_archs     noarch

description         Control your Myth system via the Web.
long_description    MythWeb provides a frontend to MythTV using a web browser. \
                    Review program listings, schedule recordings, browse previous recordings, \
                    check on the status of your system and much more.  Note that this is an \
                    INSECURE installation intended for local network access only.  Take steps to \
                    secure if access from the internet is to be allowed.  This port does not \
                    install MythTV since it is possible to have the web server and Myth backend \
                    on different machines.

homepage            http://www.mythtv.org/
checksums           rmd160  84d1bf375ff73554f5e112e9f0a8fb42cdec30aa \
                    sha256  e07dba17920ece1d796a0d308d955214e3c0a5193974fd8e7f8e769f26a80f76

set perlver         perl5.12
set perlbin         ${prefix}/bin/${perlver}
set perlmodver      p5.12

depends_run         port:php5-mysql

depends_lib         port:${perlmodver}-http-request-ascgi \
                    port:${perlmodver}-dbd-mysql

patchfiles          patch_mythweb.conf.diff

# Re class_autoload, see http://code.mythtv.org/trac/ticket/10600
patchfiles-append   class_autoload.patch

use_configure       no
build               {}

pre-patch {
    copy ${worksrcpath}/mythweb.conf.apache ${worksrcpath}/mythweb.conf
}

post-patch {
    reinplace -locale C "s|@PREFIX@|${prefix}|g" ${worksrcpath}/mythweb.conf
    reinplace -locale C "s|/usr/local|${prefix}|" ${worksrcpath}/mythweb.php

    reinplace -locale C "s|#!/usr/bin/perl|#!${perlbin}|" \
         ${worksrcpath}/mythweb.pl \
         ${worksrcpath}/modules/_shared/lang/build_translation.pl \
         ${worksrcpath}/modules/coverart/handler.pl \
         ${worksrcpath}/modules/stream/handler.pl \
         ${worksrcpath}/modules/stream/stream_asx.pl \
         ${worksrcpath}/modules/stream/stream_flv.pl \
         ${worksrcpath}/modules/stream/stream_flvp.pl \
         ${worksrcpath}/modules/stream/stream_mp4.pl \
         ${worksrcpath}/modules/stream/stream_raw.pl \
         ${worksrcpath}/modules/stream/tv.pl
}

destroot {
    xinstall -d ${destroot}${prefix}/apache2/htdocs
    copy ${worksrcpath} ${destroot}${prefix}/apache2/htdocs
    file rename ${destroot}${prefix}/apache2/htdocs/mythweb-${version} \
        ${destroot}${prefix}/apache2/htdocs/MythWeb
    system "chown -R _www:_www ${destroot}${prefix}/apache2/htdocs/MythWeb/data"

    destroot.violate_mtree yes

    destroot.keepdirs \
        ${destroot}${prefix}/apache2/htdocs/MythWeb/data/cache \
        ${destroot}${prefix}/apache2/htdocs/MythWeb/data/tv_icons
}

notes "\
############################################################################
#
# If this is the first time installing MythWeb, please see
# http://www.mythtv.org/wiki/MythWeb_via_MacPorts for information
# essential to finishing the installation of MythWeb!
#
############################################################################"

livecheck.version           ${version}
livecheck.regex             "tarball/v(0.25\[^\"\]+)"
