oldrepo/mirror-gogs/update.pl

97 lines
2.5 KiB
Perl
Raw Permalink Normal View History

2018-06-07 16:32:46 -05:00
#!/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
2018-06-07 18:15:14 -05:00
if ($ARGV[0] eq "--dry-run") {
$dry = 'TRUE';
shift @ARGV;
}
2018-06-07 16:32:46 -05:00
sub my_system {
my $cmd = join " ", @_;
chomp $cmd;
print "$cmd\n";
2018-06-07 18:15:14 -05:00
if ($dry ne "TRUE") {
2018-06-07 16:32:46 -05:00
$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";
}
2018-06-07 18:15:14 -05:00
if ($dry ne "TRUE") {
2018-06-07 16:32:46 -05:00
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") {
2018-06-07 21:18:38 -05:00
my_system("tar -c --use-compress-program=pigz -f archive.$STAMP.gogs.tgz mirrored-gogs/git/gogs-repositories/");
2018-06-07 16:32:46 -05:00
2018-06-17 04:22:17 -05:00
my_system("rsync -av --progress --delete vm9:/var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/kube-pool-image-kubernetes-dynamic-pvc-7a6428c8-376e-11e8-85ad-0a580af40662/ mirrored-gogs/");
2018-06-07 16:32:46 -05:00
my_system("rsync -av --progress --delete mirrored-gogs/git/gogs-repositories/ gitweb:/var/lib/git/gogs/");
exit;
}
2018-06-07 18:15:14 -05:00
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";
}
2018-06-07 16:32:46 -05:00
}
}
2018-06-07 16:56:40 -05:00
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");
}
2018-06-07 16:32:46 -05:00
}
}