--- /Users/julien/tmp/myports/_orig/security/sguil-client/Portfile	2013-07-15 12:03:52.000000000 -0400
+++ security/sguil-client/Portfile	2014-08-31 17:33:00.000000000 -0400
@@ -1,40 +1,49 @@
+# -*- 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 104513 2013-03-26 13:11:13Z jmr@macports.org $
 
 PortSystem 1.0
 
-name			sguil-client
-version			0.6.1
-revision        1
-categories		security net
-license			QPL-1 Permissive
-maintainers		nomaintainer
-description		GUI Console for Sguil Network Security Monitor
-long_description	${description}
-platforms		darwin
-supported_archs	noarch
-homepage		http://sguil.sf.net
-master_sites		sourceforge:sguil
-checksums		md5 68d209f882d4c8fa9c200ba0924b00b3
-worksrcdir		sguil-${version}
-depends_build		port:itcl \
-			port:tclx \
-			port:itk \
-			port:iwidgets \
-			port:tcllib \
-			port:tcl-tls \
-			port:openssl
+PortGroup           github 1.0
 
-use_configure		no
+github.setup        bammv sguil 0.9.0
+name                sguil-client
+#version            0.9.0
+categories         security net
+license            QPL-1 Permissive
+maintainers        nomaintainer
+description        GUI Console for Sguil Network Security Monitor
+long_description    ${description}
+platforms        darwin
+supported_archs    noarch
+homepage        https://bammv.github.io/sguil/
+#master_sites        sourceforge:sguil
+master_sites    https://github.com/bammv/sguil/archive/
+distname        v${version}
+
+worksrcdir        sguil-${version}
+
+checksums           rmd160  b01425bcbe20fcce51f6ad73f88482ddfa2a811f \
+                    sha256  412be894d67a6487312dd16a98a580dda8c38cff2e24f7a6c25405857769782b
+
+depends_build        port:itcl \
+            port:tclx \
+            port:itk \
+            port:iwidgets \
+            port:tcllib \
+            port:tcl-tls \
+            port:openssl
+
+use_configure        no
 build {}
 
 post-patch {
-	reinplace "s|set SGUILLIB ./lib|set SGUILLIB ${prefix}/lib/sguil|g" \
-		${worksrcpath}/client/sguil.conf
-	reinplace "s|set ETHEREAL_PATH /usr/sbin/ethereal|set ETHEREAL_PATH ${prefix}/bin/ethereal|g" \
+    reinplace "s|set SGUILLIB ./lib|set SGUILLIB ${prefix}/lib/sguil|g" \
+        ${worksrcpath}/client/sguil.conf
+    reinplace "s|set ETHEREAL_PATH /usr/sbin/ethereal|set ETHEREAL_PATH ${prefix}/bin/ethereal|g" \
                 ${worksrcpath}/client/sguil.conf
-	reinplace "s|set SERVERHOST demo.sguil.net|set SERVERHOST localhost|g" \
+    reinplace "s|set SERVERHOST demo.sguil.net|set SERVERHOST localhost|g" \
                 ${worksrcpath}/client/sguil.conf
-	reinplace "s|set MAILSERVER mail.example.com|set MAILSERVER localhost|g" \
+    reinplace "s|set MAILSERVER mail.example.com|set MAILSERVER localhost|g" \
                 ${worksrcpath}/client/sguil.conf
 }
 
@@ -45,12 +54,103 @@
 set sguildoc  ${prefix}/share/doc/sguil
 set sguiletc  ${prefix}/etc/sguil
 
