diff options
author | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-10-13 20:43:12 -0700 |
---|---|---|
committer | jblake+piny@omgwallhack.org <jblake@omgwallhack.org> | 2010-10-13 20:43:12 -0700 |
commit | 2f862e33447446116907c60ba1142369f70a99ab (patch) | |
tree | da7ed59f81ba22a8347f3fcc4802aa23bbb3169b /usr | |
parent | ca2a5d4df51dec985d00802426dc5f8fa47734d8 (diff) | |
download | piny-code-2f862e33447446116907c60ba1142369f70a99ab.tar.gz piny-code-2f862e33447446116907c60ba1142369f70a99ab.zip |
Rebuilding repo configs.
Diffstat (limited to 'usr')
-rw-r--r-- | usr/src/libpiny/debian/changelog | 6 | ||||
-rw-r--r-- | usr/src/libpiny/lib/Piny/Repo.pm | 70 | ||||
-rw-r--r-- | usr/src/pinyadmin/debian/control | 2 | ||||
-rw-r--r-- | usr/src/pinyadmin/doc/rebuildrepo.latex | 16 | ||||
-rw-r--r-- | usr/src/pinyadmin/doc/rmrepo.latex | 2 | ||||
-rwxr-xr-x | usr/src/pinyadmin/sbin/rebuildrepo | 14 |
6 files changed, 108 insertions, 2 deletions
diff --git a/usr/src/libpiny/debian/changelog b/usr/src/libpiny/debian/changelog index 777bb27..e97c2fe 100644 --- a/usr/src/libpiny/debian/changelog +++ b/usr/src/libpiny/debian/changelog @@ -1,3 +1,9 @@ +libpiny-perl (0.14) unstable; urgency=low + + * Support rebuilding a repo's config. + + -- Julian Blake Kongslie <jblake@omgwallhack.org> Wed, 13 Oct 2010 20:38:15 -0700 + libpiny-perl (0.13) unstable; urgency=low * Vastly overhauled the config stuff. diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm index ca8ae07..598760e 100644 --- a/usr/src/libpiny/lib/Piny/Repo.pm +++ b/usr/src/libpiny/lib/Piny/Repo.pm @@ -193,6 +193,76 @@ sub has_access { return $s->owner->uid == $user->uid || $user->has_group( $s->group ); }; +sub rebuild { + my ( $s ) = @_; + + my $ikiuser = Piny::User::IkiWiki->new( "name" => "ikiwiki-" . $s->name ); + + open( TOUCH, ">", $s->path . "/git-daemon-export-ok" ) or die "Could not touch git-daemon-export-ok for repo: $!"; + close( TOUCH ); + + system( "/bin/chown", "-R", $s->owner->name . "." . $s->group->name, $s->path ) and die "Could not change ownership of git repo!"; + 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: $!"; + print SETUP $s->ikiwiki_setup; + close( SETUP ) or die "Could not close new ikiwiki setup file: $!"; + + system( "/bin/chown", "-R", $ikiuser->name . "." . $ikiuser->name, $s->ikiwiki_srcdir, $s->ikiwiki_destdir, $s->secure_path ) and die "Could not change ownership of ikiwiki directories!"; + + open( WIKILIST, ">", "/etc/ikiwiki/wikilist.d/" . $s->name ) or die "Could not create wikilist.d file: $!"; + print WIKILIST $ikiuser->name . " /etc/ikiwiki/piny/" . $s->name . ".setup\n"; + close( WIKILIST ) or die "Could not close wikilist.d file: $!"; + + my $temp = File::Temp->new( ) or die "Could not create temporary file: $!"; + $temp->unlink_on_destroy( 0 ); + + my $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: $!"; + + open( CGITLIST, ">", "/etc/cgitrc.d/" . $s->name ) or die "Could not create cgitrc.d file: $!"; + print CGITLIST "repo.url=" . $s->name . "\nrepo.path=" . $s->path . "\nrepo.desc=" . $s->description . "\nrepo.owner=" . $s->owner->email->address . "\n\n"; + close( CGITLIST ) or die "Could not close cgitrc.d file: $!"; + + $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: $!"; + + 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: $!"; + print APACHE $s->apache_config; + close( APACHE ) or die "Could not close new apache config: $!"; + + symlink( "/etc/apache2/piny-available/" . $s->name, "/etc/apache2/piny-enabled/" . $s->name ) or die "Could not symlink apache config: $!"; + + system( "/etc/init.d/apache2", "reload" ) and die "Could not reload apache config!"; +}; + sub destroy { my ( $s ) = @_; diff --git a/usr/src/pinyadmin/debian/control b/usr/src/pinyadmin/debian/control index db838bd..e8c2d70 100644 --- a/usr/src/pinyadmin/debian/control +++ b/usr/src/pinyadmin/debian/control @@ -7,7 +7,7 @@ Standards-version: 3.8.4 Package: pinyadmin Architecture: all -Depends: ${perl:Depends}, ${misc:Depends}, libpiny-perl (>= 0.13), moreutils +Depends: ${perl:Depends}, ${misc:Depends}, libpiny-perl (>= 0.14), moreutils Description: Administrative programs for piny The command-line programs for day-to-day administrative tasks in the Piny infrastructure. diff --git a/usr/src/pinyadmin/doc/rebuildrepo.latex b/usr/src/pinyadmin/doc/rebuildrepo.latex new file mode 100644 index 0000000..a2e0935 --- /dev/null +++ b/usr/src/pinyadmin/doc/rebuildrepo.latex @@ -0,0 +1,16 @@ +\usepackage{latex2man} + +\begin{Name}{8piny}{rebuildrepo}{Piny Team}{Piny}{rebuildrepo} + +\Prog{rebuildrepo} - rebuild a repo configuration + +\section{Synopsis} + +\Prog{rebuildrepo} \Arg{reponame} \Dots + +\section{Description} + +The \Prog{rebuildrepo} command rewrites all of the configuration files for +the given repo and adjusts ownership and group membership of its files to a +normalized state. It is needed to propagate certain kinds of changes; +normally only the system administrator should run it. diff --git a/usr/src/pinyadmin/doc/rmrepo.latex b/usr/src/pinyadmin/doc/rmrepo.latex index a820d8f..12b58df 100644 --- a/usr/src/pinyadmin/doc/rmrepo.latex +++ b/usr/src/pinyadmin/doc/rmrepo.latex @@ -6,7 +6,7 @@ \section{Synopsis} -\Prog{rmrepo} \Arg{reponame} +\Prog{rmrepo} \Arg{reponame} \Dots \section{Description} diff --git a/usr/src/pinyadmin/sbin/rebuildrepo b/usr/src/pinyadmin/sbin/rebuildrepo new file mode 100755 index 0000000..9d4e359 --- /dev/null +++ b/usr/src/pinyadmin/sbin/rebuildrepo @@ -0,0 +1,14 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +foreach my $reponame ( @ARGV ) { + + my $repo = Piny::Repo->new( $reponame ); + + $repo->rebuild; + +}; |