#!/bin/bash # # vhost-stack # https://git.stack-source.com/msb/vhost-stack # MIT License Copyright (c) 2021 Matthew Saunders Brown # load include file source $(dirname $0)/vhost.sh help() { thisfilename=$(basename -- "$0") echo "Remove MySQL database and associated db user for the specified virtualhost." echo "" echo "usage: $thisfilename -d " echo "" echo " -h Print this help." echo " -d Domain name of VirtualHost to delete MySQL db for." exit } vhost:getoptions "$@" # check for domain (virtualhost) if [[ -z $domain ]]; then echo "domain is required" exit fi # set database name database=${domain//./dot} database=${database//-/dash} # drop database mysql -e "DROP DATABASE IF EXISTS $database;" # set default username and attempt to drop user if [ -d /srv/www/$domain ]; then vhost_username=$(stat -c '%U' /srv/www/$domain) username=$vhost_username@$domain mysql -e "DROP USER IF EXISTS '$username'@'localhost';" mysqladmin flush-privileges fi