-	xinstall -m 755 -d ${destroot}${sguilbin}
-	xinstall -m 755 ${worksrcpath}/client/sguil.tk ${destroot}${sguilbin}
-	xinstall -m 755 -d ${destroot}${sguillib}
-	system "cp -R ${worksrcpath}/client/lib/* ${destroot}${sguillib}"
-	xinstall -m 755 -d ${destroot}${sguildoc}
-	system "cp ${worksrcpath}/doc/* ${destroot}${sguildoc}"
-	xinstall -m 755 -d ${destroot}${sguiletc}
-	xinstall -m 755 ${worksrcpath}/client/sguil.conf ${destroot}${sguiletc}/sguil.conf.sample
+    xinstall -m 755 -d ${destroot}${sguilbin}
+    xinstall -m 755 ${worksrcpath}/client/sguil.tk ${destroot}${sguilbin}
+    xinstall -m 755 -d ${destroot}${sguillib}
+    system "cp -R ${worksrcpath}/client/lib/* ${destroot}${sguillib}"
+    xinstall -m 755 -d ${destroot}${sguildoc}
+    system "cp ${worksrcpath}/doc/* ${destroot}${sguildoc}"
+    xinstall -m 755 -d ${destroot}${sguiletc}
+    xinstall -m 755 -d ${destroot}${prefix}/share/examples/${name}
+    xinstall -m 644 ${worksrcpath}/client/sguil.conf ${destroot}${prefix}/share/examples/${name}/
+
+    if {${subport} eq "sguil-server"} {
+        xinstall -m 755 ${worksrcpath}/server/sguild ${destroot}${prefix}/sbin/
+        xinstall -m 755 -d ${destroot}${prefix}/share/sguild
+        copy ${worksrcpath}/server/lib ${destroot}${prefix}/share/sguild/
+
+        xinstall -m 755 -d ${destroot}${prefix}/share/examples/sguild
+        copy ${worksrcpath}/server/sql_scripts ${destroot}${prefix}/share/examples/sguild/
+        foreach f { sguild.conf sguild.users sguild.queries sguild.access } {
+            xinstall -m 644 ${worksrcpath}/server/${f} ${destroot}${prefix}/share/examples/sguild/
+        }
+    }
+}
+
+post-activate {
+    if {${subport} eq "sguil-client"} {
+        if ![file exists ${sguiletc}/sguil.conf ] {
+            copy ${prefix}/share/examples/${name}/sguil.conf ${sguiletc}/
+        }
+    }
+    if {${subport} eq "sguil-server"} {
+        foreach f { sguild.conf sguild.users sguild.queries sguild.access } {
+            if ![file exists ${prefix}/etc/sguild/${f} ] {
+                copy ${prefix}/share/examples/sguild/${f} ${prefix}/etc/sguild/
+            }
+        }
+    }
+}
+
+if {${subport} eq ${name}} {
+    
+    conflicts          ${name}-devel
+    
+}
+
+subport ${name}-devel {
+    fetch.type git
+    git.url    https://github.com/bammv/sguil.git
+    version    20140813
+    git.branch b708fa838722ac6cd8c006d3d6587e800ef14e67
+
+    conflicts          ${name}
+    
+    livecheck.type     none
 }
+
+subport sguil-server {
+    ## variant ?
+    depends_run-append  port:mysql56-server port:mysqltcl
+
+    add_users sguil group=sguil home=${prefix}/var/db/sguil shell=/sbin/nologin realname=sguil\ user
+
+    notes-append "
+*** To install sguil server ***
+
+1) Install and create sguil database
+
+    shell> mysql -u root -p mysql
+    mysql> GRANT ALL PRIVILEGES ON sguildb.*
+                 TO sguil@localhost IDENTIFIED BY 'sguilpasswd';
+    mysql> FLUSH PRIVILEGES;
+
+    $ mysql -u sguil -p -e \"CREATE DATABASE sguildb\"
+    $ mysql -u sguil -p -D sguildb < ./server/sql_scripts/create_sguildb.sql
+
+2) Install the GUI server (sguild)
+    ?port select --list tclsh       NOK
+
+    Check ${prefix}/etc/sguild files especially snort rules path.
+    Add user:
+    $ sguild -adduser <username>
+
+"
+
+    startupitem.create      yes
+    startupitem.name        sguild
+    startupitem.executable  "${prefix}/bin/sguild -D"
+}
+
+notes-append "
+
+*** To finish sguil install ***
+
+3) Install the GUI client (sguil.tk)
+4) Install the sensor
+
+"
+
+livecheck.type     regex
+livecheck.url       ${homepage}
+livecheck.regex     ">Sguil (\\d+(?:\\.\\d+)*)"
