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
|
#!/usr/bin/perl
use POSIX;
use IO::File;
sub cprint{
if ( $_[0] eq "blue" ){
print( "\e[94m".$_[1]."\e[0m\n" );
}
elsif ( $_[0] eq "green" ){
print( "\e[92m".$_[1]."\e[0m\n" );
}
elsif ( $_[0] eq "red" ){
print( "\e[91m".$_[1]."\e[0m\n" );
}
else
{
print( "\e[94m".$_[1]."\e[0m\n" );
}
}
if ( scalar(@ARGV) < 2 ){
cprint( "blue", "Usage: ".__FILE__." [clone directory] [repository list file]" );
exit( 0 );
}
if ( stat($ARGV[1]) <= 0 ){
cprint( "red", "Error: given list file doesn't exist" );
exit( 0 );
}
if ( stat($ARGV[0]) <= 0 ){
cprint( "red", "Error: given directory doesn't exist" );
exit( 0 );
}
cprint( "blue", "[+] Reading list file ".$ARGV[1] );
my $lfile = IO::File->new( $ARGV[1], "r" ) or die "Failed to open file ".$ARGV[1].": ".$!;
my @git_repo_list = ();
my $current_repo = "";
while ( $current_repo = <$lfile> =~ s/\n//gr ){
if ( $current_repo ne "\n" ){
push( @git_repo_list, $current_repo );
}
}
undef $current_repo;
undef $lfile;
cprint( "green", "[+] List from ".$ARGV[1]." has been read, cloning repositories.." );
cprint( "blue", "[+] Setting directory to ".$ARGV[0] );
chdir( $ARGV[0] ) or die "Failed to set directory to ".$ARGV[0];
cprint( "green", "[+] Directory set to ".$ARGV[0] );
cprint( "blue", "[+] Starting to clone repositories" );
for my $git_repo (@git_repo_list){
if ( length($git_repo) > 0 and $git_repo ne "\n" ){
cprint( "blue", "[+] Cloning repository ".$git_repo );
system( "git clone ".$git_repo );
cprint( "green", "[+] Cloned repository ".$git_repo );
}
}
cprint( "green", "[+] All repositories cloned" );
undef @git_repo_list;
exit( 0 );
|