vhost-stack/bin/vhost-user-destroy.sh

46 lines
1.1 KiB
Bash
Raw Normal View History

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
# load config
source /usr/local/etc/vhost.conf || echo "ERROR: Either you do not have vhost user permissions or the config file is missing." && exit
# check for and set username
if [ -n "$1" ]; then
username=$1
else
echo "username not set"
exit 1
fi
# First run a couple of basic checks. Redundant
# as user-del.sh run later does these same checks
# but prevents connecting to all nodes unnecessarily
if ! /bin/grep -q "^$username:" /etc/passwd; then
echo user \"$username\" does not exist
exit 1
fi
vhost::set-virtualhostArray
for v in "${virtualhostArray[@]}"
do
if [ $(stat -c '%U' /srv/www/$v) = $username ]; then
echo "$username has one or more installed virtualhosts ($v)"
exit 1
fi
done
# delete user from each node
vhost::set-clusterNodes all
for n in "${clusterNodes[@]}"
do
if [ $n = `hostname -s` ]; then
/usr/local/bin/user-del.sh $username
else
ssh $n.lan "/usr/local/bin/user-del.sh $username"
fi
done