Changeset 12 for shepherd

Show
Ignore:
Timestamp:
10/04/06 17:37:10 (7 years ago)
Author:
lincoln
Message:

--mirror support added with fallback to whuffy if all mirrors are down

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • shepherd

    r11 r12  
    2323# 
    2424# ToDo: 
    25 # * --mirror <url> option, to let you get software from somewhere other 
    26 #   than whuffy. Store this in shepherd.conf. Whuffy is merely the first 
    27 #   mirror. 
    2825# * Make it check compilation after installing by calling --version or 
    2926#   --desc or --ready 
     
    5047 
    5148my $HOME = 'http://www.whuffy.com'; 
    52 my $STATUS = "$HOME/status"; 
    5349 
    5450my $invoked = Cwd::realpath($0); 
     
    7167my $opt; 
    7268my $pref_order; 
     69my $mirror_site; 
    7370my $made_changes = 0; 
    7471my $debug = 1; 
     
    138135&check() if ($opt->{check}); 
    139136 
    140 if ($opt->{enable} or $opt->{disable} or $opt->{setorder} or $opt->{check}) 
     137if ($opt->{enable} or $opt->{disable} or $opt->{setorder} or $opt->{check} or $opt->{mirror}) 
    141138{ 
    142139    set_order(1) if $made_changes; 
     
    539536    printf "\nChecking for updates:\n\n"; 
    540537 
    541     print "Fetching status file: $STATUS."; 
    542     my $data = LWP::Simple::get($STATUS); 
    543     unless ($data) 
    544     { 
    545         print "Failed to retrieve status file.\n"; 
    546         return; 
    547     } 
     538    my $data; 
     539    my $sites = ""; 
     540    $sites = "$mirror_site," if ($mirror_site); 
     541    $sites .= $HOME; 
     542 
     543    foreach my $site (split(/,/,$sites)) { 
     544        my $url = $site . "/status"; 
     545        print "Fetching status file: $url.\n"; 
     546        $data = LWP::Simple::get($url); 
     547        last if $data; 
     548 
     549        print "Failed to retrieve status file from $url.\n"; 
     550    } 
     551    return if (!$data); 
    548552 
    549553    my %glist = %$grabbers; 
     
    635639    print "Downloading $proggy v$latestversion.\n"; 
    636640 
    637     my $rdir = $HOME; 
     641    my $sites = ""; 
     642    $sites = "$mirror_site," if ($mirror_site); 
     643    $sites .= $HOME; 
     644 
     645    my $rdir = ""; 
    638646    my $ldir = $CWD; 
    639     my $ver = "unkown"; 
     647    my $ver = "unknown"; 
    640648 
    641649    if (($proggy eq $progname) && ($progtype eq "shepherd")) { 
    642         $rdir = $HOME; 
    643         $ldir = $CWD; 
    644650        $ver = $version; 
    645651    } elsif ($progtype eq "grabber") { 
    646         $rdir = $HOME . "/grabbers"; 
     652        $rdir = "grabbers"; 
    647653        $ldir = "$GRABBER_DIR/$proggy"; 
    648654        $ver = $grabbers->{$proggy}->{ver} if ((defined $grabbers->{$proggy}) && $grabbers->{$proggy}->{ver}); 
    649655        -d $GRABBER_DIR or mkdir $GRABBER_DIR or die "Cannot create directory $GRABBER_DIR: $!"; 
    650656    } elsif ($progtype eq "postprocessor") { 
    651         $rdir = $HOME . "/postprocessors"; 
     657        $rdir = "postprocessors"; 
    652658        $ldir = "$POSTPROCESSOR_DIR/$proggy"; 
    653659        $ver = $postprocessors->{$proggy}->{ver} if ((defined $postprocessors->{$proggy}) && $postprocessors->{$proggy}->{ver}); 
     
    660666 
    661667    my $newfile = "$ldir/$proggy-$latestversion"; 
    662     my $rc = LWP::Simple::getstore("$rdir/$proggy-$latestversion", $newfile); 
    663  
    664     unless (is_success($rc)) 
    665     { 
    666         print "Failed to retrieve $rdir/$proggy-$latestversion.\n"; 
    667         return; 
    668     } 
     668    my $rc; 
     669 
     670    foreach my $site (split(/,/,$sites)) { 
     671        printf "Fetching $site/$rdir/$proggy-$latestversion.\n"; 
     672        $rc = LWP::Simple::getstore("$site/$rdir/$proggy-$latestversion", $newfile); 
     673        last if (is_success($rc)); 
     674 
     675        print "Failed to retrieve $site/$rdir/$proggy-$latestversion.\n"; 
     676    } 
     677    return if (!is_success($rc)); 
    669678 
    670679    # Make it executable 
     
    835844        &set_order(1); 
    836845    } 
     846 
     847    # if a mirror has been specified, add it into our config 
     848    if ($opt->{mirror}) { 
     849        $mirror_site = $opt->{mirror}; 
     850        $made_changes = 1; 
     851        print "Adding mirror: $mirror_site\n"; 
     852    } 
    837853} 
    838854 
     
    872888    open(CONF, ">$config_file") or die "cannot write to $config_file: $!"; 
    873889    print CONF Data::Dumper->Dump( 
    874         [$region,  $pref_order,  $grabbers, $postprocessors  ], 
    875         ["region", "pref_order", "grabbers", "postprocessors" ]); 
     890        [$region,  $pref_order,  $mirror_site, $grabbers, $postprocessors  ], 
     891        ["region", "pref_order", "mirror_site", "grabbers", "postprocessors" ]); 
    876892    close CONF; 
    877893    print "\nUpdated configuration file $config_file.\n" if ($debug); 
     
    892908              'configure'       => \$opt->{configure}, 
    893909              'output'          => \$opt->{output}, 
     910              'mirror=s'        => \$opt->{mirror}, 
    894911              'debug'           => \$debug); 
    895912} 
     
    11011118    --status              Print a list of grabbers maintained 
    11021119    --list                Print a detailed list of grabbers 
     1120    --mirror <s>          Set URL <s> as primary location to check for updates 
    11031121 
    11041122    --configure           Setup