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 "Jail specified user."
|
|
|
|
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 jail."
|
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 ! 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
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
if [[ -d /usr/jails/$username ]]; then
|
2021-04-04 13:28:22 -07:00
|
|
|
echo "/usr/jails/$username already exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if grep -q ":/usr/jails/$username/./home/$username:" /etc/passwd; then
|
|
|
|
echo "$username already has jail home dir set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
jk_init -k -j /usr/jails/$username shellstack
|
2021-04-15 10:01:11 -07:00
|
|
|
mkdir -p /usr/jails/$username/opt /usr/jails/$username/usr/sbin /usr/jails/$username/tmp /usr/jails/$username/srv/www
|
2021-04-15 09:31:24 -07:00
|
|
|
ln -s /usr/local/sbin/mini_sendmail /usr/jails/$username/usr/sbin/sendmail
|
2021-04-04 13:28:22 -07:00
|
|
|
chmod a+rwx /usr/jails/$username/tmp
|
|
|
|
install -d -o $username -g $username -m 755 /usr/jails/$username/home/$username
|
|
|
|
mount --bind /home/$username /usr/jails/$username/home/$username
|
2021-08-18 16:13:02 -07:00
|
|
|
echo "/home/$username /usr/jails/$username/home/$username none bind 0 0" >> /etc/fstab.jails
|
2021-04-04 13:28:22 -07:00
|
|
|
jk_jailuser -n -j /usr/jails/$username -s /bin/bash $username
|
2024-09-18 12:35:55 -07:00
|
|
|
|
|
|
|
# configure chroot for php-fpm
|
|
|
|
vhost::set-phpVersionArray
|
|
|
|
for phpVersion in "${phpVersionArray[@]}"
|
|
|
|
do
|
|
|
|
if [[ -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
|
|
|
|
if ! /bin/grep -q "^chroot" /etc/php/$phpVersion/fpm/pool.d/$username.conf; then
|
|
|
|
echo "chroot = /usr/jails/$username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|