Index: base/src/registry1.0/portuninstall.tcl
===================================================================
--- base/src/registry1.0/portuninstall.tcl	(revision 135)
+++ base/src/registry1.0/portuninstall.tcl	(working copy)
@@ -38,6 +38,61 @@
 
 namespace eval portuninstall {
 
+
+proc run-pre-uninstall {ref portname version revision variants} {
+	# this is not used in this procedure
+	# also not used in deactivate - even though defined
+	# I suspect it was assumed that the file names are being taken
+	# from the registry so prefix not needed
+	# we no longer need to worry about it here as we have added the definition
+	# to makeprepostuserproc
+	# I think the prefix should be stored in the registry and restored from there
+	# then dont have to assume the prefix is the same as when the port was first
+	# installed
+	#global macports::prefix
+
+	# execute the pre-uninstall procedures
+	set uninstall-proc-list [registry::property_retrieve $ref regproc-pre-uninstall-list] 
+	if { ${uninstall-proc-list} != 0 } {
+		foreach myuninstall ${uninstall-proc-list} {
+			set uninstall-name [lindex $myuninstall 1]
+			if {![catch {eval [string map { \\n \n } $myuninstall]} err]} {
+				ui_info "Executing ${uninstall-name} procedure"
+				if {[catch {${uninstall-name} $portname ${version}_${revision}${variants} $portname ${version} ${revision} ${variants} } err]} {
+					ui_error [format [msgcat::mc "Error executing ${uninstall-name} procedure: %s"] $err]
+				}
+			} else {
+				global errorInfo
+				ui_debug "$errorInfo"
+				ui_error [format [msgcat::mc "Could not evaluate ${uninstall-name} procedure: %s"] $err]
+			}
+		}
+	}
+}
+
+proc run-post-uninstall {ref portname version revision variants} {
+	#global macports::prefix
+
+	# execute the post-uninstall procedures
+	set uninstall-proc-list [registry::property_retrieve $ref regproc-post-uninstall-list] 
+	if { ${uninstall-proc-list} != 0 } {
+		foreach myuninstall ${uninstall-proc-list} {
+			set uninstall-name [lindex $myuninstall 1]
+			if {![catch {eval [string map { \\n \n } $myuninstall]} err]} {
+				ui_info "Executing ${uninstall-name} procedure"
+				if {[catch {${uninstall-name} $portname ${version}_${revision}${variants} $portname ${version} ${revision} ${variants} } err]} {
+					ui_error [format [msgcat::mc "Error executing ${uninstall-name} procedure: %s"] $err]
+				}
+			} else {
+				global errorInfo
+				ui_debug "$errorInfo"
+				ui_error [format [msgcat::mc "Could not evaluate ${uninstall-name} procedure: %s"] $err]
+			}
+		}
+	}
+}
+
+
 proc uninstall {portname {v ""} optionslist} {
 	global uninstall.force uninstall.nochecksum UI_PREFIX
 	array set options $optionslist
@@ -130,25 +185,16 @@
 	}
 
 	set installtype [registry::property_retrieve $ref installtype]
+
 	if { $installtype == "image" && [registry::property_retrieve $ref active] == 1} {
 		#return -code error [msgcat::mc "Registry Error: ${portname} ${version}_${revision}${variants} is active."]
 		portimage::deactivate $portname ${version}_${revision}${variants} $optionslist
+	} else {
+		run-pre-uninstall $ref $portname $version $revision $variants
 	}
 
 	ui_msg "$UI_PREFIX [format [msgcat::mc "Uninstalling %s @%s_%s%s"] $portname $version $revision $variants]"
 
-	# Look to see if the port has registered an uninstall procedure
-	set uninstall [registry::property_retrieve $ref pkg_uninstall] 
-	if { $uninstall != 0 } {
-		if {![catch {eval $uninstall} err]} {
-			pkg_uninstall $portname ${version}_${revision}${variants}
-		} else {
-			global errorInfo
-			ui_debug "$errorInfo"
-			ui_error [format [msgcat::mc "Could not evaluate pkg_uninstall procedure: %s"] $err]
-		}
-	}
-
 	# Remove the port from the deps_map if only one version was installed.
 	# This is a temporary fix for a deeper problem that is that the dependency
 	# map doesn't take the port version into account (but should).
@@ -174,7 +220,7 @@
 				set sumx {}
 			}
 			set sum1 [lindex $sumx [expr [llength $sumx] - 1]]
