47 lines
1013 B
Bash
Executable File
47 lines
1013 B
Bash
Executable File
#!/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 default db user for the specified virtualhost."
|
|
echo ""
|
|
echo "usage: $thisfilename virtualhost."
|
|
echo ""
|
|
echo " -h Print this help."
|
|
exit
|
|
}
|
|
|
|
# check for and set virtualhost.
|
|
if [ -n "$1" ]; then
|
|
if [ $1 == "-h" ]; then
|
|
help
|
|
else
|
|
virtualhost="${1,,}"
|
|
fi
|
|
else
|
|
echo "virtualhost not set"
|
|
exit 1
|
|
fi
|
|
|
|
# set database name
|
|
database=${virtualhost//./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/$virtualhost ]; then
|
|
vhost_username=$(stat -c '%U' /srv/www/$virtualhost)
|
|
username=$vhost_username@$virtualhost
|
|
mysql -e "DROP USER IF EXISTS '$username'@'localhost';"
|
|
mysqladmin flush-privileges
|
|
fi
|