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.pm183
1 files changed, 168 insertions, 15 deletions
diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm
index 84b5bb4..091d59a 100644
--- a/usr/src/libpiny/lib/Piny/Repo.pm
+++ b/usr/src/libpiny/lib/Piny/Repo.pm
@@ -8,6 +8,8 @@ use Moose::Util::TypeConstraints;
use File::Find qw( find );
+use IkiWiki::FakeSetup qw( readSetup writeSetup );
+
use Piny::Group;
use Piny::User;
@@ -85,24 +87,80 @@ has 'globally_writable' =>
, init_arg => undef
);
+has 'ikiwiki_setup' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'ikiwiki_destdir' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'ikiwiki_srcdir' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'url' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'ikiwiki_cgiuri' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'ikiwiki_historyurl' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'ikiwiki_diffurl' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
+has 'ikiwiki_cgipath' =>
+ ( is => 'ro'
+ , isa => 'Str'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
# Public methods
sub add_access {
my ( $s, @users ) = @_;
- $s->group( )->add_member( @users );
+ $s->group->add_member( @users );
};
sub remove_access {
my ( $s, @users ) = @_;
- $s->group( )->remove_member( @users );
+ $s->group->remove_member( @users );
};
sub has_access {
my ( $s, $user ) = @_;
- return $s->owner( )->uid( ) == $user->uid( ) || $user->has_group( $s->group( ) );
+ return $s->owner->uid == $user->uid || $user->has_group( $s->group );
};
# Triggers
@@ -117,7 +175,16 @@ sub _rename_repo {
rename( $olddir, $newdir ) or die "Couldn't rename $olddir to $newdir: $!";
- $s->clear_path( );
+ warn "XXX Not renaming all the ikiwiki stuff!";
+
+ $s->clear_path;
+ $s->clear_ikiwiki_setup;
+ $s->clear_ikiwiki_destdir;
+ $s->clear_ikiwiki_srcdir;
+ $s->clear_url;
+ $s->clear_ikiwiki_cgiurl;
+ $s->clear_ikiwiki_historyurl;
+ $s->clear_ikiwiki_cgipath;
};
sub _set_description {
@@ -125,9 +192,9 @@ sub _set_description {
return unless defined $old_description;
- open( my $fd, ">", $s->path( ) . "/description" ) or die "Unable to open " . $s->path( ) . "/description for writing: $!";
+ open( my $fd, ">", $s->path . "/description" ) or die "Unable to open " . $s->path . "/description for writing: $!";
print $fd $new_description;
- close( $fd ) or die "Error when closing " . $s->path( ) . "/description: $!";
+ close( $fd ) or die "Error when closing " . $s->path . "/description: $!";
};
sub _change_owner {
@@ -135,7 +202,9 @@ sub _change_owner {
return unless defined $old_owner;
- find( { wanted => sub { chown( $new_owner->uid( ), -1, $_ ) or die "Couldn't chown $_: $!"; }, no_chdir => 1 }, $s->path( ) );
+ find( { wanted => sub { chown( $new_owner->uid, -1, $_ ) or die "Couldn't chown $_: $!"; }, no_chdir => 1 }, $s->path );
+
+ $s->clear_ikiwiki_setup;
};
# Class methods
@@ -170,13 +239,13 @@ around BUILDARGS => sub {
sub _build_group {
my ( $s ) = @_;
- return Piny::Group->new( groupname => "git-" . $s->name( ) );
+ return Piny::Group->new( name => "git-" . $s->name );
};
sub _build_path {
my ( $s ) = @_;
- my $dir = "/srv/git/" . $s->name( ) . ".git";
+ my $dir = "/srv/git/" . $s->name . ".git";
if ( -d $dir ) {
return $dir;
@@ -188,7 +257,7 @@ sub _build_path {
sub _build_description {
my ( $s ) = @_;
- open( my $d, "<", $s->path( ) . "/description" ) or die "Unable to open " . $s->path( ) . "/description: $!";
+ open( my $d, "<", $s->path . "/description" ) or die "Unable to open " . $s->path . "/description: $!";
my $desc;
{
local $/ = undef;
@@ -202,15 +271,15 @@ sub _build_description {
sub _build_repostat {
my ( $s ) = @_;
- my @res = stat( $s->path( ) );
- die "stat( " . $s->path( ) . " ) failed: $!" unless @res;
+ my @res = stat( $s->path );
+ die "stat( " . $s->path . " ) failed: $!" unless @res;
return \@res;
};
sub _build_owner {
my ( $s ) = @_;
- my ( $uid ) = $s->repostat( )->[4];
+ my ( $uid ) = $s->repostat->[4];
return Piny::User->new( uid => $uid );
};
@@ -218,13 +287,97 @@ sub _build_owner {
sub _build_globally_readable {
my ( $s ) = @_;
- return ( $s->repostat( )->[2] & 0444 ) == 0444;
+ return ( $s->repostat->[2] & 0444 ) == 0444;
};
sub _build_globally_writable {
my ( $s ) = @_;
- return ( $s->repostat( )->[2] & 0111 ) == 0111;
+ return ( $s->repostat->[2] & 0111 ) == 0111;
+};
+
+sub _build_ikiwiki_setup {
+ my ( $s ) = @_;
+
+ my ( $package, $config ) = readSetup( "/usr/share/libpiny/ikiwiki.setup" );
+
+ $config->{"wikiname"} = $s->name;
+ $config->{"adminemail"} = $s->owner->email;
+ $config->{"srcdir"} = $s->ikiwiki_srcdir;
+ $config->{"destdir"} = $s->ikiwiki_destdir;
+ $config->{"url"} = $s->url;
+ $config->{"cgiurl"} = $s->ikiwiki_cgiurl;
+ $config->{"historyurl"} = $s->ikiwiki_historyurl;
+ $config->{"diffurl"} = $s->ikiwiki_diffurl;
+
+ $config->{"wrappers"} =
+ [ { "wrapper" => $s->ikiwiki_cgipath
+ , "wrappergroup" => $s->group->name
+ , "wrappermode" => 06755
+ , "cgi" => 1
+ }
+ , { "wrapper" => $s->path . "/hooks/post-update"
+ , "wrappergroup" => $s->group->name
+ , "wrappermode" => 06755
+ , "notify" => 0
+ }
+ ];
+
+ return writeSetup( $package, $config );
+};
+
+sub _build_ikiwiki_destdir {
+ my ( $s ) = @_;
+
+ my $dir = "/srv/www/piny.be/" . $s->name;
+
+ if ( -d $dir ) {
+ return $dir;
+ } else {
+ die "Expected destdir $dir does not exist!";
+ };
+};
+
+sub _build_ikiwiki_srcdir {
+ my ( $s ) = @_;
+
+ my $dir = "/srv/ikiwiki/" . $s->name;
+
+ if ( -d $dir ) {
+ return $dir;
+ } else {
+ die "Expected srcdir $dir does not exist!";
+ };
+};
+
+sub _build_url {
+ my ( $s ) = @_;
+
+ return "http://piny.be/" . $s->name;
+};
+
+sub _build_ikiwiki_cgiurl {
+ my ( $s ) = @_;
+
+ return "https://secure.piny.be/repos/" . $s->name . "/ikiwiki.cgi";
+};
+
+sub _build_ikiwiki_cgipath {
+ my ( $s ) = @_;
+
+ return "/srv/www/secure.piny.be/repos/" . $s->name . "/ikiwiki.cgi";
+};
+
+sub _build_ikiwiki_historyurl {
+ my ( $s ) = @_;
+
+ return "https://secure.piny.be/cgit/" . $s->name . "/log/[[file]]";
+};
+
+sub _build_ikiwiki_diffurl {
+ my ( $s ) = @_;
+
+ return "https://secure.piny.be/cgit/" . $s->name . "/diff/?id=[[sha1_commit]]";
};
# Moose boilerplate