#!/bin/bash #set the umask so temporary files are unreadable umask 077 delaccount() { echo "OK, I'm deleting, and there's nothing you can do about it." grep -v $VIRTHOST /etc/init.d/virthosts > /tmp/$$.virthosts cp /etc/apache/httpd.conf /tmp/$$.httpd.conf FIRSTLINE=`grep -n "START $VIRTHOST" /etc/apache/httpd.conf | tr ':' ' ' | awk '{print($1)}'` LASTLINE=`echo "$FIRSTLINE + 12" | bc` while [ $FIRSTLINE -le $LASTLINE ]; do sed ${FIRSTLINE}D < /tmp/$$.httpd.conf > /tmp/$$.httpd.conf.2 mv /tmp/$$.httpd.conf.2 /tmp/$$.httpd.conf LASTLINE=`echo "$LASTLINE - 1" | bc` done mv /tmp/$$.virthosts /etc/init.d/virthosts mv /tmp/$$.httpd.conf /etc/apache/httpd.conf userdel $DOMUSER rm -r /var/www/docs/$VIRTHOST ifconfig eth0:$DUMMY down } while [ "$VIRTHOST" == "" ]; do echo "Host to delete." echo " Please include the www. if present." echo " For a list of hosts, enter 'list'" echo " To give up, enter 'exit'" echo -n " : " read VIRTHOST if [ "$VIRTHOST" == "list" ]; then grep "START " /etc/apache/httpd.conf | awk '{print($3)}' | less VIRTHOST="" fi if [ "$VIRTHOST" == "exit" ]; then exit fi done DOMUSER=`grep "START $VIRTHOST" /etc/apache/httpd.conf | awk '{print($5)}'` DUMMY=`grep "$VIRTHOST" /etc/init.d/virthosts | tr ':' ' ' | awk '{print($3)}'` clear echo echo "Hostname is: $VIRTHOST" echo "Username is: $DOMUSER" echo "dummy interface: $DUMMY" quota $DOMUSER echo -n "Is this the account to delete? [N/yes]: " read YESNO if [ "$YESNO" == "yes" ]; then echo -n "ARE YOU SURE? YOU CANNOT UNDO THIS! [N/yes]: " read YESNO if [ "$YESNO" == "yes" ]; then delaccount else echo "Man, I bet you are glad I asked!" fi else echo "OK, aborting without making any changes..." fi