-			if {![string match $sum1 NONE] && ![info exists uninstall.nochecksum] && ![string equal -nocase $uninstall.nochecksum "yes"] } {
+			if {![string match $sum1 NONE] && !([info exists uninstall.nochecksum] && [string equal -nocase $uninstall.nochecksum "yes"]) } {
 				if {![catch {set sum2 [md5 $fname]}]} {
 					if {![string match $sum1 $sum2]} {
 						if {![info exists uninstall.force] && ![string equal -nocase $uninstall.force "yes"] } {
@@ -211,6 +257,16 @@
 			return -code error $result
 		}
 
+		# finally run the post-uninstall procedure
+		# really added for symmetry
+		# not clear anything useful could be done at this point
+		# we need to run here because of the return 0 below
+		# also need to run before delete port from registry - we read the procs
+		# from the registry!!
+		# at the moment this is not run if registry has no contents for port
+		# - note that in that case the registry entry for the port isnt deleted either!!
+		run-post-uninstall $ref $portname $version $revision $variants
+
 		if {!$uninst_err || [info exists uninstall.force] && [string equal -nocase $uninstall.force "yes"] } {
 			ui_info "$UI_PREFIX [format [msgcat::mc "Uninstall is removing %s from the port registry."] $portname]"
 			registry::delete_entry $ref
Index: base/src/registry1.0/portimage.tcl
===================================================================
--- base/src/registry1.0/portimage.tcl	(revision 135)
+++ base/src/registry1.0/portimage.tcl	(working copy)
@@ -32,6 +32,7 @@
 
 package provide portimage 1.0
 
+#package require portuninstall 1.0
 package require registry 1.0
 package require macports 1.0
 package require Pextlib 1.0
@@ -62,6 +63,33 @@
 # code very similar to what is used in portinstall is used.
 #
 
+# hmm - this looks like can be defined here - not used elsewhere
+# also means we dont need to require the port1.0 package here
+
+namespace eval portinstall {
+
+proc run-post-install {ref name version revision variants} {
+
+	set install-proc-list [registry::property_retrieve $ref regproc-post-install-list] 
+	if { ${install-proc-list} != 0 } {
+	    foreach install ${install-proc-list} {
+		set install-name [lindex $install 1]
+		if {![catch {eval [string map { \\n \n } $install]} err]} {
+			ui_info "Executing ${install-name} procedure"
+			if {[catch {${install-name} $name ${version}_${revision}${variants} $name ${version} ${revision} ${variants} } err]} {
+				ui_error [format [msgcat::mc "Error executing ${install-name} procedure: %s"] $err]
+			}
+		} else {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error [format [msgcat::mc "Could not evaluate ${install-name} procedure: %s"] $err]
+		}
+	   }
+	}
+}
+
+}
+
 namespace eval portimage {
 
 variable force
@@ -108,9 +136,17 @@
 
 	set ref [registry::open_entry $name $version $revision $variants]
 	
+	# we need to call things even if not image proc - as a sub-phase of install
+	# activate for non-image we still call the pre-/post-activate
+	# - effectively we consider the main activate proc a null proc for non-image installs
+	set doimage 1
 	if { ![string equal [registry::property_retrieve $ref installtype] "image"] } {
-		return -code error "Image error: ${name} @${version}_${revision}${variants} not installed as an image."
+		#return -code error "Image error: ${name} @${version}_${revision}${variants} not installed as an image."
+		set doimage 0
 	}
+
+	if {$doimage == 1} {
+	
 	if { [registry::property_retrieve $ref active] != 0 } {
 		return -code error "Image error: ${name} @${version}_${revision}${variants} is already active."
 	} 
@@ -118,6 +154,28 @@
 		return -code error "Image error: ${name} @${version}_${revision}${variants} is compactd."
 	} 
 
+	}
+
+	# execute the pre-activate procedures
+	set activate-proc-list [registry::property_retrieve $ref regproc-pre-activate-list] 
+	if { ${activate-proc-list} != 0 } {
+	    foreach activate ${activate-proc-list} {
+		set activate-name [lindex $activate 1]
+		if {![catch {eval [string map { \\n \n } $activate]} err]} {
+			ui_info "Executing ${activate-name} procedure"
+			if {[catch {${activate-name} $name ${version}_${revision}${variants} $name ${version} ${revision} ${variants} } err]} {
+				ui_error [format [msgcat::mc "Error executing ${activate-name} procedure: %s"] $err]
+			}
+		} else {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error [format [msgcat::mc "Could not evaluate ${activate-name} procedure: %s"] $err]
+		}
+	   }
+	}
+
+	if {$doimage == 1} {
+
 	set imagedir [registry::property_retrieve $ref imagedir]
 
 	set contents [registry::property_retrieve $ref contents]
@@ -135,6 +193,33 @@
 		registry::register_file $file $name
 	}
 	registry::write_file_map
+
+	}
+
+	# execute the post-activate procedures
+	set activate-proc-list [registry::property_retrieve $ref regproc-post-activate-list] 
+	if { ${activate-proc-list} != 0 } {
+	    foreach activate ${activate-proc-list} {
+		set activate-name [lindex $activate 1]
+		if {![catch {eval [string map { \\n \n } $activate]} err]} {
+			ui_info "Executing ${activate-name} procedure"
+			if {[catch {${activate-name} $name ${version}_${revision}${variants} $name ${version} ${revision} ${variants} } err]} {
+				ui_error [format [msgcat::mc "Error executing ${activate-name} procedure: %s"] $err]
+			}
+		} else {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error [format [msgcat::mc "Could not evaluate ${activate-name} procedure: %s"] $err]
+		}
+	   }
+	}
+
+	# also execute the post-install procedures
+	# this solves image/non-image issues
+	# also going forward makes post-install the primary proc for performing
+	# actions needed after full installing files eg. starting daemons that depend on
+	# files being installed
+	portinstall::run-post-install $ref $name $version $revision $variants
 }
 
 proc deactivate {name v optionslist} {
@@ -173,9 +258,14 @@
 	
 	set ref [registry::open_entry $name $version $revision $variants]
 
+	set doimage 1
 	if { ![string equal [registry::property_retrieve $ref installtype] "image"] } {
-		return -code error "Image error: ${name} @${fqversion} not installed as an image."
+		#return -code error "Image error: ${name} @${fqversion} not installed as an image."
+		set doimage 0
 	}
+
+	if {$doimage == 1} {
+
 	if { [registry::property_retrieve $ref active] != 1 } {
 		return -code error "Image error: ${name} @${fqversion} is not active."
 	} 
@@ -183,6 +273,36 @@
 		return -code error "Image error: ${name} @${fqversion} is compactd."
 	} 
 
+	}
+
+	# execute the pre-uninstall procedures
+	# we need to do this here as now we consider deactivate a sub-phase of uninstall
+	# this solves image/non-image issues
+	# also going forward makes pre-uninstall the primary proc for performing
+	# actions needed before removing files eg. stopping daemons that depend on
+	# files that will be removed!!
+	portuninstall::run-pre-uninstall $ref $name $version $revision $variants
+
+	# execute the pre-deactivate procedures
+	set deactivate-proc-list [registry::property_retrieve $ref regproc-pre-deactivate-list] 
+	if { ${deactivate-proc-list} != 0 } {
+	    foreach deactivate ${deactivate-proc-list} {
+		set deactivate-name [lindex $deactivate 1]
+		if {![catch {eval [string map { \\n \n } $deactivate]} err]} {
+			ui_info "Executing ${deactivate-name} procedure"
+			if {[catch {${deactivate-name} $name ${version}_${revision}${variants} $name ${version} ${revision} ${variants} } err]} {
+				ui_error [format [msgcat::mc "Error executing ${deactivate-name} procedure: %s"] $err]
+			}
+		} else {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error [format [msgcat::mc "Could not evaluate ${deactivate-name} procedure: %s"] $err]
+		}
+	   }
+	}
+
+	if {$doimage == 1} {
+
 	set imagedir [registry::property_retrieve $ref imagedir]
 
 	set imagefiles [registry::port_registered $name]
@@ -199,6 +319,26 @@
 
 	registry::write_entry $ref
 
+	}
+
+	# execute the post-deactivate procedures
+	set deactivate-proc-list [registry::property_retrieve $ref regproc-post-deactivate-list] 
+	if { ${deactivate-proc-list}!= 0 } {
+	    foreach deactivate ${deactivate-proc-list} {
+		set deactivate-name [lindex $deactivate 1]
+		if {![catch {eval [string map { \\n \n } $deactivate]} err]} {
+			ui_info "Executing ${deactivate-name} procedure"
+			if {[catch {${deactivate-name} $name ${version}_${revision}${variants} $name ${version} ${revision} ${variants} } err]} {
+				ui_error [format [msgcat::mc "Error executing ${deactivate-name} procedure: %s"] $err]
+			}
+		} else {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error [format [msgcat::mc "Could not evaluate ${deactivate-name} procedure: %s"] $err]
+		}
+	   }
+	}
+
 }
 
 proc compact {name v} {
Index: base/src/port1.0/portactivate.tcl
===================================================================
--- base/src/port1.0/portactivate.tcl	(revision 135)
+++ base/src/port1.0/portactivate.tcl	(working copy)
@@ -36,20 +36,5 @@
 package provide portactivate 1.0
 package require portutil 1.0
 
-set org.macports.activate [target_new org.macports.activate activate_main]
-target_runtype ${org.macports.activate} always
-target_state ${org.macports.activate} no
-target_provides ${org.macports.activate} activate
-if {[option portarchivemode] == "yes"} {
-	target_requires ${org.macports.activate} main unarchive fetch extract checksum patch configure build destroot archive install
-} else {
-	target_requires ${org.macports.activate} main fetch extract checksum patch configure build destroot install
-}
-
 set_ui_prefix
 
-proc activate_main {args} {
-	global portname portversion portrevision portvariants user_options
-	registry_activate $portname ${portversion}_${portrevision}${portvariants} [array get user_options]
-    return 0
-}
Index: base/src/port1.0/portinstall.tcl
===================================================================
--- base/src/port1.0/portinstall.tcl	(revision 135)
+++ base/src/port1.0/portinstall.tcl	(working copy)
@@ -44,6 +44,99 @@
 }
 target_prerun ${org.macports.install} install_start
 
+
+
+# unfortunately the procutil version makeuserproc hard encodes no arguments
+# Im not sure of the utility any more of the info globals - a lot of globals are now in
+# the ::macports namespace - in particular prefix
+# name, version, revision are needed to define these original Portfile keywords
+# portname is duplicate of name but portversion is the filename used in the receipts directory
+# currently an encoding name, version and revision
+proc makeprepostproc {name body} {
+    regsub -- "^\{(.*?)" $body "\{ \n global macports::prefix \n foreach g \[info globals\] \{ \n global \$g \n \} \n \\1" body
+    eval "proc $name {portname portversion name version revision variants} $body"
+}
+
+# define procedures for understanding activate/deactivate/uninstall pre-/post- sections
+# in Portfile
+# code body initially taken from target_provides
+# the following lists should be initialised for each port
+# I think this should work as as far as I can tell each port is built through
+# a separate interpreter hence separate loads of portinstall.tcl
+namespace eval activate {
+
+set proc-pre-activate-list [list]
+set proc-post-activate-list [list]
+
+}
+
+proc pre-activate {args} {
+   global activate::proc-pre-activate-list
+   variable proc_index
+   set proc_index [llength ${proc-pre-activate-list}]
+   set ident "org.macports.activate"
+   lappend proc-pre-activate-list regproc-pre-${ident}-activate-${proc_index}
+   makeprepostproc regproc-pre-${ident}-activate-${proc_index} $args
+}
+proc post-activate {args} {
+   global activate::proc-post-activate-list
+   variable proc_index
+   set proc_index [llength ${proc-post-activate-list}]
+   set ident "org.macports.activate"
+   lappend proc-post-activate-list regproc-post-${ident}-activate-${proc_index}
+   makeprepostproc regproc-post-${ident}-activate-${proc_index} $args
+}
+
+namespace eval deactivate {
+
+set proc-pre-deactivate-list [list]
+set proc-post-deactivate-list [list]
+
+}
+
+proc pre-deactivate {args} {
+   global deactivate::proc-pre-deactivate-list
+   variable proc_index
+   set proc_index [llength ${proc-pre-deactivate-list}]
+   set ident "org.macports.deactivate"
+   lappend proc-pre-deactivate-list regproc-pre-${ident}-deactivate-${proc_index}
+   makeprepostproc regproc-pre-${ident}-deactivate-${proc_index} $args
+}
+proc post-deactivate {args} {
+   global deactivate::proc-post-deactivate-list
+   variable proc_index
+   set proc_index [llength ${proc-post-deactivate-list}]
+   set ident "org.macports.deactivate"
+   lappend proc-post-deactivate-list regproc-post-${ident}-deactivate-${proc_index}
+   makeprepostproc regproc-post-${ident}-deactivate-${proc_index} $args
+}
+
+# now the same for pre-uninstall
+# adding a post-uninstall for symmetry but not clear what the point of it would be
+
+namespace eval uninstall {
+set proc-pre-uninstall-list [list]
+set proc-post-uninstall-list [list]
+}
+
+proc pre-uninstall {args} {
+   global uninstall::proc-pre-uninstall-list
+   variable proc_index
+   set proc_index [llength ${proc-pre-uninstall-list}]
+   set ident "org.macports.uninstall"
+   lappend proc-pre-uninstall-list regproc-pre-${ident}-uninstall-${proc_index}
+   makeprepostproc regproc-pre-${ident}-uninstall-${proc_index} $args
+}
+
+proc post-uninstall {args} {
+   global uninstall::proc-post-uninstall-list
+   variable proc_index
+   set proc_index [llength ${proc-post-uninstall-list}]
+   set ident "org.macports.uninstall"
+   lappend proc-post-uninstall-list regproc-post-${ident}-uninstall-${proc_index}
+   makeprepostproc regproc-post-${ident}-uninstall-${proc_index} $args
+}
+
 set_ui_prefix
 
 proc install_start {args} {
@@ -128,8 +221,15 @@
 }
 
 proc install_main {args} {
-	global portname portversion portpath categories description long_description homepage depends_run installPlist package-install uninstall workdir worksrcdir pregrefix UI_PREFIX destroot portrevision maintainers ports_force portvariants targets depends_lib PortInfo epoch
+	global portname portversion portpath categories description long_description homepage depends_run installPlist package-install workdir worksrcdir pregrefix UI_PREFIX destroot portrevision maintainers ports_force portvariants targets depends_lib PortInfo epoch
 
+	global activate::proc-pre-activate-list
+	global activate::proc-post-activate-list
+	global deactivate::proc-pre-deactivate-list
+	global deactivate::proc-post-deactivate-list
+	global uninstall::proc-pre-uninstall-list
+	global uninstall::proc-post-uninstall-list
+
 	# Begin the registry entry
    	set regref [registry_new $portname $portversion $portrevision $portvariants $epoch]
     
@@ -164,30 +264,118 @@
 			registry_bulk_register_files [registry_fileinfo_for_index $installPlist] $portname
 		}
 	}
-	if {[info exists package-install]} {
-		registry_prop_store $regref package-install ${package-install}
+
+    if {[info exists package-install]} {
+	registry_prop_store $regref package-install ${package-install}
     }
-    if {[info proc pkg_uninstall] == "pkg_uninstall"} {
-		registry_prop_store $regref uninstall [proc_disasm pkg_uninstall]
+
+    # and yet another issue
+    # if archivemode is being used and we are restoring an older version
+    # the pre-/post- procs will be coming from the current Portfile
+    # we really need to store the pre-/post- procs with the archive
+    # and restore them here (the Portfile already is but then need to figure out
+    # how to switch to a different Portfile version)
+    # this will have to wait for another day
+    # print warning message at the moment
+    if {[option portarchivemode] == "yes"} {
+        ui_info "$UI_PREFIX [format [msgcat::mc "Warning: archivemode is using procs from current Portfile"] ]"
     }
-	
+
+    # save the current post-install section if defined
+    # - this will now be re-done if a port activate command is run
+    # note that both userproc-post-org.macports.xxx-xxx-*
+    # and proc-post-org.macports.xxx-xxx-* are define by target_provides
+    # unfortunately target_provides will have used makeuserproc which defines
+    # the procedure with no arguments - we need to have arguments
+    set temp-proc-list [post_install_munge_proc [info proc userproc-post-org.macports.install-install*]]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-post-install-list ${temp-proc-list}
+    }
+
+    # save all the other sections after install pre-/post- procs in the registry
+    # so are version specific and can be called outside the target execution system
+    # as activate/deactivate and uninstall are now
+
+    set temp-proc-list [munge_proc ${proc-pre-activate-list}]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-pre-activate-list ${temp-proc-list}
+    }
+
+    set temp-proc-list [munge_proc ${proc-post-activate-list}]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-post-activate-list ${temp-proc-list}
+    }
+
+    set temp-proc-list [munge_proc ${proc-pre-deactivate-list}]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-pre-deactivate-list ${temp-proc-list}
+    }
+
+    set temp-proc-list [munge_proc ${proc-post-deactivate-list}]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-post-deactivate-list ${temp-proc-list}
+    }
+
+    set temp-proc-list [munge_proc ${proc-pre-uninstall-list}]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-pre-uninstall-list ${temp-proc-list}
+    }
+
+    set temp-proc-list [munge_proc ${proc-post-uninstall-list}]
+    if {[llength ${temp-proc-list}] > 0} {
+	registry_prop_store $regref regproc-post-uninstall-list ${temp-proc-list}
+    }
+
 	registry_write $regref 
 
