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
|
|
|
|
|
|
|
# check for and set username
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
username=$1
|
|
|
|
else
|
|
|
|
echo "username not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -q "^$username:" /etc/passwd; then
|
|
|
|
echo "$username is not installed on this server"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d /home/$username ]]; then
|
|
|
|
echo "/home/$username does not exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d "/usr/jails/$username" ]]; then
|
|
|
|
echo "/usr/jails/$username does not exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -q ":/usr/jails/$username/./home/$username:" /etc/passwd; then
|
|
|
|
echo "$username does not have jail home dir set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if any virtualhosts exist
|
|
|
|
if [ "$(ls -A /usr/jails/$username/var/www)" ]; then
|
|
|
|
# set virtualhosts array
|
|
|
|
cd /usr/jails/$username/srv/www/
|
|
|
|
virtualhosts=(*)
|
|
|
|
# unmount virtualhost dir(s)
|
|
|
|
for virtualhost in "${!virtualhosts[@]}"
|
|
|
|
do
|
|
|
|
virtualhost=${virtualhosts[$virtualhost]}
|
|
|
|
echo umount /usr/jails/$username/srv/www/$virtualhost
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# unmount jail home dir
|
|
|
|
echo umount /usr/jails/$username/home/$username
|
|
|
|
|
|
|
|
# del jail dir
|
|
|
|
echo rm -r /usr/jails/$username
|
|
|
|
|
|
|
|
# (re)create jail
|
|
|
|
echo jk_init -k -j /usr/jails/$username shellstack
|
|
|
|
echo mkdir -p /usr/jails/$username/opt /usr/jails/$username/usr/sbin /usr/jails/$username/tmp /usr/jails/$username/var/www
|
|
|
|
echo ln -s /usr/local/bin/mini_sendmail /usr/jails/$username/usr/sbin/sendmail
|
|
|
|
echo chmod a+rwx /usr/jails/$username/tmp
|
|
|
|
echo install -d -o $username -g $username -m 755 /usr/jails/$username/home/$username
|
|
|
|
echo jk_jailuser -n -j /usr/jails/$username -s /bin/bash $username
|
|
|
|
|
|
|
|
# remount dirs
|
|
|
|
echo mount /usr/jails/$username/home/$username
|
|
|
|
virtualhostcount=${#virtualhosts[@]}
|
|
|
|
if [ "$virtualhostcount" -gt 0 ]; then
|
|
|
|
for virtualhost in "${!virtualhosts[@]}"
|
|
|
|
do
|
|
|
|
virtualhost=${virtualhosts[$virtualhost]}
|
|
|
|
echo install -d -o $username -g $username -m 755 /usr/jails/$username/srv/www/$virtualhost
|
|
|
|
echo mount /usr/jails/$username/srv/www/$virtualhost
|
|
|
|
done
|
|
|
|
fi
|