#!/bin/bash WEBROOT="/var/www" DATASHEETS="/root/datasheets" function checkwait { read -p "Continue? Press Ctrl+C to cancel." END } read -p "Name of the user which should be deleted: " USER WEBDIR="$WEBROOT/$USER" if [ "$USER" == "" ]; then echo "User is empty. Abort." exit 1 elif [ $(grep -q "$USER" /etc/passwd; echo $?) == "1" ]; then echo "User does not exist. Abort." exit 1 fi echo "[INFO] Deleting website..." chattr -i -V $WEBDIR/php-fcgi/php-fcgi-starter rm -rf $WEBDIR rm -f /etc/apache2/sites-available/$USER.conf a2dissite $USER.conf service apache2 restart echo "[INFO] Deleting MySQL databases and user..." echo "DROP DATABASE $USER;" | mysql echo "DROP USER '$USER'@'localhost';" | mysql echo "[INFO] Deleting datasheets..." rm -f $DATASHEETS/datasheet-$USER.* rm -f /var/share/teachers/datasheet-$USER.pdf echo "[INFO] Deleting user and all its files from system..." deluser --remove-home $USER groupdel $USER echo "[INFO] Done."