#!/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 );