Merge branch 'master' of git+ssh://repo.or.cz/srv/git/girocco
[girocco/testingthisout.git] / cgi / mirrorproj.cgi
blob9aa7c2e77589510095cd9bb94cc352acba57b898
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::valid_name($name)) {
26 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
27 exit;
30 if (!Girocco::Project::does_exist($name)) {
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!";
38 if (!$proj->{mirror} or !$proj->{clone_in_progress}) {
39 print "<p>This project is not a mirror to be cloned.</p>\n";
40 exit;
44 $| = 1;
46 if (!$proj->{clone_logged} or $proj->{clone_failed}) {
47 # Kick off the clone since it is not running yet
48 print "<p>Initiated mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
49 "<a href=\"$Girocco::Config::gitweburl/$name.git\">$name</a>.git:</p>\n";
50 $proj->clone;
52 } else {
53 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
54 "<a href=\"$Girocco::Config::gitweburl/$name.git\">$name</a>.git in progress:</p>\n";
57 print "<pre>\n";
59 open LOG, $proj->_clonelog_path() or die "clonelog: $!";
60 tailf: for (;;) {
61 my $curpos;
62 for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
63 chomp;
64 $_ eq '@OVER@' and last tailf;
65 print "$_\n";
67 sleep 1;
68 seek(LOG, $curpos, 0); # seek to where we had been
70 close LOG;
72 print "</pre>\n";
74 my $proj = Girocco::Project->load($name);
75 $proj or die "not found project $name on second load, that's _REALLY_ weird!";
77 if ($proj->{clone_failed}) {
78 print <<EOT;
79 <p><strong>Mirroring failed!</strong> Please <a href="editproj.cgi?name=$name">revisit the project settings</a>.</p>
80 EOT