Changeset 146885


Ignore:
Timestamp:
Mar 19, 2016, 2:49:40 PM (3 years ago)
Author:
raimue@…
Message:

Move selfupdate code into separate file

Location:
trunk/base/src/macports1.0
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/macports1.0/Makefile.in

    r141366 r146885  
    55
    66SRCS=           macports.tcl macports_dlist.tcl macports_util.tcl \
    7                 macports_autoconf.tcl diagnose.tcl reclaim.tcl
     7                macports_autoconf.tcl diagnose.tcl reclaim.tcl selfupdate.tcl
    88OBJS=           macports.o get_systemconfiguration_proxies.o sysctl.o
    99SHLIB_NAME=     MacPorts${SHLIB_SUFFIX}
  • trunk/base/src/macports1.0/macports.tcl

    r146738 r146885  
    3939package require diagnose 1.0
    4040package require reclaim 1.0
     41package require selfupdate 1.0
    4142package require Tclx
    4243
     
    35453546# selfupdate procedure
    35463547proc macports::selfupdate {{optionslist {}} {updatestatusvar {}}} {
    3547     global macports::prefix macports::portdbpath macports::rsync_server macports::rsync_dir \
    3548            macports::rsync_options macports::autoconf::macports_version \
    3549            macports::autoconf::rsync_path tcl_platform macports::autoconf::openssl_path \
    3550            macports::autoconf::tar_path
    3551     array set options $optionslist
    3552 
    3553     # variable that indicates whether we actually updated base
    3554     if {$updatestatusvar ne ""} {
    3555         upvar $updatestatusvar updatestatus
    3556         set updatestatus no
    3557     }
    3558 
    3559     # are we syncing a tarball? (implies detached signature)
    3560     set is_tarball 0
    3561     if {[string range $rsync_dir end-3 end] eq ".tar"} {
    3562         set is_tarball 1
    3563         set mp_source_path [file join $portdbpath sources $rsync_server [file dirname $rsync_dir]]
    3564     } else {
    3565         if {[string index $rsync_dir end] ne "/"} {
    3566             append rsync_dir /
    3567         }
    3568         set mp_source_path [file join $portdbpath sources $rsync_server $rsync_dir]
    3569     }
    3570     # create the path to the to be downloaded sources if it doesn't exist
    3571     if {![file exists $mp_source_path]} {
    3572         file mkdir $mp_source_path
    3573     }
    3574     ui_debug "MacPorts sources location: $mp_source_path"
    3575 
    3576     # sync the MacPorts sources
    3577     ui_msg "$macports::ui_prefix Updating MacPorts base sources using rsync"
    3578     try -pass_signal {
    3579         system "$rsync_path $rsync_options rsync://${rsync_server}/$rsync_dir $mp_source_path"
    3580     } catch {{*} eCode eMessage} {
    3581         return -code error "Error synchronizing MacPorts sources: $eMessage"
    3582     }
    3583 
    3584     if {$is_tarball} {
    3585         # verify signature for tarball
    3586         global macports::archivefetch_pubkeys
    3587         try -pass_signal {
    3588             system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir}.rmd160 $mp_source_path"
    3589         } catch {{*} eCode eMessage} {
    3590             return -code error "Error synchronizing MacPorts source signature: $eMessage"
    3591         }
    3592         set openssl [findBinary openssl $macports::autoconf::openssl_path]
    3593         set tarball ${mp_source_path}/[file tail $rsync_dir]
    3594         set signature ${tarball}.rmd160
    3595         set verified 0
    3596         foreach pubkey $macports::archivefetch_pubkeys {
    3597             try -pass_signal {
    3598                 exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball
    3599                 set verified 1
    3600                 ui_debug "successful verification with key $pubkey"
    3601                 break
    3602             }  catch {{*} eCode eMessage} {
    3603                 ui_debug "failed verification with key $pubkey"
    3604                 ui_debug "openssl output: $eMessage"
    3605             }
    3606         }
    3607         if {!$verified} {
    3608             return -code error "Failed to verify signature for MacPorts source!"
    3609         }
    3610 
    3611         # extract tarball and move into place
    3612         set tar [macports::findBinary tar $macports::autoconf::tar_path]
    3613         file mkdir ${mp_source_path}/tmp
    3614         set tar_cmd "$tar -C ${mp_source_path}/tmp -xf $tarball"
    3615         try -pass_signal {
    3616             system $tar_cmd
    3617         } catch {*} {
    3618             return -code error "Failed to extract MacPorts sources from tarball!"
    3619         }
    3620         file delete -force ${mp_source_path}/base
    3621         file rename ${mp_source_path}/tmp/base ${mp_source_path}/base
    3622         file delete -force ${mp_source_path}/tmp
    3623         # set the final extracted source path
    3624         set mp_source_path ${mp_source_path}/base
    3625     }
    3626 
    3627     # echo current MacPorts version
    3628     ui_msg "MacPorts base version $macports::autoconf::macports_version installed,"
    3629 
    3630     if {[info exists options(ports_force)] && $options(ports_force)} {
    3631         set use_the_force_luke yes
    3632         ui_debug "Forcing a rebuild and reinstallation of MacPorts"
    3633     } else {
    3634         set use_the_force_luke no
    3635         ui_debug "Rebuilding and reinstalling MacPorts if needed"
    3636     }
    3637 
    3638     # Choose what version file to use: old, floating point format or new, real version number format
    3639     set version_file [file join $mp_source_path config macports_version]
    3640     if {[file exists $version_file]} {
    3641         set fd [open $version_file r]
    3642         gets $fd macports_version_new
    3643         close $fd
    3644         # echo downloaded MacPorts version
    3645         ui_msg "MacPorts base version $macports_version_new downloaded."
    3646     } else {
    3647         ui_warn "No version file found, please rerun selfupdate."
    3648         set macports_version_new 0
    3649     }
    3650 
    3651     # check if we we need to rebuild base
    3652     set comp [vercmp $macports_version_new $macports::autoconf::macports_version]
    3653 
    3654     # syncing ports tree.
    3655     if {![info exists options(ports_selfupdate_nosync)] || !$options(ports_selfupdate_nosync)} {
    3656         if {$comp > 0} {
    3657             # updated portfiles potentially need new base to parse - tell sync to try to
    3658             # use prefabricated PortIndex files and signal if it couldn't
    3659             lappend optionslist no_reindex 1 needed_portindex_var needed_portindex
    3660         }
    3661         try {
    3662             mportsync $optionslist
    3663         }  catch {{*} eCode eMessage} {
    3664             return -code error "Couldn't sync the ports tree: $eMessage"
    3665         }
    3666     }
    3667 
    3668     if {$use_the_force_luke || $comp > 0} {
    3669         if {[info exists options(ports_dryrun)] && $options(ports_dryrun)} {
    3670             ui_msg "$macports::ui_prefix MacPorts base is outdated, selfupdate would install $macports_version_new (dry run)"
    3671         } else {
    3672             ui_msg "$macports::ui_prefix MacPorts base is outdated, installing new version $macports_version_new"
    3673 
    3674             # get installation user/group and permissions
    3675             set owner [file attributes $prefix -owner]
    3676             set group [file attributes $prefix -group]
    3677             set perms [string range [file attributes $prefix -permissions] end-3 end]
    3678             if {$tcl_platform(user) ne "root" && $tcl_platform(user) ne $owner} {
    3679                 return -code error "User $tcl_platform(user) does not own $prefix - try using sudo"
    3680             }
    3681             ui_debug "Permissions OK"
    3682 
    3683             set configure_args "--prefix=[macports::shellescape $prefix] --with-install-user=[macports::shellescape $owner] --with-install-group=[macports::shellescape $group] --with-directory-mode=[macports::shellescape $perms]"
    3684             # too many users have an incompatible readline in /usr/local, see ticket #10651
    3685             if {$tcl_platform(os) ne "Darwin" || $prefix eq "/usr/local"
    3686                 || ([glob -nocomplain /usr/local/lib/lib{readline,history}*] eq "" && [glob -nocomplain /usr/local/include/readline/*.h] eq "")} {
    3687                 append configure_args " --enable-readline"
    3688             } else {
    3689                 ui_warn "Disabling readline support due to readline in /usr/local"
    3690             }
    3691 
    3692             if {$prefix eq "/usr/local" || $prefix eq "/usr"} {
    3693                 append configure_args " --with-unsupported-prefix"
    3694             }
    3695 
    3696             # Choose a sane compiler
    3697             set cc_arg {}
    3698             if {$::macports::os_platform eq "darwin"} {
    3699                 set cc_arg "CC=/usr/bin/cc OBJC=/usr/bin/cc "
    3700             }
    3701 
    3702             # do the actual configure, build and installation of new base
    3703             ui_msg "Installing new MacPorts release in $prefix as ${owner}:${group}; permissions ${perms}\n"
    3704             try {
    3705                 system -W $mp_source_path "${cc_arg}./configure $configure_args && make SELFUPDATING=1 && make install SELFUPDATING=1"
    3706             } catch {{*} eCode eMessage} {
    3707                 return -code error "Error installing new MacPorts base: $eMessage"
    3708             }
    3709             if {[info exists updatestatus]} {
    3710                 set updatestatus yes
    3711             }
    3712         }
    3713     } elseif {$comp < 0} {
    3714         ui_msg "$macports::ui_prefix MacPorts base is probably trunk or a release candidate"
    3715     } else {
    3716         ui_msg "$macports::ui_prefix MacPorts base is already the latest version"
    3717     }
    3718 
    3719     # set the MacPorts sources to the right owner
    3720     set sources_owner [file attributes [file join $portdbpath sources/] -owner]
    3721     ui_debug "Setting MacPorts sources ownership to $sources_owner"
    3722     try {
    3723         exec [findBinary chown $macports::autoconf::chown_path] -R $sources_owner [file join $portdbpath sources/]
    3724     }  catch {{*} eCode eMessage} {
    3725         return -code error "Couldn't change permissions of the MacPorts sources at $mp_source_path to ${sources_owner}: $eMessage"
    3726     }
    3727 
    3728     if {![info exists options(ports_selfupdate_nosync)] || !$options(ports_selfupdate_nosync)} {
    3729         if {[info exists needed_portindex]} {
    3730             ui_msg "Not all sources could be fully synced using the old version of MacPorts."
    3731             ui_msg "Please run selfupdate again now that MacPorts base has been updated."
    3732         } else {
    3733             ui_msg "\nThe ports tree has been updated. To upgrade your installed ports, you should run"
    3734             ui_msg "  port upgrade outdated"
    3735         }
    3736     }
    3737 
    3738     return 0
     3548    return [uplevel [list selfupdate::main $optionslist $updatestatusvar]]
    37393549}
    37403550
Note: See TracChangeset for help on using the changeset viewer.