From 29355a1653a12742928ce563e4c077a77f67c9f9 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 6 Sep 2009 04:26:13 -0700 Subject: Import of unversioned piny code. --- usr/local/sbin/rmrepo | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 usr/local/sbin/rmrepo (limited to 'usr/local/sbin/rmrepo') diff --git a/usr/local/sbin/rmrepo b/usr/local/sbin/rmrepo new file mode 100755 index 0000000..3905412 --- /dev/null +++ b/usr/local/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() { + 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 ); +system( "/bin/cat /etc/ikiwiki/wikilist.d/* > $wikilisttempfile" ); +chmod ( 0644, $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 ); +system( "/bin/cat /etc/cgitrc.d/* > $cgitrctempfile" ); +chmod ( 0644, $cgitrctempfile ); +system( "/bin/mv $cgitrctempfile /etc/cgitrepos" ); # This is marginally racy, but the consequences are probably ignorable. + +system( "/bin/rm -r /srv/www/piny.svcs.cs.pdx.edu/$reponame" ); +system( "/bin/rm -r /srv/www/cgi.piny.svcs.cs.pdx.edu/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" ); -- cgit v1.2.3