ccnx: Final customizations. Adding java and apps variants (enabled by
default), ccnx user is automatically created, and daemon is running as
ccnx, instead of root
diff --git a/net/ccnx/Portfile b/net/ccnx/Portfile
index 5a53738..33d9136 100644
--- a/net/ccnx/Portfile
+++ b/net/ccnx/Portfile
@@ -22,46 +22,72 @@
             contributing to its evolution. 
 homepage    http://www.ccnx.org/
 
-fetch.type git
-git.url    https://github.com/ProjectCCNx/ccnx.git
-git.branch ccnx-0.6.1
+# fetch.type git
+# git.url    https://github.com/ProjectCCNx/ccnx.git
+# git.branch ccnx-0.6.1
 
-# master_sites http://www.ccnx.org/releases/
-# checksums   rmd160 9c8eb49aa8d2edfe5eb873312f6273ca469255a4 \
-#             sha256 7ac8f2ac3b6bcda85e9b4df34c025f68d576d98dcadf16eea2ed1c3dcee4d557
+master_sites http://www.ccnx.org/releases/
+checksums   rmd160 073478f3d5818b0e4fe09e21a727e5f3207e4277 \
+            sha256 bfaae10c2c1a327d77f752737b60243e23fd8f3a7c7025ae92221ba0a700b889 
 
-# use_parallel_build  yes
+use_parallel_build  yes
 
 depends_lib port:openssl \
             port:expat \
             port:libpcap \
             port:libxml2
 
-# default_variants   +java
+set ccnxuser  ccnx
+set ccnxgroup ccnx
+set ccnxdir   ${prefix}/etc/ccnx
+
+add_users ${ccnxuser} shell=/bin/sh group=${ccnxgroup} \
+    home=${ccnxdir} \
+    realname=CCNx\ Account
+
+default_variants   +java +apps
+
+variant java description {Enable Java API build} {
+    configure.env-delete BUILD_JAVA=false
+}
+
+variant apps requires java description {Enable build of reference applications} {
+    configure.env-delete BUILD_APPS=false
+}
 
 configure.env-append OPENSSL_CFLAGS=-I${prefix}/include
 configure.env-append OPENSSL_LIBS=-L${prefix}/lib
 configure.env-append INSTALL_BASE=${prefix}
+configure.env-append BUILD_JAVA=false
+configure.env-append BUILD_APPS=false
 configure.cflags -DCCNX_DIR=\\\"${prefix}/etc/ccnx\\\" 
 
 pre-build {
     reinplace "s|\$HOME/.ccnx/|${prefix}/etc/ccnx/|g" ${worksrcpath}/csrc/util/ccndstart.sh 
 }
 
+post-destroot {
+    system "mkdir -p ${destroot}${prefix}/var/log"
+    system "touch ${destroot}${prefix}/var/log/ccnd.log"
+    system "chown ${ccnxuser}:${ccnxgroup} ${destroot}${prefix}/var/log/ccnd.log"
+
+    file mkdir ${destroot}${prefix}/etc/ccnx
+    file copy ${worksrcpath}/csrc/libexec/ccnd.conf.sample ${destroot}${prefix}/etc/ccnx/
+
+    system "echo CCND_LOG=${prefix}/var/log/ccnd.log > ${destroot}${prefix}/etc/ccnx/ccndrc.sample"
+    system "echo CCND_DEBUG=16 >> ${destroot}${prefix}/etc/ccnx/ccndrc.sample"
+}
+
 build.env-append OPENSSL_CFLAGS=-I${prefix}/include
 build.env-append OPENSSL_LIBS=-L${prefix}/lib
-build.env-append INSTALL_BASE=${destroot}${prefix}
-build.env-append CCNX_DIR=${destroot}${prefix}/etc/ccnx
-
-destroot.env-append INSTALL_BASE=${destroot}${prefix}
-destroot.env-append CCNX_DIR=${destroot}${prefix}/etc/ccnx
+build.env-append INSTALL_BASE=${prefix}
 
 patchfiles    patch-macports-customizations.diff
 
 startupitem.pidfile     none
-startupitem.start       "${prefix}/bin/ccndstart"
-startupitem.stop        "${prefix}/bin/ccndstop"
-startupitem.restart     "${prefix}/bin/ccndstop && sleep 3 && ${prefix}/bin/ccndstart"
+startupitem.start       "su ${ccnxuser} -c \"${prefix}/bin/ccndstart\""
+startupitem.stop        "su ${ccnxuser} -c \"${prefix}/bin/ccndstop\""
+startupitem.restart     "su ${ccnxuser} -c \"${prefix}/bin/ccndstop && sleep 3 && ${prefix}/bin/ccndstart\""
 
 startupitem.create      yes
 startupitem.name        ccnx