+    # also we still have the problem of post-install being run by
+    # the target phase and by the activate procedure
+    # rename the current post-install proc and define a dummy proc
+    # do this in a separate loop as should only be run during the install phase
+    set proc-post-install-list [info proc userproc-post-org.macports.install-install*]
+    if {[llength ${proc-post-install-list}] > 0} {
+        foreach oldname ${proc-post-install-list} {
+	    # we now need to redefine the procedure with new name
+	    set prcname [string map { userproc proc } $oldname ]
+	    set newname [string map { userproc nouseproc } $oldname ]
+	    rename $prcname $newname
+	    eval "proc $prcname {name} { return 0 }"
+	}
+    }
+
+	# this is the only way to solve the install/activate debacle
+	# activate is strictly a sub-phase of install
+	# - at the end of an install process most people would expect the
+	# software to be fully installed
+	# (similarly deactivate is a sub-phase of uninstall)
+	# by calling the activate function at this point
+	# (which then calls the current pre-/post-activate procs)
+	# we end up with a fully installed port after the install phase
+	# this solves the issue of non-image installations never calling
+	# activate (or deactivate) - at least with other mods to portimage.tcl
+	# note with this a post-install Portfile section is the last thing called
+	# not post-activate
+	# - but this also solves the problem of current post-activate sections
+	# as they will still be called and if no post-install section is defined
+	# they will be the last thing called
+	# (which is mainly the case at present)
+	# going forward this will mean the natural place to do actions after the
+	# port is fully installed will be in a post-install section
+
+	install_activate args
+
     return 0
 }
 
