summaryrefslogtreecommitdiff
path: root/usr/src/pinyadmin/sbin/rmrepo
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2010-03-18 13:56:03 -0700
committerJulian Blake Kongslie <jblake@omgwallhack.org>2010-03-18 13:56:03 -0700
commitab08391a42cb9a8e0d9023525f60f73ef848d17e (patch)
tree565f60e4a48dd5ac98e319ee222ee7f486424bab /usr/src/pinyadmin/sbin/rmrepo
parent311d67a43ba7958c327d60a13e040a51cbb94139 (diff)
downloadpiny-code-ab08391a42cb9a8e0d9023525f60f73ef848d17e.tar.gz
piny-code-ab08391a42cb9a8e0d9023525f60f73ef848d17e.zip
Moved the various administrative scripts into Debian packaging.
Diffstat (limited to 'usr/src/pinyadmin/sbin/rmrepo')
-rwxr-xr-xusr/src/pinyadmin/sbin/rmrepo64
1 files changed, 64 insertions, 0 deletions
diff --git a/usr/src/pinyadmin/sbin/rmrepo b/usr/src/pinyadmin/sbin/rmrepo
new file mode 100755
index 0000000..864830f
--- /dev/null
+++ b/usr/src/pinyadmin/sbin/rmrepo
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my( $reponame, $uid, $gitowner, $wikilisttempfile, $cgitrctempfile);
+
+if ( ( ! scalar $ARGV[0] ) or ( scalar $ARGV[1] ) or ( $ARGV[0] !~ /^[a-z0-9][a-z0-9-]+$/ ) ) {
+ print( "Usage: rmrepo REPONAME\n" );
+ exit( 1 );
+} else {
+ $reponame = $ARGV[0];
+};
+
+open (PASSWD, '/etc/passwd');
+while(<PASSWD>) {
+ if( $_ =~ /^$ENV{SUDO_USER}:.+?:(.+?):/ ) { $uid = $1; }; # grabbing uid.
+};
+close(PASSWD);
+
+unless( -d "/srv/git/$reponame.git" ) {
+ print( "/srv/git/$reponame.git doesn't exist!\n" );
+ exit( 2 );
+};
+
+$gitowner = (stat "/srv/git/$reponame.git")[4];
+
+if( ( $gitowner != $uid ) and ( $gitowner != 65534 ) ) {
+ print( "$reponame is not owned by you!\n" );
+ exit( 3 );
+};
+
+# We have to be careful about how we delete things; we don't want have post-update or ikiwiki.cgi thrashing, and we REALLY don't want to leave remappable owner UIDs around, but we're also keying security on /srv/git/$reponame
+system( "/bin/chown -R nobody.nogroup /srv/git/$reponame.git" );
+
+unlink( "/etc/ikiwiki/wikilist.d/$reponame" );
+$wikilisttempfile = `/bin/mktemp`;
+chomp ( $wikilisttempfile );
+chmod ( 0644, $wikilisttempfile );
+system( "/bin/cat /etc/ikiwiki/wikilist.d/* > $wikilisttempfile" );
+system( "/bin/mv $wikilisttempfile /etc/ikiwiki/wikilist" ); # This is marginally racy, but the consequences are probably ignorable.
+
+unlink( "/etc/cgitrc.d/$reponame" );
+$cgitrctempfile = `/bin/mktemp`;
+chomp ( $cgitrctempfile );
+chmod ( 0644, $cgitrctempfile );
+system( "/bin/cat /etc/cgitrc.d/* > $cgitrctempfile" );
+system( "/bin/mv $cgitrctempfile /etc/cgitrepos" ); # This is marginally racy, but the consequences are probably ignorable.
+
+system( "/bin/rm -r /srv/www/piny.be/$reponame" );
+system( "/bin/rm -r /srv/www/secure.piny.be/repos/$reponame" );
+
+unlink( "/etc/ikiwiki/piny/$reponame.setup" );
+system( "/bin/rm -r /srv/ikiwiki/$reponame" );
+
+unlink( "/etc/apache2/piny-available/$reponame" );
+unlink( "/etc/apache2/piny-enabled/$reponame" );
+system( '/etc/init.d/apache2 reload | grep -v "Reloading web server config: apache2."' );
+
+system( "/usr/sbin/delgroup --quiet git-$reponame" );
+system( "/usr/sbin/deluser --quiet --remove-home ikiwiki-$reponame" );
+system( "/usr/sbin/delgroup --quiet ikiwiki-$reponame" );
+
+system( "/bin/rm -rf /srv/git/$reponame.git" );