--- Portfile.orig	2011-02-22 14:32:57.000000000 -0500
+++ Portfile	2011-02-22 14:41:07.000000000 -0500
@@ -1,5 +1,5 @@
 # -*- 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$
+# $Id: Portfile 76365 2011-02-21 04:47:56Z ryandesign@macports.org $
 
 PortSystem              1.0
 
@@ -93,7 +93,11 @@
                         GPP=${configure.cxx} \
                         CPPreal=${configure.cpp}
 
-destroot.keepdirs       ${destroot}${prefix}/share/arb/lib/pts
+pre-destroot            {
+                        # Give the default settings a recognizable name ending in .default
+                        file rename ${worksrcpath}/lib/arb_tcp.dat ${worksrcpath}/lib/arb_tcp.dat.default
+                        file rename ${worksrcpath}/lib/macros ${worksrcpath}/lib/macros.default
+}
 
 destroot                {
                         eval xinstall -m 0755 [glob ${worksrcpath}/bin/*] ${destroot}${prefix}/bin
@@ -105,9 +109,6 @@
                         file copy ${worksrcpath}/PERL_SCRIPTS ${destroot}${prefix}/share/arb/PERL_SCRIPTS
                         file copy ${worksrcpath}/SH ${destroot}${prefix}/share/arb/SH
                         file copy ${worksrcpath}/demo.arb ${destroot}${prefix}/share/arb
-                        file attributes ${destroot}${prefix}/share/arb/lib/arb_tcp.dat -permissions a+w
-                        file attributes ${destroot}${prefix}/share/arb/lib/pts -permissions a+w
-                        file attributes ${destroot}${prefix}/share/arb/lib/macros -permissions a+w
                         ln -s ${prefix}/bin/arb_pt_server ${destroot}${prefix}/share/arb/bin/arb_pt_server
                         ln -s ${prefix}/bin/arb_name_server ${destroot}${prefix}/share/arb/bin/arb_name_server
 }
@@ -117,6 +118,23 @@
 
 post-activate           {
                         system "rm -rf `find ${prefix}/share/arb -type d -name .svn`"
+                        
+                        # Presere the user's pt_server config file and macros; otherwise set default values
+                        foreach f { arb_tcp.dat macros } {
+                            if {![file exists ${prefix}/share/arb/lib/${f}]} {
+                                  file copy ${worksrcpath}/lib/${f}.default \
+                                       ${prefix}/share/arb/lib/${f}
+                                  file attributes ${prefix}/share/arb/lib/${f} -permissions a+w
+                            }
+                        }
+                        
+                        # Preserve the directory where the user's pt_servers are saved; otherwise create it
+                         foreach f { pts } {
+                            if {![file exists ${prefix}/share/arb/lib/${f}]} {
+                                  file mkdir ${prefix}/share/arb/lib/${f}
+                                  file attributes ${prefix}/share/arb/lib/${f} -permissions a+w
+                            }
+                        }
 }
 
 notes "
@@ -132,7 +150,7 @@
 	
 B) Follow the steps below:
 
-1a)
+1)
 bash users add the following lines to your ~/.profile or to your ~/.bashrc
 
       ARBHOME=${prefix}/share/arb;export ARBHOME
@@ -141,17 +159,31 @@
 
       enter the following command:
       . ~/.profile
-1b)
+2)
 tcsh users add the following lines to your ~/.cshrc
+      
       setenv ARBHOME ${prefix}/share/arb
       setenv PATH ${prefix}/share/arb\:\$PATH
 
       enter the following command:
       source ~/.cshrc
-2)
+C)
 type arb to start ARB
 
 A demo data base is located at ${prefix}/share/arb/demo.arb
 
+************************************************************************
+User generated macros, arb_tcp.dat and pt_servers have been preserved,
+but you should keep backups of these just in case.  They are located at:
+
+${prefix}/share/arb/lib/macros/
+${prefix}/share/arb/lib/arb_tcp.dat
+${prefix}/share/arb/lib/pts/
+
+Default settings are maintained at:
+
+${prefix}/share/arb/lib/macros.default/
+${prefix}/share/arb/lib/arb_tcp.dat.default
+
 Please cite: Wolfgang Ludwig, et al. (2004) ARB: a software environment for sequence data. Nucleic Acids Research. 32:1363-1371
 "
