mirroring: add individual foreign vcs mirror control
[girocco.git] / cgi / mirrorproj.cgi
blob39866e352f17d38eeb907e5510b7ba429a171db8
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('Project Mirroring');
15 my $cgi = $gcgi->cgi;
17 my $name = $cgi->param('name');
18 $name =~ s#\.git$## if $name; #
20 unless (defined $name) {
21 print "<p>I need the project name as an argument now.</p>\n";
22 exit;
25 if (!Girocco::Project::does_exist($name,1) && !Girocco::Project::valid_name($name)) {
26 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
27 exit;
30 if (!Girocco::Project::does_exist($name,1)) {
31 print "<p>Sorry but the project $name does not exist. Now, how did you <em>get</em> here?!</p>\n";
32 exit;
35 my $proj = Girocco::Project->load($name);
36 $proj or die "not found project $name, that's really weird!";
37 my $escname = $name;
38 $escname =~ s/[+]/%2B/g;
40 if (!$proj->{mirror}) {
41 print "<p>This project is not a mirror to be cloned.</p>\n";
42 exit;
46 $| = 1;
48 if (!$proj->{clone_logged} or $proj->{clone_failed}) {
49 # Kick off the clone since it is not running yet
50 print "<p>Initiated mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
51 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git:</p>\n";
52 $proj->clone;
54 } elsif ($proj->{clone_in_progress}) {
55 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
56 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git in progress:</p>\n";
57 } else {
58 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
59 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git completed:</p>\n";
62 print "<pre>\n";
64 open LOG, $proj->_clonelog_path() or die "clonelog: $!";
65 tailf: for (;;) {
66 my $curpos;
67 for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
68 chomp;
69 $_ eq '@OVER@' and last tailf;
70 print "$_\n";
72 sleep 1;
73 seek(LOG, $curpos, 0); # seek to where we had been
75 close LOG;
77 print "</pre>\n";
79 $proj = Girocco::Project->load($name);
80 $proj or die "not found project $name on second load, that's _REALLY_ weird!";
82 if ($proj->{clone_failed}) {
83 print <<EOT;
84 <p><strong>Mirroring failed!</strong> Please <a
85 href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$escname"
86 >revisit the project settings</a>.</p>
87 EOT