github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/third_party/update.pl (about)

     1  #!/usr/bin/perl
     2  
     3  use strict;
     4  use FindBin qw($Bin);
     5  
     6  die "TODO(bradfitz): update.";
     7  
     8  chdir($Bin) or die;
     9  
    10  my $workdir = "$Bin/workdir";
    11  unless (-d $workdir) { 
    12      mkdir $workdir, 0755 or die;
    13  }
    14  
    15  my %proj = (
    16      "fuse" => {
    17          git => "https://github.com/hanwen/go-fuse.git",
    18          copies => [
    19              # File glob => target directory
    20              [ "fuse/*.go", "github.com/hanwen/go-fuse/fuse" ]
    21          ],
    22      },
    23      "mysqlfork" => {
    24          git => "https://github.com/camlistore/GoMySQL.git",
    25          copies => [
    26              # File glob => target directory
    27              [ "*.go", "github.com/camlistore/GoMySQL" ]
    28          ],
    29      },
    30      "goauth" => {
    31          hg => "https://code.google.com/p/goauth2/",
    32          copies => [
    33              # File glob => target directory
    34              [ "oauth/*.go", "code.google.com/goauth2/oauth" ]
    35          ],
    36      },
    37      "gomemcache" => {
    38          git => "https://github.com/bradfitz/gomemcache/",
    39          copies => [
    40              # File glob => target directory
    41              [ "*.go", "github.com/bradfitz/gomemcache" ]
    42          ],
    43      },
    44      "flickr" => {
    45          git => "https://github.com/mncaudill/go-flickr.git",
    46          copies => [
    47              # File glob => target directory
    48              [ "*", "github.com/mncaudill/go-flickr" ]
    49          ],
    50      },
    51  );
    52  
    53  # Copies the file globs specified by a project 'copies' value.
    54  sub copy_files {
    55    my $name = shift;
    56    my $p = $proj{$name};
    57    for my $cp (@{$p->{copies}}) {
    58        my $glob = $cp->[0] or die;
    59        my $target_dir = $cp->[1] or die;
    60        system("mkdir", "-p", "$Bin/$target_dir") and die "Failed to make $Bin/$target_dir";
    61        my @files = glob($glob) or die "Glob '$glob' didn't match any files for project '$name'";
    62        system("cp", "-p", @files, "$Bin/$target_dir") and die "Copy failed.";
    63    }
    64  }
    65  
    66  # Fetches most recent project sources from git
    67  sub update_git {
    68    my $name = shift;
    69    my $p = $proj{$name};
    70  
    71    chdir($workdir) or die;
    72    unless (-d $name) {
    73      print STDERR "Cloning $name ...\n";
    74      system("git", "clone", $p->{git}, $name) and die "git clone failure";
    75    }
    76  
    77    chdir($name) or die;
    78    print STDERR "Updating $name ...\n";
    79    system("git", "pull");
    80    copy_files($name);
    81  }
    82  
    83  # Fetches most recent project sources from mercurial
    84  sub update_hg {
    85    my $name = shift;
    86    my $p = $proj{$name};
    87  
    88    chdir($workdir) or die;
    89    unless (-d $name) {
    90      print STDERR "Cloning $name ...\n";
    91      system("hg", "clone", $p->{hg}, $name) and die "hg clone failure";
    92    }
    93  
    94    chdir($name) or die;
    95    print STDERR "Updating $name ...\n";
    96    system("hg", "pull");
    97    system("hg", "update");
    98    copy_files($name);
    99  }
   100  
   101  foreach my $name (sort keys %proj) {
   102      next if @ARGV && $name !~ /\Q$ARGV[0]\E/;
   103      my $p = $proj{$name};
   104  
   105      if ($p->{git}) {
   106        update_git($name);
   107      } elsif ($p->{hg}) {
   108        update_hg($name);
   109      } else {
   110        die "No known VCS defined for $name";
   111      }
   112  }
   113