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")
|
|
|
|
echo "Remove user from this server."
|
|
|
|
echo ""
|
2021-10-05 11:33:24 -07:00
|
|
|
echo "usage: $thisfilename -u <username> [-h]"
|
2021-09-16 16:21:35 -07:00
|
|
|
echo ""
|
|
|
|
echo " -h Print this help."
|
2021-10-05 11:33:24 -07:00
|
|
|
echo " -u <username> System username to remove from server."
|
2021-09-16 16:21:35 -07:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
vhost:getoptions "$@"
|
|
|
|
|
|
|
|
# check for username
|
|
|
|
if [ -z "$username" ]; then
|
2021-04-04 13:28:22 -07:00
|
|
|
echo "username not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# check for jailed vhost mount
|
2022-08-03 15:47:17 -07:00
|
|
|
if /bin/grep -q " /usr/jails/$username/srv/www/" /etc/mtab; then
|
2021-04-04 13:28:22 -07:00
|
|
|
echo user \"$username\" has one or more jailed vhosts mounted
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-18 16:13:02 -07:00
|
|
|
# check for virtualhost jail mount(s) in fstab.jails
|
|
|
|
if /bin/grep -q " /usr/jails/$username/srv/www/" /etc/fstab.jails; then
|
2021-04-04 13:28:22 -07:00
|
|
|
echo user \"$username\" has one or more jailed vhost mounts
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# checks complete, start removing stuff
|
|
|
|
|
2024-09-18 12:35:55 -07:00
|
|
|
# check for php-fpm pool confs
|
|
|
|
vhost::set-phpVersionArray
|
|
|
|
for phpVersion in "${phpVersionArray[@]}"
|
|
|
|
do
|
|
|
|
if [[ -f "/etc/php/$phpVersion/fpm/pool.d/$username.conf" ]]; then
|
|
|
|
rm /etc/php/$phpVersion/fpm/pool.d/$username.conf
|
|
|
|
fi
|
|
|
|
done
|
2021-04-04 13:28:22 -07:00
|
|
|
|
|
|
|
# if users home dir is mounted in a jail, unmount it
|
2022-08-03 15:47:17 -07:00
|
|
|
if grep -q " /usr/jails/$username/home/$username " /etc/mtab; then
|
2021-04-04 13:28:22 -07:00
|
|
|
umount /usr/jails/$username/home/$username
|
|
|
|
fi
|
|
|
|
|
2021-08-18 16:13:02 -07:00
|
|
|
# if user home dir mount in fstab.jails exists remove it
|
|
|
|
if grep -q "^/home/$username /usr/jails/$username/home/$username " /etc/fstab.jails; then
|
|
|
|
sed -i "\|/home/$username /usr/jails/$username/home/$username|d" /etc/fstab.jails
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# delete user
|
|
|
|
/usr/sbin/userdel $username
|
|
|
|
|
|
|
|
# delete users home dir if it still exists
|
|
|
|
if [[ -d "/home/$username" ]]; then
|
|
|
|
rm -r /home/$username
|
|
|
|
fi
|
|
|
|
|
|
|
|
# delete users jail dir if it exists
|
|
|
|
if [[ -d "/usr/jails/$username" ]]; then
|
|
|
|
rm -r /usr/jails/$username
|
|
|
|
fi
|
|
|
|
|
|
|
|
# remove jailkit socket if it exists
|
|
|
|
if grep -q "\[/usr/jails/$username/dev/log\]" /etc/jailkit/jk_socketd.ini; then
|
2023-03-03 10:42:13 -08:00
|
|
|
sed -i "/\/usr\/jails\/$username\/dev\/log/,+3 d" /etc/jailkit/jk_socketd.ini
|
2023-05-20 12:08:08 -07:00
|
|
|
# remove trailing empty line from file, if it exists
|
|
|
|
sed -i '${/^$/d;}' /etc/jailkit/jk_socketd.ini
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|