vhost-stack/bin/vhost-user-jail.sh
Matthew Saunders Brown ce2a3470f4 removed shift
2021-09-17 11:48:51 -07:00

63 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# load include file
source $(dirname $0)/vhost.sh
help()
{
thisfilename=$(basename -- "$0")
echo "Jail specified user."
echo ""
echo "usage: $thisfilename username"
echo ""
echo " -h Print this help."
exit
}
# check for and set username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
username="${1,,}"
fi
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 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
mkdir -p /usr/jails/$username/opt /usr/jails/$username/usr/sbin /usr/jails/$username/tmp /usr/jails/$username/srv/www
ln -s /usr/local/sbin/mini_sendmail /usr/jails/$username/usr/sbin/sendmail
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
echo "/home/$username /usr/jails/$username/home/$username none bind 0 0" >> /etc/fstab.jails
killall jk_socketd
jk_socketd
jk_jailuser -n -j /usr/jails/$username -s /bin/bash $username