summaryrefslogtreecommitdiff
path: root/usr/src/libpiny/lib/Piny/Repo.pm
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/libpiny/lib/Piny/Repo.pm')
-rw-r--r--usr/src/libpiny/lib/Piny/Repo.pm70
1 files changed, 70 insertions, 0 deletions
diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm
index ca8ae07..598760e 100644
--- a/usr/src/libpiny/lib/Piny/Repo.pm
+++ b/usr/src/libpiny/lib/Piny/Repo.pm
@@ -193,6 +193,76 @@ sub has_access {
return $s->owner->uid == $user->uid || $user->has_group( $s->group );
};
+sub rebuild {
+ my ( $s ) = @_;
+
+ my $ikiuser = Piny::User::IkiWiki->new( "name" => "ikiwiki-" . $s->name );
+
+ open( TOUCH, ">", $s->path . "/git-daemon-export-ok" ) or die "Could not touch git-daemon-export-ok for repo: $!";
+ close( TOUCH );
+
+ system( "/bin/chown", "-R", $s->owner->name . "." . $s->group->name, $s->path ) and die "Could not change ownership of git repo!";
+ system( "/bin/chown", "-R", $ikiuser->name . "." . $ikiuser->name, $s->path . "/hooks" ) and die "Could not change ownership of git hooks!";
+
+ open( SETUP, ">", "/etc/ikiwiki/piny/" . $s->name . ".setup" ) or die "Could not open new ikiwiki setup file: $!";
+ print SETUP $s->ikiwiki_setup;
+ close( SETUP ) or die "Could not close new ikiwiki setup file: $!";
+
+ system( "/bin/chown", "-R", $ikiuser->name . "." . $ikiuser->name, $s->ikiwiki_srcdir, $s->ikiwiki_destdir, $s->secure_path ) and die "Could not change ownership of ikiwiki directories!";
+
+ open( WIKILIST, ">", "/etc/ikiwiki/wikilist.d/" . $s->name ) or die "Could not create wikilist.d file: $!";
+ print WIKILIST $ikiuser->name . " /etc/ikiwiki/piny/" . $s->name . ".setup\n";
+ close( WIKILIST ) or die "Could not close wikilist.d file: $!";
+
+ my $temp = File::Temp->new( ) or die "Could not create temporary file: $!";
+ $temp->unlink_on_destroy( 0 );
+
+ my $dh = IO::Dir->new( "/etc/ikiwiki/wikilist.d" ) or die "Could not open wikilist.d directory: $!";
+ while ( defined ( my $entry = $dh->read ) ) {
+ next if ( $entry =~ /^\./ );
+ open( FILE, "<", "/etc/ikiwiki/wikilist.d/" . $entry ) or die "Could not open wikilist.d entry $entry: $!";
+ print $temp <FILE>;
+ close( FILE ) or die "Could not close wikilist.d entry $entry: $!";
+ };
+
+ $temp->close or die "Could not close new wikilist: $!";
+
+ chmod( 00644, $temp->filename ) or die "Could not fix mode of new wikilist: $!";
+
+ rename( $temp->filename, "/etc/ikiwiki/wikilist" ) or die "Could not rename over old wikilist: $!";
+
+ open( CGITLIST, ">", "/etc/cgitrc.d/" . $s->name ) or die "Could not create cgitrc.d file: $!";
+ print CGITLIST "repo.url=" . $s->name . "\nrepo.path=" . $s->path . "\nrepo.desc=" . $s->description . "\nrepo.owner=" . $s->owner->email->address . "\n\n";
+ close( CGITLIST ) or die "Could not close cgitrc.d file: $!";
+
+ $temp = File::Temp->new( ) or die "Could not create temporary file: $!";
+ $temp->unlink_on_destroy( 0 );
+
+ $dh = IO::Dir->new( "/etc/cgitrc.d" ) or die "Could not open cgitrc.d directory: $!";
+ while ( defined ( my $entry = $dh->read ) ) {
+ next if ( $entry =~ /^\./ );
+ open( FILE, "<", "/etc/cgitrc.d/" . $entry ) or die "Could not open cgitrc.d entry $entry: $!";
+ print $temp <FILE>;
+ close( FILE ) or die "Could not close cgitrc.d entry $entry: $!";
+ };
+
+ $temp->close or die "Could not close new cgitrc: $!";
+
+ chmod( 00644, $temp->filename ) or die "Could not fix mode of new cgitrc: $!";
+
+ rename( $temp->filename, "/etc/cgitrepos" ) or die "Could not rename over old cgitrc: $!";
+
+ system( "/usr/bin/sudo", "-u", $ikiuser->name, "/usr/bin/ikiwiki", "--setup", "/etc/ikiwiki/piny/" . $s->name . ".setup" ) and die "Could not do initial compile of ikiwiki!";
+
+ open( APACHE, ">", "/etc/apache2/piny-available/" . $s->name ) or die "Could not open new apache config: $!";
+ print APACHE $s->apache_config;
+ close( APACHE ) or die "Could not close new apache config: $!";
+
+ symlink( "/etc/apache2/piny-available/" . $s->name, "/etc/apache2/piny-enabled/" . $s->name ) or die "Could not symlink apache config: $!";
+
+ system( "/etc/init.d/apache2", "reload" ) and die "Could not reload apache config!";
+};
+
sub destroy {
my ( $s ) = @_;