From 1e0fde1688055de6ddd42da658af43546ee90871 Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Sun, 21 Jan 2018 01:51:27 -0800 Subject: Piny::Repo: Initial read-only repository support. Not all systems want us to manage git repositories: we can still provide ikiwiki/apache support for existing read-only repositories. This would probably be better done with some sort of configuration variable, but a simple access() W_OK writability check will have to do for now. --- libpiny/lib/Piny/Repo.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libpiny/lib/Piny/Repo.pm b/libpiny/lib/Piny/Repo.pm index ffdd9fb..d59ad7e 100644 --- a/libpiny/lib/Piny/Repo.pm +++ b/libpiny/lib/Piny/Repo.pm @@ -16,6 +16,7 @@ use File::Find qw( find ); use File::Temp qw( ); use IO::Dir qw( ); use Math::GMP qw( ); +use POSIX qw( ); use IkiWiki::FakeSetup qw( readSetup writeSetup ); @@ -227,7 +228,11 @@ sub has_access { sub rebuild { my ( $s ) = @_; - $s->rebuild_git; + if( POSIX::access( $s->path, &POSIX::W_OK ) ){ + $s->rebuild_git; + } else { + warn "Read-only git repository detected. Skipping git rebuild."; + }; $s->rebuild_apache; $s->destroy_ikiwiki; @@ -342,12 +347,12 @@ sub rebuild_ikiwiki { unless( getpwnam("iki-" . $s->shortname ) ) { system( "/usr/sbin/adduser", "--quiet", "--system", "--group", "--gecos", $s->shortname, "iki-" . $s->shortname ) and die "Could not create ikiwiki user!"; - system( "/usr/sbin/adduser", "--quiet", "iki-" . $s->shortname, "git-" . $s->shortname ) and die "Could not add ikiwiki user to the repo group!"; + system( "/usr/sbin/adduser", "--quiet", "iki-" . $s->shortname, "git-" . $s->shortname ) and warn "Could not add ikiwiki user to the repo group!"; }; my $ikiuser = Piny::User::IkiWiki->new( "name" => "iki-" . $s->shortname ); - system( "/bin/chown", "-R", $ikiuser->name . "." . $ikiuser->name, $s->path . "/hooks" ) and die "Could not change ownership of git hooks!"; + system( "/bin/chown", $ikiuser->name . "." . $ikiuser->name, $s->path . "/hooks" ) and warn "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; -- cgit v1.2.3