52 lines
963 B
Perl
Executable File
52 lines
963 B
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
$repo=$ARGV[0];
|
|
$repo=~s/\/\s*$//;
|
|
|
|
die if ($repo=~/^\s*$/);
|
|
|
|
$cgit='git://git.micw.org';
|
|
$pgit='ssh://git@git.micw.org:2234/home/git';
|
|
|
|
if (-d $repo) {
|
|
if (yesno('overwrite existing directory?',0)) {
|
|
&cmd("rm -rf $repo")
|
|
} else {
|
|
exit;
|
|
}
|
|
}
|
|
|
|
&cmd("git clone $cgit/$repo.git");
|
|
&cmd("cd $repo;git remote set-url origin $pgit/$repo.git");
|
|
|
|
sub cmd() {
|
|
my($cmd,$quiet)=@_;
|
|
print "$cmd\n" if (!$quiet);
|
|
system($cmd);
|
|
}
|
|
|
|
sub yesno {
|
|
my($prom,$def)=@_;
|
|
my($ans);
|
|
if ($def) {;$ans=&getkey("$prom Y/n ? ");}
|
|
else {;$ans=&getkey("$prom y/N ? ");}
|
|
if ($ans=~/^\s*$/) {
|
|
if ($def) {;return(1);}
|
|
else {;return(0);}
|
|
}
|
|
if ($ans=~/^\s*y\s*$/i || $ans=~/^\s*yes\s*$/i) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
sub getkey {
|
|
$|=1;
|
|
print "$_[0]";
|
|
system "stty", '-icanon', '-echo', 'eol', "\001";
|
|
$key = getc(STDIN);$key=~s/[\r\n\t]//g;
|
|
system "stty", 'icanon', 'echo', 'eol', "^@";
|
|
print "$key\n";
|
|
return $key;
|
|
}
|