2021-04-04 13:28:22 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# vhost-stack
|
|
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
|
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")
|
|
|
|
echo "Remove virtualhost and associated user & database & db user from this server."
|
|
|
|
echo ""
|
|
|
|
echo "usage: $thisfilename virtualhost"
|
|
|
|
echo ""
|
|
|
|
echo " -h Print this help."
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2021-04-04 13:28:22 -07:00
|
|
|
# check for and set virtualhost
|
|
|
|
if [ -n "$1" ]; then
|
2021-09-16 16:21:35 -07:00
|
|
|
if [ $1 == "-h" ]; then
|
|
|
|
help
|
|
|
|
elif [ ! -d /srv/www/$1 ]; then
|
|
|
|
echo "virtualhost dir does not exist"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
virtualhost="${1,,}"
|
|
|
|
shift
|
|
|
|
fi
|
2021-04-04 13:28:22 -07:00
|
|
|
else
|
2021-09-16 16:21:35 -07:00
|
|
|
help
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-09-16 16:21:35 -07:00
|
|
|
# check for database and delete if it exists
|
|
|
|
database=${virtualhost//./dot}
|
|
|
|
database=${database//-/dash}
|
|
|
|
if [ -d /var/lib/mysql/$database ]; then
|
|
|
|
/usr/local/bin/vhost-mysql-db-del.sh $virtualhost
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-09-16 16:21:35 -07:00
|
|
|
# get & set username for this virtualhost
|
|
|
|
username=$(stat -c '%U' /srv/www/$virtualhost)
|
2021-04-04 13:28:22 -07:00
|
|
|
|
2021-09-16 16:21:35 -07:00
|
|
|
# check for a delete varnish config
|
|
|
|
|
|
|
|
# del virtualhost files & configs
|
2021-08-14 13:04:46 -07:00
|
|
|
/usr/local/bin/vhost-del.sh $virtualhost
|
2021-04-04 13:28:22 -07:00
|
|
|
|
2021-09-16 16:21:35 -07:00
|
|
|
# check for any remaining virtualhosts before deleting user
|
|
|
|
# same check is done in vhost-user-del.sh
|
|
|
|
# but doing this here avoids generating any errors
|
|
|
|
existingvirtualhosts=false
|
|
|
|
vhost::set-virtualhostArray
|
|
|
|
for v in "${virtualhostArray[@]}"
|
|
|
|
do
|
|
|
|
if [ $(stat -c '%U' /srv/www/$v) = $username ]; then
|
|
|
|
existingvirtualhosts=true
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $existingvirtualhosts = false ]]; then
|
2021-08-14 13:04:46 -07:00
|
|
|
/usr/local/bin/vhost-user-del.sh $username
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|