# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 78805 2011-05-23 02:31:48Z mbclark@macports.org $

PortSystem          1.0

name                wview
version             5.19.0
categories          science
maintainers         macports.org:mbclark
homepage            http://wviewweather.com/
description         unix weather application that generates web sites

long_description \
  wview is a collection of linux/unix daemons that interface with a supported \
  weather station to retrieve archive records (if generated by the station) and \
  current conditions. The archive records are stored in an SQLite3 database. At a \
  configurable interval, wview will utilize the archive history and current \
  conditions to generate weather images (buckets, dials and graphs) and HTML web \
  pages based on user-configurable HTML templates.

platforms           darwin
use_autoconf        yes
master_sites        sourceforge:wview

depends_lib         port:gd2 port:radlib port:openssl port:libpng port:zlib \
                    port:sqlite3 port:curl port:gawk     

checksums           md5     7a615d953a56c8f5c604f839b7a291ed \
                    sha1    380e201866f0f6ab055c5816e15ebd85f1a7b950 \
                    rmd160  00340bc9e4859045874e1af3817844d0b7b2cd15

destroot.violate_mtree

post-destroot {
  xinstall -d -o root -g wheel -m 755 ${destroot}/Library/StartupItems
  
  xinstall -d -o root -g wheel -m 755 \
    ${worksrcpath}/examples/MacOSX/wview ${destroot}/Library/StartupItems/wview
  
  xinstall -o root -g wheel -m 755 ${worksrcpath}/examples/MacOSX/wview/wview \
    ${destroot}/Library/StartupItems/wview/wview
  
  xinstall -o root -g wheel -m 644 \
    ${worksrcpath}/examples/MacOSX/wview/StartupParameters.plist \
    ${destroot}/Library/StartupItems/wview/StartupParameters.plist
    
  file rename ${destroot}${prefix}/var/wviewmgmt ${destroot}${prefix}/www/wviewmgmt
  
  reinplace "s|/etc/init.d/wview stop|/sbin/SystemStarter stop wview|" \
    ${destroot}${prefix}/www/wviewmgmt/wview_control.php
    
  reinplace "s|/etc/init.d/wview start|/sbin/SystemStarter start wview|" \
    ${destroot}${prefix}/www/wviewmgmt/wview_control.php
    
  reinplace "s|/etc/init.d/wview stop|/sbin/SystemStarter stop wview|" \
    ${destroot}${prefix}/www/wviewmgmt/wview_upgrade.php
  
  file mkdir ${destroot}${prefix}/share/${name}
  
  file mkdir ${destroot}${prefix}/share/doc/${name}
  
  file mkdir ${destroot}${prefix}/share/${name}/etc
  
  file mkdir ${destroot}${prefix}/share/${name}/var
  
  file mkdir ${destroot}${prefix}/share/${name}/examples
  
  file rename ${destroot}${prefix}/etc/${name} \
    ${destroot}${prefix}/share/${name}/etc/${name}
  
  file rename ${destroot}${prefix}/var/${name} \
    ${destroot}${prefix}/share/${name}/var/${name}
  
  file copy ${worksrcpath}/examples/conf \
    ${destroot}${prefix}/share/${name}/examples/conf
  
  file copy ${worksrcpath}/wview-Quick-Start-MacOSX.html \
    ${destroot}${prefix}/share/doc/${name}/wview-Quick-Start-MacOSX.html
  
  file copy ${worksrcpath}/wview-Quick-Start.html \
    ${destroot}${prefix}/share/doc/${name}/wview-Quick-Start.html
  
  file copy ${worksrcpath}/wview-User-Manual.html \
    ${destroot}${prefix}/share/doc/${name}/wview-User-Manual.html
  
  file copy ${worksrcpath}/COPYING \
    ${destroot}${prefix}/share/doc/${name}/COPYING
  
  file copy ${worksrcpath}/UPGRADE \
    ${destroot}${prefix}/share/doc/${name}/UPGRADE
}

post-install {
  if {![file exists ${prefix}/var/${name}]} {
    file copy ${destroot}${prefix}/share/${name}/var/${name} ${prefix}/var/wview
  }
  
  if {![file exists ${prefix}/etc/${name}/wview-conf.sdb]} {
    file copy ${destroot}${prefix}/share/${name}/etc/${name} ${prefix}/etc/wview
    file attributes ${prefix}/etc/wview -group www -permissions rwxrwxr-x
    file attributes ${prefix}/etc/${name}/wview-conf.sdb -group www -permissions rw-rw-r--
  } else {
    file copy -force ${destroot}${prefix}/share/${name}/etc/${name}/wview-conf-update.sql \
      ${prefix}/etc/${name}/wview-conf-update.sql
    exec sqlite3 ${prefix}/etc/${name}/wview-conf.sdb <  ${prefix}/etc/${name}/wview-conf-update.sql
  }
  
  file copy -force ${destroot}${prefix}/share/${name}/etc/${name}/wview-version \
    ${prefix}/etc/wview/wview-version
}

notes "#####################################
  Run
    sudo ${prefix}/bin/wviewconfig
    sudo ${prefix}/bin/wviewhtmlconfig
  before launching wview
#####################################
  html templates and config files are stored in
    ${prefix}/etc/wview/
  archive files are stored in
    ${prefix}/var/wview/
#####################################
  wviewmgmt scripts are installed in
    ${prefix}/www/wviewmgmt
#####################################
  Start the daemons with the command:
    sudo /sbin/SystemStarter start wview
#####################################"

