-
Notifications
You must be signed in to change notification settings - Fork 16
/
rules-archive.pl
executable file
·83 lines (78 loc) · 2.13 KB
/
rules-archive.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
#!/usr/bin/perl
use strict;
my $head = "download:";
my $output;
open ( RULES, $ARGV[0] ) or die;
while ( <RULES> )
{
chomp;
if ( ! m/^#/ and ! m/^\s*$/ )
{
@_ = split ( /;/, $_ );
my $file = $_[0];
my $url = $_[1];
$head .= " \$(archivedir)/" . $file;
$output .= "\$(archivedir)/" . $file . ":\n\tfalse || ";
$output .= "mkdir -p \$(archivedir) && ( \\\n\t";
if ( $url =~ m#^ftp://# )
{
$output .= "wget -c --passive-ftp -P \$(archivedir) " . $url . "/" . $file . " || \\\n\t";
}
elsif ( $url =~ m#^http://# )
{
$output .= "wget -t 2 -T 10 -c -P \$(archivedir) " . $url . "/" . $file . " || \\\n\t";
}
elsif ( $url =~ m#^https://# )
{
$output .= "wget -t 2 -T 10 -c -P \$(archivedir) " . $url . "/" . $file . " || \\\n\t";
}
elsif ( $url =~ m#^cvs://# )
{
$output .= "cvs checkout ";
if ( @_ > 2 )
{
my $revision = $_[2];
$output .= "-r " . $revision . " ";
}
$output .= $url ." \$(archivedir)/" . $file . " || \\\n\t";
}
elsif ( $url =~ m#^svn://# )
{
$output .= "svn checkout ";
if ( @_ > 2 )
{
my $revision = $_[2];
$output .= "-r " . $revision . " ";
}
$output .= $url ." \$(archivedir)/" . $file . " || \\\n\t";
}
elsif ( $url =~ m#^git://# )
{
$output .= "git clone ";
if ( @_ > 3 )
{
my $branch = $_[3];
$output .= "-b " . $branch . " ";
}
if ( $url =~ m#^git://# ) {
my $tmpurl= $url;
$tmpurl =~ s#^git#https# if $url =~ m#^git://github.com#;
$tmpurl =~ s#^git#http# if $url =~ m#^git://git.code.sf.net#;
$output .= $tmpurl ." \$(archivedir)/" . $file . " ";
} else {
$output .= $url ." \$(archivedir)/" . $file . " ";
}
if ( @_ > 2 )
{
my $revision = $_[2];
$output .= "&& (cd \$(archivedir)/" . $file . "; git checkout " . $revision . "; cd -) ";
}
$output .= "|| \\\n\t";
}
$output .= "false )";
$output .= "\n\t\@touch \$\@";
$output .= "\n\n";
}
}
close ( RULES );
print $head . "\n\n" . $output . "\n";