-proc proc_disasm {pname} {
-    set p "proc "
-    append p $pname " \{"
-    set space ""
-    foreach arg [info args $pname] {
-	if {[info default $pname $arg value]} {
-	    append p "$space{" [list $arg $value] "}"
-	} else {
-	    append p $space $arg
-	}
-	set space " "
-    }
-    append p "\} \{" [info body $pname] "\}"
-    return $p
+# at end of install phase activate the image if doing image installs
+
+proc install_activate {args} {
+        global portname portversion portrevision portvariants user_options
+
+	# in new implementation we always call activate - whether image or not
+	# the post-install phase is called from there
+        registry_activate $portname ${portversion}_${portrevision}${portvariants} [array get user_options]
+
+	return 0
 }
+
Index: base/src/port1.0/portutil.tcl
===================================================================
--- base/src/port1.0/portutil.tcl	(revision 135)
+++ base/src/port1.0/portutil.tcl	(working copy)
@@ -646,6 +646,57 @@
     }
 }
 
+########### Pre/Post proc functions ###########
+# procedures for converting procs for saving in registry
+# or in archive
+
+proc munge_proc {proc-list} {
+    set temp-proc-list {}
+    if {[llength ${proc-list}] > 0} {
+        foreach prename ${proc-list} {
+	    lappend temp-proc-list [proc_disasm $prename]
+        }
+    }
+    return ${temp-proc-list}
+}
+
+# special proc for post-install procs - we have to convert the proc
+# to allow for arguments 
+proc post_install_munge_proc {proc-post-install-list} {
+    set temp-proc-list {}
+    if {[llength ${proc-post-install-list}] > 0} {
+        foreach oldname ${proc-post-install-list} {
+	    # munge body 
+	    set curbody [info body $oldname]
+	    # we now need to redefine the procedure with new name
+	    set prename [string map { userproc regproc } $oldname ]
+	    if {[info proc $prename] == {}} {
+    	    	eval "proc $prename {portname portversion name version revision variants} { $curbody }"
+	    }
+	    lappend temp-proc-list [proc_disasm $prename]
+        }
+    }
+    return ${temp-proc-list}
+}
+
+# this procedure encodes the pre-/post- body so that it can be stored in the
+# the receipt file
+proc proc_disasm {pname} {
+    set p "proc "
+    append p $pname " {"
+    set space ""
+    foreach arg [info args $pname] {
+	if {[info default $pname $arg value]} {
+	    append p "$space{" [list $arg $value] "}"
+	} else {
+	    append p $space $arg
+	}
+	set space " "
+    }
+    append p "} {" [string map { \n \\n } [info body $pname] ] " }"
+    return $p
+}
+
 ########### Environment utility functions ###########
 
 # Parse the environment string of a command, storing the values into the
