various: add read-only mode support
[girocco.git] / cgi / mirrorproj.cgi
blobb949e32926e29481bc5b8312ed97c40b2e3463f7
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib "__BASEDIR__";
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 if (my $romsg=check_readonly(1)) {
36 print "<p>$romsg</p>\n";
37 exit;
40 my $proj = Girocco::Project->load($name);
41 if (!$proj) {
42 print "<p>not found project $name, that's really weird!</p>\n";
43 exit;
45 my $escname = $name;
46 $escname =~ s/[+]/%2B/g;
48 if (!$proj->{mirror}) {
49 print "<p>This project is not a mirror to be cloned.</p>\n";
50 exit;
54 $| = 1;
56 if (!$proj->{clone_logged} or $proj->{clone_failed}) {
57 # Kick off the clone since it is not running yet
58 print "<p>Initiated mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
59 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git:</p>\n";
61 } elsif ($proj->{clone_in_progress}) {
62 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
63 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git in progress:</p>\n";
64 } else {
65 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
66 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git completed:</p>\n";
69 my $retries = 7;
70 for (;;) {
71 open LOG, '<', $proj->_clonelog_path() and last;
72 if ($retries--) {
73 sleep 1;
74 } else {
75 print "<p>Mirroring has not yet started, there may be a clone backlog.</p>\n";
76 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname\">reload this page</a> again later.</p>\n";
77 exit 0;
81 print "<pre>\n";
82 tailf: for (;;) {
83 my $curpos;
84 for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
85 chomp;
86 $_ eq '@OVER@' and last tailf;
87 print "$_\n";
89 sleep 1;
90 seek(LOG, $curpos, 0); # seek to where we had been
92 print "</pre>\n";
93 close LOG;
95 $proj = Girocco::Project->load($name);
96 $proj or die "not found project $name on second load, that's _REALLY_ weird!";
98 if ($proj->{clone_failed}) {
99 print <<EOT;
100 <p><strong>Mirroring failed!</strong> Please <a
101 href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$escname"
102 >revisit the project settings</a>.</p>