diff options
Diffstat (limited to 'libpiny/lib/Piny/Repo.pm')
-rw-r--r-- | libpiny/lib/Piny/Repo.pm | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/libpiny/lib/Piny/Repo.pm b/libpiny/lib/Piny/Repo.pm index f4154da..134894c 100644 --- a/libpiny/lib/Piny/Repo.pm +++ b/libpiny/lib/Piny/Repo.pm @@ -211,19 +211,19 @@ sub has_access { sub rebuild { my ( $s ) = @_; + $s->rebuild_git; + $s->rebuild_ikiwiki; +}; + +sub rebuild_git { + my ( $s ) = @_; + unless( getgrnam("git-" . $s->shortname ) ) { system( "/usr/sbin/addgroup", "--quiet", "git-" . $s->shortname ) and die "Could not create repo group!"; system( "/usr/sbin/adduser", "--quiet", $s->owner->name, "git-" . $s->shortname ) and die "Could not add you to the repo group!"; - system( "/usr/sbin/adduser", "--quiet", "iki-" . $s->shortname, "git-" . $s->shortname ) and print "...But that's probably okay.\n"; - }; - - 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 print "...But that's okay.\n"; }; - my $ikiuser = Piny::User::IkiWiki->new( "name" => "iki-" . $s->shortname ); - foreach( "git-daemon-export-ok", "packed-refs" ) { unless( -e $s->path . "/" . $_ ) { open( TOUCH, ">", $s->path . "/" . $_ ) or die "Could not touch $_ for repo: $!"; @@ -231,16 +231,32 @@ sub rebuild { }; }; + chown( 0, 0, $s->path, $s->path . "/config" ) or die "Could not change ownership of git config!"; + foreach( "info", "logs", "branches" ) { (-e $s->path . "/" . $_) or mkdir( $s->path . "/" . $_ ) or die "Could not mkdir $_ for repo: $!"; }; - chown( 0, 0, $s->path, $s->path . "/config" ) or die "Could not change ownership of git dir!"; - foreach( "branches", "description", "HEAD", "info", "logs", "objects", "packed-refs", "refs" ) { system( "/bin/chown", "-R", $s->owner->name . "." . $s->group->name, $s->path . "/" . $_ ) and die "Could not change ownership of $_ for repo: $!"; }; + $ENV{"GIT_DIR"} = $s->path; + system( "/usr/bin/git", "config", "gitweb.owner", $s->owner->email->address ) and die "Could not git config gitweb.owner!"; + delete $ENV{"GIT_DIR"}; + +}; + +sub rebuild_ikiwiki { + my ( $s ) = @_; + + 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!"; + }; + + 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!"; open( SETUP, ">", "/etc/ikiwiki/piny/" . $s->name . ".setup" ) or die "Could not open new ikiwiki setup file: $!"; @@ -279,10 +295,6 @@ sub rebuild { rename( $temp->filename, "/etc/ikiwiki/wikilist" ) or die "Could not rename over old wikilist: $!"; - $ENV{"GIT_DIR"} = $s->path; - system( "/usr/bin/git", "config", "gitweb.owner", $s->owner->email->address ) and die "Could not git config gitweb.owner!"; - delete $ENV{"GIT_DIR"}; - 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: $!"; @@ -382,10 +394,17 @@ sub create { mkdir( $repo->path ) or die "The repo $name appears to already exist! ($!)"; $ENV{"GIT_DIR"} = $repo->path; - system( "/usr/bin/git", "init", "--template=/srv/git-template.git", "--quiet", "--shared" ) and die "Could not initialize git repo!"; - system( "/bin/chown", "-R", $user->name, $repo->path . "/objects" ) and die "Could not change ownership of $_ for repo: $!"; + system( "/usr/bin/git", "init", "--bare", "--quiet", "--shared" ) and die "Could not initialize git repo!"; delete $ENV{"GIT_DIR"}; +# if source repo is defined { +# $ENV{"GIT_DIR"} = $source; +# system( "/usr/bin/git", "push", "--mirror", $repo->path ) and die "Could not push refs to new repository!"; +# delete $ENV{"GIT_DIR"}; +# } + + system( "/bin/chown", "-R", $user->name, $repo->path . "/objects" ) and die "Could not change ownership of $_ for repo: $!"; + $repo->description( $description ); $repo->rebuild; |