# -*- 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

PortSystem          1.0
PortGroup           github 1.0

# set fullhash      ed8d6a1c9621c612fb3e69d85c78614cdf0996fa
set shorthash       ed8d6a1c
github.setup        MythTV mythweb ${shorthash}
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
set majorversion    .28
set minorversion    .1
name                mythweb${majorversion}
version             0${majorversion}${minorversion}-Fixes-20170719
revision            3
checksums           rmd160  87d3dca327aa5ece6cb546bc94a0433e8ecb3de4 \
                    sha256  5691a175c87307694bddb744058b53b92d1f41b69da7db48721c69c4f00936bc
categories          multimedia www
platforms           any
license             GPL-2 LGPL-2.1
maintainers         nomaintainer
supported_archs     noarch
conflicts           mythweb.25 mythweb.26 mythweb.27

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.

homepage            https://www.mythtv.org/

set perlver         perl5.28
set perlbin         ${prefix}/bin/${perlver}
set perlmodver      p5.28
set phpver          php54
set webroot         ${prefix}/www/apache2/html
#set webroot         ${prefix}/apache2/htdocs

depends_run         port:mythtv-core${majorversion} \
                    port:${perlmodver}-http-request-ascgi \
                    port:${perlmodver}-dbd-mysql \
                    port:${phpver}-apache2handler \
                    port:${phpver}-mysql \
                    port:${phpver}-posix \
                    port:${phpver}-sockets

# mythtv-core already ensures p5.28-dbd-mysql +mariadb variant is active.
# No need to repeat here

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}${webroot}
    copy ${worksrcpath} ${destroot}${webroot}
    file rename ${destroot}${webroot}/mythweb-${shorthash} \
        ${destroot}${webroot}/MythWeb
    system "chown -R _www:_www ${destroot}${webroot}/MythWeb/data"
    destroot.keepdirs \
        ${destroot}${webroot}/MythWeb/data/cache \
        ${destroot}${webroot}/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!
#
# Upgrading for the first time after October 20, 2017?  Check your 
# configuration with the above wiki page.
#
############################################################################"

livecheck.type              none
