summaryrefslogtreecommitdiff
path: root/usr/src/libpiny
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2010-10-13 20:43:12 -0700
committerjblake+piny@omgwallhack.org <jblake@omgwallhack.org>2010-10-13 20:43:12 -0700
commit2f862e33447446116907c60ba1142369f70a99ab (patch)
treeda7ed59f81ba22a8347f3fcc4802aa23bbb3169b /usr/src/libpiny
parentca2a5d4df51dec985d00802426dc5f8fa47734d8 (diff)
downloadpiny-code-2f862e33447446116907c60ba1142369f70a99ab.tar.gz
piny-code-2f862e33447446116907c60ba1142369f70a99ab.zip
Rebuilding repo configs.
Diffstat (limited to 'usr/src/libpiny')
-rw-r--r--usr/src/libpiny/debian/changelog6
-rw-r--r--usr/src/libpiny/lib/Piny/Repo.pm70
2 files changed, 76 insertions, 0 deletions
diff --git a/usr/src/libpiny/debian/changelog b/usr/src/libpiny/debian/changelog
index 777bb27..e97c2fe 100644
--- a/usr/src/libpiny/debian/changelog
+++ b/usr/src/libpiny/debian/changelog
@@ -1,3 +1,9 @@
+libpiny-perl (0.14) unstable; urgency=low
+
+ * Support rebuilding a repo's config.
+
+ -- Julian Blake Kongslie <jblake@omgwallhack.org> Wed, 13 Oct 2010 20:38:15 -0700
+
libpiny-perl (0.13) unstable; urgency=low
* Vastly overhauled the config stuff.
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 ) = @_;