97 lines
2.5 KiB
Perl
97 lines
2.5 KiB
Perl
|
#!/usr/bin/perl
|
||
|
|
||
|
$STAMP=`date +%Y.%m.%d.%H%M%S`;
|
||
|
chomp $STAMP;
|
||
|
|
||
|
# find gogs:
|
||
|
# kubectl -n cloud-wit get pods
|
||
|
# kubectl -n cloud-wit describe pod gogs-7596dddd7-7j6zb # the old one? now it's:
|
||
|
# kubectl -n cloud-wit describe pod gogs-fbf5fd88f-9v45z
|
||
|
# kubectl -n cloud-wit get pv |grep gogs
|
||
|
|
||
|
if ($ARGV[0] eq "--dry-run") {
|
||
|
$dry = 'TRUE';
|
||
|
shift @ARGV;
|
||
|
}
|
||
|
|
||
|
|
||
|
sub my_system {
|
||
|
my $cmd = join " ", @_;
|
||
|
chomp $cmd;
|
||
|
print "$cmd\n";
|
||
|
if ($dry ne "TRUE") {
|
||
|
$return = system $cmd;
|
||
|
if ($return eq 2) {
|
||
|
print "SYSTEM RETURNED $return\n";
|
||
|
exit;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub gitrepo {
|
||
|
my ($base, $name, $repo) = @_;
|
||
|
# print "$base,$name,$repo\n";
|
||
|
if (! -d "$base") {
|
||
|
my_system "mkdir -p $base/$dir\n";
|
||
|
}
|
||
|
if (-d "$base/$name") {
|
||
|
my_system "cd $base/$name; git pull\n";
|
||
|
} else {
|
||
|
my_system "cd $base; git clone $repo $name\n";
|
||
|
}
|
||
|
if ($dry ne "TRUE") {
|
||
|
if (! -d "$base/$name/.git") {
|
||
|
print "GIT FAILED for $repo\n";
|
||
|
my_system "rmdir $base/$name" if -d "$base/$name";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$basedir = `pwd`;
|
||
|
chomp $basedir;
|
||
|
|
||
|
if ($ARGV[0] eq "rsync") {
|
||
|
my_system("tar -c --use-compress-program=pigz -f archive.$STAMP.gogs.tgz mirrored-gogs/git/gogs-repositories/");
|
||
|
|
||
|
my_system("rsync -av --progress --delete vm10:/var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/kube-pool-image-kubernetes-dynamic-pvc-7a6428c8-376e-11e8-85ad-0a580af40662/ mirrored-gogs/");
|
||
|
my_system("rsync -av --progress --delete mirrored-gogs/git/gogs-repositories/ gitweb:/var/lib/git/gogs/");
|
||
|
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
if ($ARGV[0] eq "manifest") {
|
||
|
@lines = split "\n", `cat MANIFEST`;
|
||
|
foreach $line (@lines) {
|
||
|
my ($repo, $tmp) = split / +/, $line;
|
||
|
next if $repo eq "";
|
||
|
my @dirs = split /\//, $tmp;
|
||
|
my $name = pop @dirs;
|
||
|
my $dir = join '/', @dirs;
|
||
|
if ( 'git/' eq substr $repo, 0, 4 ) {
|
||
|
gitrepo ("cloned-ping/$dir", $name, "ssh://root\@ping.wit.com/var/lib/$repo");
|
||
|
# } elsif ( 'git@github.com:witst' eq substr $repo, 0, 20 ) {
|
||
|
# gitrepo ("cloned-github/$dir", $name, $repo);
|
||
|
} elsif ( 'git@git.wit.com' eq substr $repo, 0, 15 ) {
|
||
|
gitrepo ("cloned-jcarr/$dir", $name, $repo);
|
||
|
} else {
|
||
|
# print "$path, $dir\n";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($ARGV[0] eq "gogs") {
|
||
|
foreach $dir (`ls mirrored-gogs/git/gogs-repositories/`) {
|
||
|
chomp $dir;
|
||
|
# print "$dir\n";
|
||
|
if (! -d "cloned-gogs/$dir") {
|
||
|
my_system "mkdir -p cloned-gogs/$dir\n";
|
||
|
}
|
||
|
foreach $name (`ls mirrored-gogs/git/gogs-repositories/$dir`) {
|
||
|
chomp $name;
|
||
|
next if ".git" ne substr $name, -4;
|
||
|
$name = substr $name, 0, -4;
|
||
|
gitrepo ("cloned-gogs/$dir", $name, "git\@git.wit.com:$dir/$name");
|
||
|
}
|
||
|
}
|
||
|
}
|