vhost-stack/bin/vhost-cgi-wrap.sh

94 lines
2.6 KiB
Bash
Raw Permalink Normal View History

2022-04-26 15:58:13 -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)
2022-04-26 15:58:13 -07:00
# load include file
source $(dirname $0)/vhost.sh
help()
{
thisfilename=$(basename -- "$0")
echo "Create CGI Wrapper for virtualhost."
echo ""
echo "usage: $thisfilename --d <domain> [-h]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to create cgi-wrapper for."
exit
}
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
if [[ -d "/srv/www/$domain" ]]; then
# get and set $username
username=$(stat -c '%U' /srv/www/$domain)
else
echo "VirtualHost dir for $domain does not exist."
exit 1
fi
if [[ -f /usr/local/lib/cgi-wrap/$domain/cgiwrap ]]; then
echo "cgi-wrapper for $domain already exists"
exit 1
fi
if ! grep -q ":/usr/jails/$username/./home/$username:" /etc/passwd; then
echo "$username must be jailed before creating cgi-wrapper."
exit 1
fi
if [[ -d /usr/jails/$username ]]; then
if [[ ! -d /usr/jails/$username/usr/jails/$username/ ]]; then
mkdir -p /usr/jails/$username/usr/jails/$username/
cd /usr/jails/$username/usr/jails/$username/
ln -s /home ./home
fi
else
echo "Jail dir for $username does not exist."
exit 1
fi
2022-04-27 10:18:31 -07:00
if [[ ! -d /srv/www/$domain/cgi-bin ]]; then
install --owner=$username --group=$username --mode=755 --directory /srv/www/$domain/cgi-bin
fi
2022-04-26 15:58:13 -07:00
if [[ ! -d /usr/local/lib/cgi-wrap/$domain ]]; then
mkdir -p /usr/local/lib/cgi-wrap/$domain
fi
cd /usr/local/src
if [[ -d cgiwrap-4.1 ]]; then
rm -r cgiwrap-4.1
fi
if [[ ! -f cgiwrap-4.1.tar.gz ]]; then
wget --quiet https://github.com/cgiwrap/cgiwrap/releases/download/cgiwrap-4.1/cgiwrap-4.1.tar.gz
fi
if [[ -f cgiwrap-4.1.tar.gz ]]; then
tar zxf cgiwrap-4.1.tar.gz
else
echo "cgiwrap-4.1.tar.gz does not exist and failed to download"
exit 1
fi
cd cgiwrap-4.1
./configure --with-chroot=/usr/jails/$username --with-rlimit-core=0 --with-rlimit-cpu=60 --without-redirect-stderr --without-logging-file --with-httpd-user=www-data --with-cgi-dir=$domain/cgi-bin --with-install-dir=/usr/local/lib/cgi-wrap/$domain --with-wall --with-local-contact-email=webmaster@$domain
make
make install
echo "Make sure the desired scripting languages are installed in the $username jail. e.g.:"
echo "jk_init -k -j /usr/jails/$username perl"
echo "jk_init -k -j /usr/jails/$username python3"
echo "jk_init -k -j /usr/jails/$username ruby"