summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2010-07-07 14:07:06 -0700
committerJulian Blake Kongslie <jblake@omgwallhack.org>2010-07-07 14:07:06 -0700
commit4fa79cd01321b079ad94c6041038bd3a7dcc0958 (patch)
tree5c55ffa7d5f06827a18a9c38e953226160530fa9 /usr
parent7b243125659e9a13126198b2b790a697552d59e5 (diff)
downloadpiny-code-4fa79cd01321b079ad94c6041038bd3a7dcc0958.tar.gz
piny-code-4fa79cd01321b079ad94c6041038bd3a7dcc0958.zip
Lots more ikiwiki integration stuff in libpiny.
Diffstat (limited to 'usr')
-rw-r--r--usr/src/libpiny/Build.PL32
-rw-r--r--usr/src/libpiny/debian/changelog6
-rw-r--r--usr/src/libpiny/lib/Piny/Environment.pm4
-rw-r--r--usr/src/libpiny/lib/Piny/Group.pm30
-rw-r--r--usr/src/libpiny/lib/Piny/Repo.pm183
-rw-r--r--usr/src/libpiny/lib/Piny/User.pm24
-rw-r--r--usr/src/libpiny/share/ikiwiki.setup77
-rwxr-xr-xusr/src/pinyadmin/bin/lsaccess2
8 files changed, 307 insertions, 51 deletions
diff --git a/usr/src/libpiny/Build.PL b/usr/src/libpiny/Build.PL
index 09cf3fb..bfb5fd7 100644
--- a/usr/src/libpiny/Build.PL
+++ b/usr/src/libpiny/Build.PL
@@ -1,10 +1,30 @@
use Module::Build;
-Module::Build->new
- ( module_name => 'Piny'
- , license => 'BSD-3'
- , dist_version => '0.6'
- , requires =>
+
+open( DCH, "<", "debian/changelog" ) or die "changelog: $!";
+
+my $version = "0";
+while ( defined ( my $line = <DCH> ) ) {
+ if ( $line =~ /\(([0-9.]+)\)/ ) {
+ $version = $1;
+ last;
+ };
+};
+
+close( DCH );
+
+my $build = Module::Build->new
+ ( 'module_name' => 'Piny'
+ , 'dist_version' => $version
+ , 'license' => 'BSD-3'
+ , 'setup_files' => { 'share/ikiwiki.setup' => 'share/ikiwiki.setup' }
+ , 'install_path' =>
+ { 'share' => '/usr/share/libpiny'
+ }
+ , 'requires' =>
{ 'Moose' => 0
, 'Email::Valid::Loose' => 0
}
- )->create_build_script( );
+ );
+
+$build->add_build_element( "setup" );
+$build->create_build_script( );
diff --git a/usr/src/libpiny/debian/changelog b/usr/src/libpiny/debian/changelog
index df872b4..cc6a89b 100644
--- a/usr/src/libpiny/debian/changelog
+++ b/usr/src/libpiny/debian/changelog
@@ -1,3 +1,9 @@
+libpiny-perl (0.7) unstable; urgency=low
+
+ * Lots more ikiwiki integration.
+
+ -- Julian Blake Kongslie <jblake@omgwallhack.org> Wed, 07 Jul 2010 13:45:42 -0700
+
libpiny-perl (0.6) unstable; urgency=low
* Added IkiWiki::FakeSetup for manipulating IkiWiki setup scripts.
diff --git a/usr/src/libpiny/lib/Piny/Environment.pm b/usr/src/libpiny/lib/Piny/Environment.pm
index 586cce3..fcd4392 100644
--- a/usr/src/libpiny/lib/Piny/Environment.pm
+++ b/usr/src/libpiny/lib/Piny/Environment.pm
@@ -24,11 +24,11 @@ sub _build_user {
if ( defined $ENV{"SUDO_UID"} ) {
return Piny::User->new( uid => $ENV{"SUDO_UID"} );
} elsif ( defined $ENV{"SUDO_USER"} ) {
- return Piny::User->new( username => $ENV{"SUDO_USER"} );
+ return Piny::User->new( name => $ENV{"SUDO_USER"} );
} elsif ( defined $ENV{"UID"} ) {
return Piny::User->new( uid => $ENV{"UID"} );
} elsif ( defined $ENV{"USER"} ) {
- return Piny::User->new( username => $ENV{"USER"} );
+ return Piny::User->new( name => $ENV{"USER"} );
} else {
return Piny::User->new( uid => $< );
};
diff --git a/usr/src/libpiny/lib/Piny/Group.pm b/usr/src/libpiny/lib/Piny/Group.pm
index a4d3c27..ac064da 100644
--- a/usr/src/libpiny/lib/Piny/Group.pm
+++ b/usr/src/libpiny/lib/Piny/Group.pm
@@ -15,7 +15,7 @@ has 'gid' =>
, lazy_build => 1
);
-has 'groupname' =>
+has 'name' =>
( is => 'ro'
, isa => 'Str'
, lazy_build => 1
@@ -41,7 +41,7 @@ sub add_member {
my ( $s, @users ) = @_;
foreach my $user ( @users ) {
- system( "/usr/sbin/adduser", $user->username( ), $s->groupname( ) );
+ system( "/usr/sbin/adduser", $user->name( ), $s->name( ) );
$user->clear_groups( );
};
@@ -52,7 +52,7 @@ sub remove_member {
my ( $s, @users ) = @_;
foreach my $user ( @users ) {
- system( "/usr/sbin/deluser", $user->username( ), $s->groupname( ) );
+ system( "/usr/sbin/deluser", $user->name( ), $s->name( ) );
$user->clear_groups( );
};
@@ -62,8 +62,8 @@ sub remove_member {
# Builder methods
# If constructed with just one argument, then
-# * If that argument is numeric, treat it as a UID.
-# * Otherwise, treat it as a username.
+# * If that argument is numeric, treat it as a GID.
+# * Otherwise, treat it as a name.
around BUILDARGS => sub {
my ( $orig, $class ) = ( shift, shift );
@@ -71,7 +71,7 @@ around BUILDARGS => sub {
if ( $_[0] =~ m/^\d+$/ ) {
return $class->$orig( gid => $_[0] );
} else {
- return $class->$orig( groupname => $_[0] );
+ return $class->$orig( name => $_[0] );
};
} else {
return $class->$orig( @_ );
@@ -81,12 +81,12 @@ around BUILDARGS => sub {
sub BUILD {
my ( $s ) = @_;
- if ( not ( $s->has_gid( ) or $s->has_groupname( ) ) ) {
- die "You must provide either GID or groupname!";
+ if ( not ( $s->has_gid( ) or $s->has_name( ) ) ) {
+ die "You must provide either GID or name!";
};
- if ( $s->has_gid( ) and $s->has_groupname( ) ) {
- die "You must not provide both GID and groupname!";
+ if ( $s->has_gid( ) and $s->has_name( ) ) {
+ die "You must not provide both GID and name!";
};
};
@@ -96,7 +96,7 @@ sub _build_gid {
return $s->grent( )->[2];
};
-sub _build_groupname {
+sub _build_name {
my ( $s ) = @_;
return $s->grent( )->[0];
@@ -109,9 +109,9 @@ sub _build_grent {
my @res = getgrgid( $s->gid( ) );
die "getgrgid( " . $s->gid( ) . " ) failed: $!" unless @res;
return \@res;
- } elsif ( $s->has_groupname( ) ) {
- my @res = getgrnam( $s->groupname( ) );
- die "getgrnam( " . $s->groupname( ) . " ) failed: $!" unless @res;
+ } elsif ( $s->has_name( ) ) {
+ my @res = getgrnam( $s->name( ) );
+ die "getgrnam( " . $s->name( ) . " ) failed: $!" unless @res;
return \@res;
} else {
die "Not enough information provided to lookup group!";
@@ -122,7 +122,7 @@ sub _build_members {
my ( $s ) = @_;
return [ ] if ( $s->grent( )->[3] eq "" );
- return [ map { Piny::User->new( username => $_ ) } split( /:/, $s->grent( )->[3] ) ];
+ return [ map { Piny::User->new( name => $_ ) } split( /:/, $s->grent( )->[3] ) ];
};
# Moose boilerplate
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
diff --git a/usr/src/libpiny/lib/Piny/User.pm b/usr/src/libpiny/lib/Piny/User.pm
index 559adfd..173b592 100644
--- a/usr/src/libpiny/lib/Piny/User.pm
+++ b/usr/src/libpiny/lib/Piny/User.pm
@@ -25,7 +25,7 @@ has 'uid' =>
, lazy_build => 1
);
-has 'username' =>
+has 'name' =>
( is => 'ro'
, isa => 'Username'
, lazy_build => 1
@@ -100,7 +100,7 @@ sub all_users {
eval {
my $user = $class->new( uid => $info[2] );
# Some forced early evaluation, so error checking happens now.
- $user->username( );
+ $user->name( );
$user->email( );
push( @ret, $user );
};
@@ -123,7 +123,7 @@ around BUILDARGS => sub {
if ( $_[0] =~ m/^\d+$/ ) {
return $class->$orig( uid => $_[0] );
} else {
- return $class->$orig( username => $_[0] );
+ return $class->$orig( name => $_[0] );
};
} else {
return $class->$orig( @_ );
@@ -133,12 +133,12 @@ around BUILDARGS => sub {
sub BUILD {
my ( $s ) = @_;
- if ( not ( $s->has_uid( ) or $s->has_username( ) ) ) {
- die "You must provide either UID or username!";
+ if ( not ( $s->has_uid( ) or $s->has_name( ) ) ) {
+ die "You must provide either UID or name!";
};
- if ( $s->has_uid( ) and $s->has_username( ) ) {
- die "You must not provide both UID and username!";
+ if ( $s->has_uid( ) and $s->has_name( ) ) {
+ die "You must not provide both UID and name!";
};
};
@@ -148,7 +148,7 @@ sub _build_uid {
return $s->pwent( )->[2];
};
-sub _build_username {
+sub _build_name {
my ( $s ) = @_;
return $s->pwent( )->[0];
@@ -161,9 +161,9 @@ sub _build_pwent {
my @res = getpwuid( $s->uid( ) );
die "getpwuid( " . $s->uid( ) . " ) failed: $!" unless @res;
return \@res;
- } elsif ( $s->has_username( ) ) {
- my @res = getpwnam( $s->username( ) );
- die "getpwnam( " . $s->username( ) . " ) failed: $!" unless @res;
+ } elsif ( $s->has_name( ) ) {
+ my @res = getpwnam( $s->name( ) );
+ die "getpwnam( " . $s->name( ) . " ) failed: $!" unless @res;
return \@res;
} else {
die "Not enough information provided to lookup user!";
@@ -193,7 +193,7 @@ sub _build_groups {
while ( @ent = getgrent( ) ) {
next if ( $ent[3] eq "" );
foreach my $member ( split( / /, $ent[3] ) ) {
- if ( $member eq $s->username( ) ) {
+ if ( $member eq $s->name( ) ) {
push @res, Piny::Group->new( gid => $ent[2] );
last;
};
diff --git a/usr/src/libpiny/share/ikiwiki.setup b/usr/src/libpiny/share/ikiwiki.setup
new file mode 100644
index 0000000..4cba4b2
--- /dev/null
+++ b/usr/src/libpiny/share/ikiwiki.setup
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+# Configuration file for ikiwiki.
+# Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
+# build the wiki.
+#
+# Remember to re-run ikiwiki --setup any time you edit this file.
+
+use IkiWiki::Setup::Standard {
+ # wikiname => "', # LATER MODIFIED BY LATER MODIFIED BY PINY
+ # adminemail => "', # LATER MODIFIED BY LATER MODIFIED BY PINY
+ # srcdir => "', # LATER MODIFIED BY PINY
+ # destdir => "', # LATER MODIFIED BY PINY
+ # url => "', # LATER MODIFIED BY PINY
+ # cgiurl => "', # LATER MODIFIED BY PINY
+ # historyurl => "', # LATER MODIFIED BY PINY
+ # diffurl => "', # LATER MODIFIED BY PINY
+
+ templatedir => "/srv/templates", # TODO: user-customizable templates
+ underlaydir => "/etc/ikiwiki/share/underlay",
+
+ rcs => "git",
+ gitorigin_branch => "origin",
+ gitmaster_branch => "master",
+
+ # wrappers => [ ], controlled by piny
+
+ # Generate rss feeds for blogs?
+ rss => 1,
+ # Generate atom feeds for blogs?
+ atom => 0,
+ # Include discussion links on all pages?
+ discussion => 0,
+ # To exclude files matching a regexp from processing. This adds to
+ # the default exclude list.
+ #exclude => qr/*\.wav/,
+ # To change the extension used for generated html files.
+ #htmlext => "htm",
+ # Time format (for strftime)
+ #timeformat => "%c",
+ # Locale to use. Must be a UTF-8 locale.
+ #locale => "en_US.UTF-8",
+ # Only send cookies over SSL connections.
+ sslcookie => 1,
+ # Logging settings:
+ verbose => 0,
+ syslog => 1,
+ # To link to user pages in a subdirectory of the wiki.
+ #userdir => "users",
+ # To create output files named page.html rather than page/index.html.
+ usedirs => 1,
+ # Simple spam prevention: require an account-creation password.
+ #account_creation_password => "example",
+ # Use new "!"-prefixed preprocessor directive syntax
+ prefix_directives => 1,
+ httpauth => 1,
+ # To add plugins, list them here.
+ add_plugins => [qw{sidebar toc meta table tag graphviz httpauth img attachment rename remove map teximg version edittemplate}],
+ disable_plugins => [qw{openid passwordauth}],
+ teximg_prefix => "\\documentclass{scrartcl}
+\\usepackage[version=3]{mhchem}
+\\usepackage{amsmath}
+\\usepackage{amsfonts}
+\\usepackage{amssymb}
+\\pagestyle{empty}
+\\newcommand{\\unit}[1]{\\ensuremath{\\, \\mathrm{#1}}}
+\\begin{document}",
+
+ teximg_dvipng => 1,
+
+ # For use with the tag plugin, make all tags be located under a
+ # base page.
+ tagbase => "tag",
+
+ # For use with the search plugin if your estseek.cgi is located
+ # somewhere else.
+ #estseek => "/usr/lib/estraier/estseek.cgi",
+};
diff --git a/usr/src/pinyadmin/bin/lsaccess b/usr/src/pinyadmin/bin/lsaccess
index a5b5b12..b55900c 100755
--- a/usr/src/pinyadmin/bin/lsaccess
+++ b/usr/src/pinyadmin/bin/lsaccess
@@ -15,7 +15,7 @@ if ( defined $reponame ) {
foreach my $user ( Piny::User->all_users( ) ) {
if ( $repo->has_access( $user ) ) {
- print $user->username . "\n";
+ print $user->name . "\n";
};
};