summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2010-07-19 02:29:48 -0700
committerjblake+piny@omgwallhack.org <jblake@omgwallhack.org>2010-07-19 02:29:48 -0700
commitd70d3046d0816d457e9279ccca7eeb48eb6a5021 (patch)
tree7a75827e9b412d8ac095ede047bd0f5b9f3e570d /usr
parent940fcea58adc84f32aea4e773a71e043e43d9398 (diff)
downloadpiny-code-d70d3046d0816d457e9279ccca7eeb48eb6a5021.tar.gz
piny-code-d70d3046d0816d457e9279ccca7eeb48eb6a5021.zip
Code for destroying repos.
Diffstat (limited to 'usr')
-rw-r--r--usr/src/libpiny/lib/Piny/Repo.pm78
1 files changed, 69 insertions, 9 deletions
diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm
index d8501f8..05c5793 100644
--- a/usr/src/libpiny/lib/Piny/Repo.pm
+++ b/usr/src/libpiny/lib/Piny/Repo.pm
@@ -182,6 +182,64 @@ sub has_access {
return $s->owner->uid == $user->uid || $user->has_group( $s->group );
};
+sub destroy {
+ my ( $s ) = @_;
+
+ my $user = Piny::Environment->instance->user;
+
+ unlink( "/etc/apache2/piny-enabled/" . $s->name );
+ unlink( "/etc/apache2/piny-available/" . $s->name );
+
+ system( "/etc/init.d/apache2", "reload" ) and die "Could not reload apache config!";
+
+ unlink( "/etc/cgitrc.d/" . $s->name );
+
+ my $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: $!";
+
+ unlink( "/etc/ikiwiki/wikilist.d/" . $s->name );
+
+ $temp = File::Temp->new( ) or die "Could not create temporary file: $!";
+ $temp->unlink_on_destroy( 0 );
+
+ $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: $!";
+
+ system( "rm", "-rf", $repo->secure_path, $repo->ikiwiki_destdir, $repo->ikiwiki_srcdir, "/etc/ikiwiki/piny/" . $repo->name . ".setup", $repo->path );
+
+ my $ikiuser = Piny::User::IkiWiki->new( "name" => "ikiwiki-" . $s->name );
+
+ system( "deluser", "--remove-home", $ikiuser->name );
+ system( "delgroup", $ikiuser->name );
+ system( "delgroup", "git-" . $repo->name );
+
+};
+
# Triggers
sub _rename_repo {
@@ -283,14 +341,6 @@ sub create {
print SETUP $repo->ikiwiki_setup;
close( SETUP ) or die "Could not close new ikiwiki setup file: $!";
- open( APACHE, ">", "/etc/apache2/piny-available/" . $repo->name ) or die "Could not open new apache config: $!";
- print APACHE $repo->apache_config;
- close( APACHE ) or die "Could not close new apache config: $!";
-
- symlink( "/etc/apache2/piny-available/" . $repo->name, "/etc/apache2/piny-enabled/" . $repo->name ) or die "Could not symlink apache config: $!";
-
- system( "/etc/init.d/apache2", "reload" ) and die "Could not reload apache config!";
-
system( "/usr/bin/git", "clone", "--quiet", $repo->path, $repo->ikiwiki_srcdir ) and die "Could not clone repo to ikiwiki srcdir!";
mkdir( $repo->ikiwiki_destdir ) or die "Could not create ikiwiki destdir: $!";
@@ -315,6 +365,8 @@ sub create {
$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/" . $repo->name ) or die "Could not create cgitrc.d file: $!";
@@ -334,12 +386,20 @@ sub create {
$temp->close or die "Could not close new cgitrc: $!";
- chmod( 00644, $temp->filename );
+ 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/" . $repo->name . ".setup" ) and die "Could not do initial compile of ikiwiki!";
+ open( APACHE, ">", "/etc/apache2/piny-available/" . $repo->name ) or die "Could not open new apache config: $!";
+ print APACHE $repo->apache_config;
+ close( APACHE ) or die "Could not close new apache config: $!";
+
+ symlink( "/etc/apache2/piny-available/" . $repo->name, "/etc/apache2/piny-enabled/" . $repo->name ) or die "Could not symlink apache config: $!";
+
+ system( "/etc/init.d/apache2", "reload" ) and die "Could not reload apache config!";
+
return $repo;
};