2021-04-04 13:28:22 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# vhost-stack
|
|
|
|
# https://git.stack-source.com/msb/vhost-stack
|
2022-08-22 13:22:16 -07:00
|
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2021-04-04 13:28:22 -07:00
|
|
|
|
2021-04-04 14:15:16 -07:00
|
|
|
# load include file
|
|
|
|
source $(dirname $0)/vhost.sh
|
2021-04-04 13:28:22 -07:00
|
|
|
|
2021-09-16 16:21:35 -07:00
|
|
|
help()
|
|
|
|
{
|
|
|
|
thisfilename=$(basename -- "$0")
|
2022-07-18 19:11:44 -07:00
|
|
|
echo "Remove MySQL database and associated db user for the specified virtualhost."
|
2021-09-16 16:21:35 -07:00
|
|
|
echo ""
|
2021-10-05 11:33:24 -07:00
|
|
|
echo "usage: $thisfilename -d <domain>"
|
2021-09-16 16:21:35 -07:00
|
|
|
echo ""
|
|
|
|
echo " -h Print this help."
|
2022-07-18 19:11:44 -07:00
|
|
|
echo " -d <domain> Domain name of VirtualHost to delete MySQL db for."
|
2021-09-16 16:21:35 -07:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
vhost:getoptions "$@"
|
|
|
|
|
|
|
|
# check for domain (virtualhost)
|
|
|
|
if [[ -z $domain ]]; then
|
|
|
|
echo "domain is required"
|
|
|
|
exit
|
2021-09-16 16:21:35 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# set database name
|
2022-03-11 08:50:19 -08:00
|
|
|
database=${domain//./dot}
|
2021-09-16 16:21:35 -07:00
|
|
|
database=${database//-/dash}
|
|
|
|
|
|
|
|
# drop database
|
|
|
|
mysql -e "DROP DATABASE IF EXISTS $database;"
|
|
|
|
|
|
|
|
# set default username and attempt to drop user
|
2021-10-05 11:33:24 -07:00
|
|
|
if [ -d /srv/www/$domain ]; then
|
|
|
|
vhost_username=$(stat -c '%U' /srv/www/$domain)
|
|
|
|
username=$vhost_username@$domain
|
2021-09-16 16:21:35 -07:00
|
|
|
mysql -e "DROP USER IF EXISTS '$username'@'localhost';"
|
|
|
|
mysqladmin flush-privileges
|
|
|
|
fi
|