# -*- 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 113155 2013-11-11 01:54:29Z pixilla@macports.org $

PortSystem          1.0
PortGroup           github 1.0

# set fullhash      6d10afe73e1fb5f21688d4b6d6919cab618e6e88
set shorthash       6d10afe7
github.setup        MythTV mythweb ${shorthash}
version             .27
revision            20131017
set minorversion    ""
name                mythweb${version}
categories          multimedia www
platforms           darwin
license             GPL-2 LGPL-2.1
maintainers         cogeco.ca:ctreleaven openmaintainer
supported_archs     noarch
conflicts           mythweb.25 mythweb.26

description         control your Myth system via a web browser
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  1834ffc20572e06ee83e05126796ae5dcb096009 \
                    sha256  b9a9cd9148ba97031af9ec0f37d347a1fb060a3615ef403d3e922d07954312d8

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

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-${shorthash} \
        ${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.type              none