Index: base/src/macports1.0/macports.tcl
===================================================================
--- base/src/macports1.0/macports.tcl	(revision 135)
+++ base/src/macports1.0/macports.tcl	(working copy)
@@ -1187,15 +1187,23 @@
 ### _mportinstalled is private; may change without notice
 
 # Determine if a port is already *installed*, as in "in the registry".
+# fix this up so that if image install we check if port is active
+# as far as I can see everywhere _mportinstalled is called is preceded by the check
+# for image installs and if image then _mportactive is called
+# this brings this into line with the concept activate is sub-phase of install
 proc _mportinstalled {mport} {
-    # Check for the presense of the port in the registry
-    set workername [ditem_key $mport workername]
-    set res [$workername eval registry_exists \${portname} \${portversion}]
-    if {$res != 0} {
-        ui_debug "[ditem_key $mport provides] is installed"
-        return 1
+    if { [string equal ${macports::registry.installtype} "image"] } {
+       return [_mportactive $mport]
     } else {
-        return 0
+        # Check for the presense of the port in the registry
+        set workername [ditem_key $mport workername]
+        set res [$workername eval registry_exists \${portname} \${portversion}]
+        if {$res != 0} {
+            ui_debug "[ditem_key $mport provides] is installed"
+            return 1
+        } else {
+            return 0
+        }
     }
 }
 
@@ -1219,11 +1227,7 @@
 # depspec   the dependency test specification (path, bin, lib, etc.)
 proc _mportispresent {mport depspec} {
     ui_debug "Searching for dependency: [ditem_key $mport provides]"
-    if {[string equal ${macports::registry.installtype} "image"]} {
-        set res [_mportactive $mport]
-    } else {
-        set res [_mportinstalled $mport]
-    }
+    set res [_mportinstalled $mport]
     if {$res != 0} {
         ui_debug "Found Dependency: receipt exists for [ditem_key $mport provides]"
         return 1
@@ -1310,14 +1314,8 @@
         dlist_delete dlist $mport
 
         # install them
-        # xxx: as with below, this is ugly.  and deps need to be fixed to
-        # understand Port Images before this can get prettier
-        if { [string equal ${macports::registry.installtype} "image"] } {
-            set result [dlist_eval $dlist _mportactive [list _mportexec "activate"]]
-        } else {
-            set result [dlist_eval $dlist _mportinstalled [list _mportexec "install"]]
-        }
-        
+	set result [dlist_eval $dlist _mportinstalled [list _mportexec "install"]]
+
         if {$result != {}} {
             set errstring "The following dependencies failed to build:"
             foreach ditem $result {
@@ -1339,12 +1337,6 @@
         set clean 1
     }
 
-    # If we're doing image installs, then we should activate after install
-    # xxx: This isn't pretty
-    if { [string equal ${macports::registry.installtype} "image"] && [string equal $target "install"] } {
-        set target activate
-    }
-    
     # Build this port with the specified target
     set result [$workername eval eval_targets $target]
 
