[32394] trunk/base/src/macports1.0/macports.tcl

jmpp at macports.org jmpp at macports.org
Fri Dec 28 20:43:51 PST 2007


Revision: 32394
          http://trac.macosforge.org/projects/macports/changeset/32394
Author:   jmpp at macports.org
Date:     2007-12-28 20:43:49 -0800 (Fri, 28 Dec 2007)

Log Message:
-----------

A thoroughly rewritten selfupdate proc:

 * steps now happen in a more logical order: first we sync the ports tree, then the base sources, then see if we're being forced
   or if we're using version numbers to discern upgrading or not and, lastly, we rebuild accordingly;
 * the above reordering allows us to force the selfupdate to get around no rsync'd version file being found for whatever reason;
   previously such event would lead to a situation in which not even forcing would help, affected users had to grab the dmg or
   rebuild from source manually;
 * in case we're not being forced, choose between two rsync'd version files: the old, floating point format (mp_version) or the new,
   real version number format (macports_version); we're still using the old one (cf. r32364), but when we release something like 2.0.0
   we'll switch to the new one;
 * improved MacPorts installation owner detection and setting upon reinstallation: we now read ${prefix}'s attributes;
 * ${prefix} permissions are now also preserved across selfupdates (REMINDER: this should be a NEWS & ChangeLog entry);
 * renamed some variables to clearer names;
 * improved many informational and debug messages and in-source comments.

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2007-12-28 23:44:58 UTC (rev 32393)
+++ trunk/base/src/macports1.0/macports.tcl	2007-12-29 04:43:49 UTC (rev 32394)
@@ -1622,92 +1622,93 @@
 
 # selfupdate procedure
 proc macports::selfupdate {{optionslist {}}} {
-    global macports::prefix macports::portdbpath macports::rsync_server macports::rsync_dir macports::rsync_options
+    global macports::prefix macports::portdbpath macports::libpath macports::rsync_server macports::rsync_dir macports::rsync_options
     global macports::autoconf::macports_version macports::autoconf::rsync_path
     array set options $optionslist
     
-    if { [info exists options(ports_force)] && $options(ports_force) == "yes" } {
-        set use_the_force_luke yes
-        ui_debug "Forcing a rebuild of the MacPorts base system."
-    } else {
-        set use_the_force_luke no
-        ui_debug "Rebuilding the MacPorts base system if needed."
-    }
-    # syncing ports tree. We expect the user have rsync:// in the sources.conf
+    # syncing ports tree.
     if {[catch {mportsync} result]} {
         return -code error "Couldn't sync the ports tree: $result"
     }
-
+    
+    # create the path to the to be downloaded sources if it doesn't exist
     set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}/]
     if {![file exists $mp_source_path]} {
         file mkdir $mp_source_path
     }
-    ui_debug "MacPorts sources dir: $mp_source_path"
+    ui_debug "MacPorts sources location: $mp_source_path"
+    
+    # sync the MacPorts sources
+    ui_debug "Updating MacPorts sources using rsync"
+    if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir} $mp_source_path" } result ] } {
+       return -code error "Error synchronizing MacPorts sources: $result"
+    }
 
-    # get user of the MacPorts system
-    set user [file attributes [file join $portdbpath sources/] -owner]
-    ui_debug "Setting user: $user"
-
-    # echo MacPorts version
+    # echo current MacPorts version
     ui_msg "\nMacPorts base version $macports::autoconf::macports_version installed"
 
-    ui_debug "Updating using rsync"
-    if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir} $mp_source_path" } ] } {
-        return -code error "Error: rsync failed in selfupdate"
+    if { [info exists options(ports_force)] && $options(ports_force) == "yes" } {
+        set use_the_force_luke yes
+        ui_debug "Forcing a rebuild and reinstallation of MacPorts"
+    } else {
+        set use_the_force_luke no
+        ui_debug "Rebuilding and reinstalling MacPorts if needed"
+        # Choose what version file to use: old, floating point format or new, real version number format
+        set old_version_file [file join $mp_source_path config mp_version]
+        set new_version_file [file join $mp_source_path config macports_version]
+        if {[file exists $old_version_file]} {
+            set fd [open $old_version_file r]
+        } elseif {[file exists $new_version_file]} {
+            set fd [open $new_version_file r]
+        }
+        # get downloaded MacPorts version
+        gets $fd macports_version_new
+        close $fd
+        # echo downloaded MacPorts version
+        ui_msg "\nDownloaded MacPorts base version $macports_version_new"
     }
 
