-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-files.pl
executable file
·182 lines (140 loc) · 3.52 KB
/
get-files.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env perl
use Cwd;
use strict;
use warnings;
our @types = qw/cvs svn curl tgz zip bzr_tgz git/;
open SOURCES, "<sources" or die $!;
our $update = 0;
if ($#::ARGV == 0) {
$update = $::ARGV[0] eq "--update";
}
while (<SOURCES>) {
next if /^\s*\#|^\s*$/;
chomp;
my ($dir, $type, @arguments) = split(/\|/, $_);
print "$dir:$type:";
if (not grep /$type/, @types) {
print "Source type not recognized: $type\n";
next;
}
if ($#ARGV < 0 or grep(/$dir/, @ARGV)) {
print "updating\n";
# Hack. Use dispatch table
&{\&$type}($dir, @arguments);
} elsif ($update) {
if ($type eq "tgz" or $type eq "zip" or $type eq "curl") {
print "skipped\n";
next;
}
print "updating\n";
# Hack. Use dispatch table
&{\&$type}($dir, @arguments)
} else { print "skipped\n"; }
}
sub cvs ($$$$) {
my ($dir, $root, $module, $tag, $tagArg);
$dir = shift, $root = shift, $module = shift, $tag = shift;
if ($tag eq "") {
$tagArg = "";
} else {
$tagArg = "-r$tag";
}
if ($update) {
my $cmd = "cvs -d$root co $tagArg $module";
print "$cmd\n";
open CMD, "$cmd|";
print while (<CMD>);
return;
}
if (-e $dir) {
my $old_dir = getcwd;
# Maybe update
} else {
my $cmd = "cvs -d$root co $tagArg $module";
print "$cmd\n";
open CMD, "$cmd|";
print while (<CMD>);
}
}
sub svn ($$) {
my ($dir, $repo);
$dir = shift, $repo = shift;
if ($update) {
my $cmd = "svn $dir";
open CMD, "$cmd|";
print while (<CMD>);
return;
}
if (-e $dir) {
my $old_dir = getcwd;
# Maybe update
} else {
my $cmd = "svn co $repo $dir";
open CMD, "$cmd|";
print while (<CMD>);
}
}
sub curl($$) {
my ($file, $url);
$file = shift, $url = shift;
return if (-e $file);
system("mkdir -p `dirname $file`");
open CURL, "curl -o '$file' '$url'|";
print while (<CURL>);
}
sub tgz ($$$) {
my ($dir, $url, $res);
$dir = shift, $url = shift, $res = shift;
return if (-e $dir);
print "Downloading from: $url\n";
open CURL, "curl '$url' | tar xvzf -|";
print while (<CURL>);
`mv "$res" "$dir"` unless ($res eq "");
}
sub zip ($$$) {
my ($dir, $url, $res);
$dir = shift, $url = shift, $res = shift;
return if (-e $dir);
my $tmpf = "tmp.zip";
print "Downloading from: $url\n";
open CURL, "curl '$url' -o $tmpf|";
print while (<CURL>);
open UNZIP, "unzip $tmpf|";
print while (<UNZIP>);
`rm $tmpf`;
`mv "$res" "$dir"` unless ($res eq "");
}
sub bzr_tgz ($$$$) {
my ($dir, $bzr_url, $tgz_url, $res);
$dir = shift, $bzr_url = shift, $tgz_url = shift, $res = shift;
if ($update) {
my $cmd = "bzr update $dir";
open CMD, "$cmd|";
print while (<CMD>);
return;
}
return if (-e $dir);
open BZR, "bzr get $bzr_url $dir |";
print while (<BZR>);
close BZR;
unless ($? == 0) {
system("rm -rf $dir");
tgz($dir, $tgz_url, $res);
}
}
sub git ($$$$) {
my ($dir, $git_url);
$dir = shift, $git_url = shift;
if ($update) {
open GIT, "cd $dir && git pull |";
print while (<GIT>);
close GIT;
return;
}
return if (-e $dir); # Update?
open GIT, "git clone $git_url $dir |";
print while (<GIT>);
close GIT;
}
print "\n";
print "Done!\n";