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 "Add virtualhost to this server."
|
|
|
|
echo ""
|
2023-04-16 10:50:42 -07:00
|
|
|
echo "usage: $thisfilename -d <domain> -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 " -d <domain> Domain name to add as a VirtualHost. www. subdomain is automatically aliased."
|
|
|
|
echo " -u <username> Username to install VirtualHost for. Username must already exist."
|
|
|
|
echo " If need be run vhost-user-add.sh first."
|
2021-10-03 12:16:40 -07:00
|
|
|
echo " Or use vhost-deploy.sh instead to automatically generate username."
|
2021-09-16 16:21:35 -07:00
|
|
|
}
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
vhost:getoptions "$@"
|
|
|
|
|
|
|
|
# check for domain (virtualhost)
|
|
|
|
if [[ -z $domain ]]; then
|
|
|
|
echo "domain is required"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check for username
|
|
|
|
if [[ -z $username ]]; then
|
|
|
|
echo "username is required"
|
|
|
|
exit
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
if [[ ! -d /home/$username ]]; then
|
2021-04-04 13:28:22 -07:00
|
|
|
echo "home dir for $username does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
if [[ -d /srv/www/$domain ]]; then
|
|
|
|
chown $username:$username /srv/www/$domain
|
|
|
|
chmod 755 /srv/www/$domain
|
2021-04-04 13:28:22 -07:00
|
|
|
else
|
2021-10-05 11:33:24 -07:00
|
|
|
install -d -o $username -g $username -m 755 /srv/www/$domain
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
if [[ -d /srv/www/$domain/html ]]; then
|
|
|
|
chown $username:$username /srv/www/$domain/html
|
|
|
|
chmod 755 /srv/www/$domain/html
|
2021-04-04 13:28:22 -07:00
|
|
|
else
|
2021-10-05 11:33:24 -07:00
|
|
|
install -d -o $username -g $username -m 755 /srv/www/$domain/html
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
if [[ ! -e /home/$username/$domain ]]; then
|
|
|
|
ln -s /srv/www/$domain /home/$username/$domain
|
|
|
|
chown -h $username:$username /home/$username/$domain
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-10-05 11:33:24 -07:00
|
|
|
if [[ -d /usr/jails/$username ]]; then
|
|
|
|
if [[ ! -d /usr/jails/$username/srv/www/$domain ]]; then
|
|
|
|
install -d -o $username -g $username -m 755 /usr/jails/$username/srv/www/$domain
|
|
|
|
mount --bind /srv/www/$domain /usr/jails/$username/srv/www/$domain
|
|
|
|
echo "/srv/www/$domain /usr/jails/$username/srv/www/$domain none bind 0 0" >> /etc/fstab.jails
|
2021-04-04 13:28:22 -07:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-04-16 10:50:42 -07:00
|
|
|
# set sendmail_path in php-fpm, but only if not already set
|
2024-03-28 14:27:46 -07:00
|
|
|
## disabled, now relying on defaults (user@fqdn) with .forward (/home/user/.forward)
|
|
|
|
## vhost::set-phpVersion
|
|
|
|
## if [[ -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
|
|
|
|
## if ! /bin/grep -q "^php_admin_value\[sendmail_path\]" /etc/php/$phpVersion/fpm/pool.d/$username.conf; then
|
|
|
|
## echo "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -fwebmaster@$domain" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
|
|
|
|
## fi
|
|
|
|
## fi
|
2021-04-04 13:28:22 -07:00
|
|
|
|
|
|
|
# create & enable apache config
|
2021-10-05 14:03:01 -07:00
|
|
|
/usr/local/bin/vhost-enable.sh -d $domain -m VHostHTTP
|