-    # get downloaded MacPorts version
-    set fd [open [file join $mp_source_path config mp_version] r]
-    gets $fd macports_version_new
-    close $fd
-    ui_msg "\nDownloaded MacPorts base version $macports_version_new"
-
     # check if we we need to rebuild base
     if {[rpm-vercomp $macports_version_new $macports::autoconf::macports_version] > 0 || $use_the_force_luke == "yes"} {
-        ui_msg "Configuring, Building and Installing new MacPorts base"
-        # check if $prefix/bin/port is writable, if so we go !
-        # get installation user / group 
-        set owner root
-        set group admin
-        set portprog [file join $prefix bin port]
-        if {[file exists $portprog ]} {
-            # set owner
-            set owner [file attributes $portprog -owner]
-            # set group
-            set group [file attributes $portprog -group]
-        }
-        set p_user [exec /usr/bin/whoami]
-        if {[file writable $portprog] || [string equal $p_user $owner] } {
-            ui_debug "permissions OK"
+        ui_msg "\nConfiguring, building and installing new MacPorts release"
+        # get installation user/group and permissions
+        set owner [file attributes ${prefix} -owner]
+        set group [file attributes ${prefix} -group]
+        set perms [file attributes ${prefix} -permissions]
+        set installing_user [exec /usr/bin/whoami]
+        if {[string equal $installing_user $owner]} {
+            ui_debug "Permissions OK"
         } else {
-            return -code error "Error: $p_user cannot write to ${prefix}/bin - try using sudo"
+            return -code error "Error: $installing_user cannot write to ${prefix} - try using sudo"
         }
-        ui_debug "Setting owner: $owner group: $group"
+        ui_debug "Setting owner: $owner; group: $group"
 
+        # where to install our macports1.0 tcl package
         set mp_tclpackage_path [file join $portdbpath .tclpackage]
         if { [file exists $mp_tclpackage_path]} {
             set fd [open $mp_tclpackage_path r]
             gets $fd tclpackage
             close $fd
         } else {
-            set tclpackage [file join ${prefix} share macports Tcl]
+            set tclpackage $libpath
         }
-        # do the actual installation of new base
-        ui_debug "Install in: $prefix as $owner : $group - TCL-PACKAGE in $tclpackage"
-        if { [catch { system "cd $mp_source_path && ./configure --prefix=$prefix --with-install-user=$owner --with-install-group=$group --with-tclpackage=$tclpackage && make && make install" } result] } {
+        
+        # do the actual configure, build and installation of new base
+        ui_debug "Install new MacPorts release in $prefix as $owner:$group - TCL-PACKAGE in $tclpackage; permissions: $perms"
+        if { [catch { system "cd $mp_source_path && ./configure --prefix=$prefix --with-tclpackage=$tclpackage --with-install-user=$owner --with-install-group=$group --with-directory-mode=$perms && make && make install" } result] } {
             return -code error "Error installing new MacPorts base: $result"
         }
     } else {
-        ui_msg "\nThe MacPorts installation is not outdated and so was not updated"
+        ui_msg "\nThe MacPorts installation is not outdated so it was not updated"
     }
 
-    # set the macports system to the right owner 
-    ui_debug "Setting ownership to $user"
-    if { [catch { exec chown -R $user [file join $portdbpath sources/] } result] } {
-        return -code error "Couldn't change permissions: $result"
+    # set the MacPorts sources to the right owner
+    set sources_owner [file attributes [file join $portdbpath sources/] -owner]
+    ui_debug "Setting MacPorts sources ownership to $sources_owner"
+    if { [catch { exec chown -R $sources_owner [file join $portdbpath sources/] } result] } {
+        return -code error "Couldn't change permissions of the MacPorts sources at $mp_source_path to $sources_owner: $result"
     }
 
-    # set the right version
     ui_msg "selfupdate done!"
 
     return 0
@@ -1715,9 +1716,7 @@
 
 proc macports::version {} {
     global macports::autoconf::macports_version
-    
     return $macports::autoconf::macports_version
-
 }
 
 # upgrade procedure

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20071228/380472a5/attachment.html


More information about the macports-changes mailing list