adding help() and associated changes
This commit is contained in:
parent
70c589f908
commit
0bffa3ca8d
|
@ -7,25 +7,53 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
# check for and set virtualhost
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Add virtualhost to this server."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost username [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo ""
|
||||||
|
echo " Username must already exist. If need be run vhost-user-add.sh first."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# check for and set virtualhost & username
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
if vhost::validate_domain $1; then
|
if [ $1 == "-h" ]; then
|
||||||
virtualhost=$1
|
help
|
||||||
else
|
else
|
||||||
echo "ERROR: $1 is not a valid domain name."
|
# virtualhost
|
||||||
exit 1
|
if vhost::validate_domain $1; then
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "ERROR: $1 is not a valid domain name."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# username
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
if [ $2 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
username="${2,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "username not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# last check for -h
|
||||||
|
if [ -n "$3" ]; then
|
||||||
|
if [ $3 == "-h" ]; then
|
||||||
|
help
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
help
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check for and set username
|
|
||||||
if [ -n "$2" ]; then
|
|
||||||
username=$2
|
|
||||||
else
|
|
||||||
echo "username not set"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d /home/$username ]; then
|
if [ ! -d /home/$username ]; then
|
||||||
|
|
|
@ -7,12 +7,27 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Removes virtualhost from server."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set virtualhost
|
# check for and set virtualhost
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
virtualhost=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
help
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove virtualhost dir
|
# remove virtualhost dir
|
||||||
|
|
|
@ -7,16 +7,40 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
# -v virtualhost (required)
|
help()
|
||||||
# -u username (optional)
|
{
|
||||||
# -p password (optional)
|
thisfilename=$(basename -- "$0")
|
||||||
# -j jail (true or false, optional)
|
echo "Add virtualhost to this server, including shell user and MySQL database."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo " -u USERNAME Username to use for this virtualhost. Optional, defaults to first 8 characters of virtualhost."
|
||||||
|
echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
|
||||||
|
echo " -j Whether or not to jail the user. Optional, default is to not jail user."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
while getopts ":v:u:p:j:" opt; do
|
# check for and set virtualhost
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
elif vhost::validate_domain $1; then
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "ERROR: Invalid virtualhost: $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
help
|
||||||
|
fi
|
||||||
|
|
||||||
|
while getopts "hu:p:j" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
v )
|
h )
|
||||||
virtualhost=${OPTARG}
|
help
|
||||||
;;
|
exit;;
|
||||||
u )
|
u )
|
||||||
username=${OPTARG}
|
username=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
@ -24,7 +48,7 @@ while getopts ":v:u:p:j:" opt; do
|
||||||
password=${OPTARG}
|
password=${OPTARG}
|
||||||
;;
|
;;
|
||||||
j )
|
j )
|
||||||
jail=${OPTARG}
|
jail=true
|
||||||
;;
|
;;
|
||||||
\? )
|
\? )
|
||||||
echo "Invalid option: $OPTARG"
|
echo "Invalid option: $OPTARG"
|
||||||
|
@ -43,11 +67,6 @@ if [ ! -n "$virtualhost" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! vhost::validate_domain $virtualhost; then
|
|
||||||
echo "ERROR: $virtualhost is not a valid domain name."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d /srv/www/$virtualhost ] || [ -f /etc/apache2/sites-available/$virtualhost.conf ]; then
|
if [ -d /srv/www/$virtualhost ] || [ -f /etc/apache2/sites-available/$virtualhost.conf ]; then
|
||||||
echo "virtualhost for $virtualhost already installed"
|
echo "virtualhost for $virtualhost already installed"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -64,10 +83,8 @@ if ! grep -q "^$username:" /etc/passwd; then
|
||||||
if [ ! -n "$password" ]; then
|
if [ ! -n "$password" ]; then
|
||||||
password=`/usr/bin/pwgen 12 1`
|
password=`/usr/bin/pwgen 12 1`
|
||||||
fi
|
fi
|
||||||
# set userid
|
|
||||||
userid=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=65534; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
|
|
||||||
# add user
|
# add user
|
||||||
/usr/local/bin/vhost-user-add.sh $username "$password" $userid
|
/usr/local/bin/vhost-user-add.sh $username -p "$password"
|
||||||
# if jail option is set then jail user
|
# if jail option is set then jail user
|
||||||
if [[ $jail = true ]]; then
|
if [[ $jail = true ]]; then
|
||||||
/usr/local/bin/vhost-user-jail.sh $username > /dev/null 2>&1
|
/usr/local/bin/vhost-user-jail.sh $username > /dev/null 2>&1
|
||||||
|
@ -76,3 +93,6 @@ fi
|
||||||
|
|
||||||
# add virtualhost
|
# add virtualhost
|
||||||
/usr/local/bin/vhost-add.sh $virtualhost $username > /dev/null 2>&1
|
/usr/local/bin/vhost-add.sh $virtualhost $username > /dev/null 2>&1
|
||||||
|
|
||||||
|
# add mysql database
|
||||||
|
/usr/local/bin/vhost-mysql-db-add.sh $virtualhost > /dev/null 2>&1
|
||||||
|
|
|
@ -7,30 +7,59 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Remove virtualhost and associated user & database & db user from this server."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set virtualhost
|
# check for and set virtualhost
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
virtualhost=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
elif [ ! -d /srv/www/$1 ]; then
|
||||||
|
echo "virtualhost dir does not exist"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
help
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# First check for virtualhost. Redundant
|
# check for database and delete if it exists
|
||||||
# as vhost-del.sh run later does this same check
|
database=${virtualhost//./dot}
|
||||||
# but prevents connecting to all nodes unnecessarily
|
database=${database//-/dash}
|
||||||
if [ ! -d /srv/www/$virtualhost ]; then
|
if [ -d /var/lib/mysql/$database ]; then
|
||||||
echo "virtualhost dir does not exist"
|
/usr/local/bin/vhost-mysql-db-del.sh $virtualhost
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for userdel option and set username if enabled
|
# get & set username for this virtualhost
|
||||||
if [ -n "$2" ] && [ $2 = "userdel" ]; then
|
username=$(stat -c '%U' /srv/www/$virtualhost)
|
||||||
username=$(stat -c '%U' /srv/www/$virtualhost)
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# check for a delete varnish config
|
||||||
|
|
||||||
|
# del virtualhost files & configs
|
||||||
/usr/local/bin/vhost-del.sh $virtualhost
|
/usr/local/bin/vhost-del.sh $virtualhost
|
||||||
|
|
||||||
# check for userdel option
|
# check for any remaining virtualhosts before deleting user
|
||||||
if [ -n "$2" ] && [ $2 = "userdel" ] && [ -n $username ]; then
|
# same check is done in vhost-user-del.sh
|
||||||
|
# but doing this here avoids generating any errors
|
||||||
|
existingvirtualhosts=false
|
||||||
|
vhost::set-virtualhostArray
|
||||||
|
for v in "${virtualhostArray[@]}"
|
||||||
|
do
|
||||||
|
if [ $(stat -c '%U' /srv/www/$v) = $username ]; then
|
||||||
|
existingvirtualhosts=true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $existingvirtualhosts = false ]]; then
|
||||||
/usr/local/bin/vhost-user-del.sh $username
|
/usr/local/bin/vhost-user-del.sh $username
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -7,9 +7,25 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Disable Apache config for specified virtualhost."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set virtualhost
|
# check for and set virtualhost
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
virtualhost=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
echo "virtualhost not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -7,54 +7,86 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
# vhost-enable.sh macro_name vhost [subdomain|alias]
|
help()
|
||||||
# vhost-enable.sh VHostHTTPS example.com
|
{
|
||||||
# vhost-enable.sh VHostSubdomainHTTPS example.com staging
|
thisfilename=$(basename -- "$0")
|
||||||
# vhost-enable.sh VHostAliasHTTPS example.com existingsite
|
echo "Enable Apache config for virtualhost."
|
||||||
# vhost-enable.sh VMailHTTPS mail.example.com
|
echo ""
|
||||||
# vhost-enable.sh RedirectHTTPS example.com https://my.newsite.com/path/page.html
|
echo "usage: $thisfilename macro_name vhost [subdomain|alias]"
|
||||||
#
|
echo ""
|
||||||
# mod_macro config will look like:
|
echo " -h Print this help."
|
||||||
# Use VHostHTTP $vhost $username
|
echo ""
|
||||||
# Use VHostHTTPS $vhost $username
|
echo " Available Apache Macros:"
|
||||||
# Use VHostHTTPSVarnish $vhost $username
|
echo ""
|
||||||
# Use VHostSubdomainHTTP $vhost $username $subdomain
|
# working on building autodetected macros
|
||||||
# Use VHostSubdomainHTTPS $vhost $username $subdomain
|
# needs work - remove $username, set other vars
|
||||||
# Use VHostSubdomainHTTPSVarnish $vhost $username $subdomain
|
# default_ifs="$IFS"
|
||||||
# Use VHostAliasHTTP $vhost $username $alias
|
# IFS=""
|
||||||
# Use VHostAliasHTTPS $vhost $username $alias
|
# macro_help_array=($(grep Macro /etc/apache2/mods-available/macro.conf|cut -d ' ' -f 2-|cut -d \> -f 1|grep -v Macro))
|
||||||
# Use VHostAliasHTTPSVarnish $vhost $username $alias
|
# for each_macro in ${macro_help_array[*]}
|
||||||
# Use VMailHTTPS $vhost
|
# do
|
||||||
# Use RedirectHTTP $vhost $redirect
|
# echo "${each_macro}"
|
||||||
# Use RedirectHTTPS $vhost $redirect
|
# done
|
||||||
#
|
# IFS="$default_ifs"
|
||||||
# $username is autodetected from vhost dir ownership
|
echo ""
|
||||||
|
echo " Usage examples:"
|
||||||
|
echo " vhost-enable.sh VHostHTTPS example.com"
|
||||||
|
echo " vhost-enable.sh VHostSubdomainHTTPS example.com staging"
|
||||||
|
echo " vhost-enable.sh VHostAliasHTTPS example.com existingsite"
|
||||||
|
echo " vhost-enable.sh VMailHTTPS mail.example.com"
|
||||||
|
echo " vhost-enable.sh RedirectHTTPS example.com https://my.newsite.com/path/page.html"
|
||||||
|
echo ""
|
||||||
|
echo " Apache mod_macro config will look like:"
|
||||||
|
echo ' Use VHostHTTP $vhost $username'
|
||||||
|
echo ' Use VHostHTTPS $vhost $username'
|
||||||
|
echo ' Use VHostHTTPSVarnish $vhost $username'
|
||||||
|
echo ' Use VHostSubdomainHTTP $vhost $username $subdomain'
|
||||||
|
echo ' Use VHostSubdomainHTTPS $vhost $username $subdomain'
|
||||||
|
echo ' Use VHostSubdomainHTTPSVarnish $vhost $username $subdomain'
|
||||||
|
echo ' Use VHostAliasHTTP $vhost $username $alias'
|
||||||
|
echo ' Use VHostAliasHTTPS $vhost $username $alias'
|
||||||
|
echo ' Use VHostAliasHTTPSVarnish $vhost $username $alias'
|
||||||
|
echo ' Use VMailHTTPS $vhost'
|
||||||
|
echo ' Use RedirectHTTP $vhost $redirect'
|
||||||
|
echo ' Use RedirectHTTPS $vhost $redirect'
|
||||||
|
echo ''
|
||||||
|
echo ' $username is autodetected from vhost dir ownership'
|
||||||
|
echo " See /etc/apache2/mods-available/macro.conf for macro details."
|
||||||
|
echo ""
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
macro_array=($(grep Macro /etc/apache2/mods-available/macro.conf |cut -d ' ' -f 2|grep -v Macro))
|
macro_array=($(grep Macro /etc/apache2/mods-available/macro.conf |cut -d ' ' -f 2|grep -v Macro))
|
||||||
macro_vhost_line="Use"
|
macro_vhost_line="Use"
|
||||||
|
|
||||||
# check for and set mode
|
# check for and set macro & vhost
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
macro_name=$1
|
if [ $1 == "-h" ]; then
|
||||||
if [[ " ${macro_array[@]} " =~ " ${macro_name} " ]]; then
|
help
|
||||||
macro_vhost_line="$macro_vhost_line $macro_name"
|
|
||||||
else
|
else
|
||||||
echo "invalid macro name"
|
# check for and set macro
|
||||||
exit 1
|
macro_name=$1
|
||||||
|
shift
|
||||||
|
if [[ " ${macro_array[@]} " =~ " ${macro_name} " ]]; then
|
||||||
|
macro_vhost_line="$macro_vhost_line $macro_name"
|
||||||
|
else
|
||||||
|
echo "invalid macro name"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# check for and set vhost
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
vhost=$2
|
||||||
|
shift
|
||||||
|
macro_vhost_line="$macro_vhost_line $vhost"
|
||||||
|
vhost_conf="$vhost.conf"
|
||||||
|
else
|
||||||
|
echo "vhost not set"
|
||||||
|
echo
|
||||||
|
help
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "macro name not set"
|
help
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check for and set vhost
|
|
||||||
if [ -n "$2" ]; then
|
|
||||||
vhost=$2
|
|
||||||
macro_vhost_line="$macro_vhost_line $vhost"
|
|
||||||
vhost_conf="$vhost.conf"
|
|
||||||
else
|
|
||||||
echo "vhost not set"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set username for all VHost macros
|
# set username for all VHost macros
|
||||||
|
|
|
@ -7,13 +7,40 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
help()
|
||||||
if [ "$1" = '--verbose' ] || [ "$1" = '-v' ]; then
|
{
|
||||||
mode=verbose
|
thisfilename=$(basename -- "$0")
|
||||||
elif [ "$1" = '--dry-run' ] || [ "$1" = '-n' ]; then
|
echo "Make sure all home (/home/...) and virtualhost (/srv/www/...) files are owned by correct users."
|
||||||
mode=dry-run
|
echo ""
|
||||||
fi
|
echo "usage: $thisfilename [OPTIONS]"
|
||||||
fi
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo " -n dry-run - List all files that need modification, but don't actually do anything."
|
||||||
|
echo " -v verbose - List all files that are being modified."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts "hvn" opt; do
|
||||||
|
case "${opt}" in
|
||||||
|
h )
|
||||||
|
help
|
||||||
|
;;
|
||||||
|
v )
|
||||||
|
mode=verbose
|
||||||
|
;;
|
||||||
|
n )
|
||||||
|
mode=dry-run
|
||||||
|
;;
|
||||||
|
\? )
|
||||||
|
echo "Invalid option: $OPTARG"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
: )
|
||||||
|
echo "Invalid option: $OPTARG requires an argument"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
for VHOST in /srv/www/*/; {
|
for VHOST in /srv/www/*/; {
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,35 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Creates default MySQL database and db user for specified virtualhost."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost. [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo " -u USERNAME Username for accessing the database. Optional, autogenerated if none specified."
|
||||||
|
echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
|
||||||
|
echo ""
|
||||||
|
echo " MySQL database names is based on virtualhost, with . replaced by the word 'dot'"
|
||||||
|
echo " and - replaced by the word 'dash'. If username is autogenerated it is based on"
|
||||||
|
echo " the shell username & the virtualhost name."
|
||||||
|
echo " e.g. for virtualost example.com the db name will be 'exampledotcom' and the"
|
||||||
|
echo " username will be examplec@example.com."
|
||||||
|
echo " db info stored in a file named /srv/www/$virtualhost/db_info.txt"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# check for and set virtualhost
|
# check for and set virtualhost
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
virtualhost=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
echo "virtualhost not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -31,11 +57,14 @@ if [ -d /var/lib/mysql/$database ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# get & set username of virtualhost
|
||||||
|
vhost_username=$(stat -c '%U' /srv/www/$virtualhost)
|
||||||
|
|
||||||
# check for and set mysql username
|
# check for and set mysql username
|
||||||
if [ -n "$2" ]; then
|
if [ -n "$2" ]; then
|
||||||
username=$2
|
username=$2
|
||||||
else
|
else
|
||||||
username=$(stat -c '%U' /srv/www/$virtualhost)@$virtualhost
|
username=$vhost_username@$virtualhost
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for and set mysql password
|
# check for and set mysql password
|
||||||
|
@ -50,4 +79,13 @@ mysql -e "CREATE USER '$username'@'localhost' IDENTIFIED BY '$password';"
|
||||||
mysql -e "GRANT ALL PRIVILEGES ON $database.* TO '$username'@'localhost';"
|
mysql -e "GRANT ALL PRIVILEGES ON $database.* TO '$username'@'localhost';"
|
||||||
mysqladmin flush-privileges
|
mysqladmin flush-privileges
|
||||||
|
|
||||||
|
# save mysql db info to file
|
||||||
|
touch /srv/www/$virtualhost/db_info.txt
|
||||||
|
chown $vhost_username:$vhost_username /srv/www/$virtualhost/db_info.txt
|
||||||
|
chmod 640 /srv/www/$virtualhost/db_info.txt
|
||||||
|
echo "hostname=127.0.0.1" > /srv/www/$virtualhost/db_info.txt
|
||||||
|
echo "database=$database" >> /srv/www/$virtualhost/db_info.txt
|
||||||
|
echo "username=$username" >> /srv/www/$virtualhost/db_info.txt
|
||||||
|
echo "password=$password" >> /srv/www/$virtualhost/db_info.txt
|
||||||
|
|
||||||
echo "database '$database' created with username '$username' and password '$password'"
|
echo "database '$database' created with username '$username' and password '$password'"
|
||||||
|
|
|
@ -7,47 +7,41 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
# # check for and set virtualhost
|
help()
|
||||||
# if [ -n "$1" ]; then
|
{
|
||||||
# virtualhost=$1
|
thisfilename=$(basename -- "$0")
|
||||||
# else
|
echo "Remove MySQL database and default db user for the specified virtualhost."
|
||||||
# echo "virtualhost not set"
|
echo ""
|
||||||
# exit 1
|
echo "usage: $thisfilename virtualhost."
|
||||||
# fi
|
echo ""
|
||||||
#
|
echo " -h Print this help."
|
||||||
# # make sure virtualhost exists
|
exit
|
||||||
# if [ ! -d /srv/www/$virtualhost ]; then
|
}
|
||||||
# echo "virtualhost $virtualhost does not exist"
|
|
||||||
# exit 1
|
# check for and set virtualhost.
|
||||||
# fi
|
if [ -n "$1" ]; then
|
||||||
#
|
if [ $1 == "-h" ]; then
|
||||||
# # set database name
|
help
|
||||||
# database=${virtualhost//./dot}
|
else
|
||||||
# database=${database//-/dash}
|
virtualhost="${1,,}"
|
||||||
#
|
shift
|
||||||
# # make sure database doesn't already exist
|
fi
|
||||||
# if [ -d /var/lib/mysql/$database ]; then
|
else
|
||||||
# echo "database $database already exists"
|
echo "virtualhost not set"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
#
|
|
||||||
# # check for and set mysql username
|
# set database name
|
||||||
# if [ -n "$2" ]; then
|
database=${virtualhost//./dot}
|
||||||
# username=$2
|
database=${database//-/dash}
|
||||||
# else
|
|
||||||
# username=$(stat -c '%U' /srv/www/$virtualhost)@$virtualhost
|
# drop database
|
||||||
# fi
|
mysql -e "DROP DATABASE IF EXISTS $database;"
|
||||||
#
|
|
||||||
# # check for and set mysql password
|
# set default username and attempt to drop user
|
||||||
# if [ -n "$3" ]; then
|
if [ -d /srv/www/$virtualhost ]; then
|
||||||
# password=$3
|
vhost_username=$(stat -c '%U' /srv/www/$virtualhost)
|
||||||
# else
|
username=$vhost_username@$virtualhost
|
||||||
# password=`/usr/bin/pwgen 16 1`
|
mysql -e "DROP USER IF EXISTS '$username'@'localhost';"
|
||||||
# fi
|
mysqladmin flush-privileges
|
||||||
#
|
fi
|
||||||
# mysqladmin create $database
|
|
||||||
# mysql -e "CREATE USER '$username'@'localhost' IDENTIFIED BY '$password';"
|
|
||||||
# mysql -e "GRANT ALL PRIVILEGES ON $database.* TO '$username'@'localhost';"
|
|
||||||
# mysqladmin flush-privileges
|
|
||||||
#
|
|
||||||
# echo "database '$database' created with username '$username' and password '$password'"
|
|
||||||
|
|
|
@ -7,30 +7,66 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Add system user to server."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename username [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
|
||||||
|
echo " -u UID Numberic User ID to assign to user. Optional, next available uid set if none specified."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set username
|
# check for and set username
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
username=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
username="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "username not set"
|
echo "username not set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for and set password
|
while getopts "hp:u:" opt; do
|
||||||
if [ -n "$2" ]; then
|
case "${opt}" in
|
||||||
password=$2
|
h )
|
||||||
else
|
help
|
||||||
echo "password not set"
|
p )
|
||||||
exit 1
|
password=${OPTARG}
|
||||||
|
;;
|
||||||
|
u )
|
||||||
|
uid=${OPTARG}
|
||||||
|
;;
|
||||||
|
\? )
|
||||||
|
echo "Invalid option: $OPTARG"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
: )
|
||||||
|
echo "Invalid option: $OPTARG requires an argument"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# generate password if none specified
|
||||||
|
if [ ! -n "$password" ]; then
|
||||||
|
password=`/usr/bin/pwgen 12 1`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for and set userid
|
# get next UID if none specified
|
||||||
if [ -n "$3" ]; then
|
if [ ! -n "$uid" ]; then
|
||||||
userid=$3
|
userid=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=65534; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
|
||||||
else
|
|
||||||
echo "userid not set"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# user & related files are only added if they don't already exist
|
||||||
|
# in this way it's safe to repeatedly try to add the same user
|
||||||
|
|
||||||
if ! /bin/grep -q "^$username:" /etc/passwd; then
|
if ! /bin/grep -q "^$username:" /etc/passwd; then
|
||||||
newusers="$username:$password:$userid:$userid::/home/$username:/bin/bash"
|
newusers="$username:$password:$userid:$userid::/home/$username:/bin/bash"
|
||||||
echo "$newusers"|newusers
|
echo "$newusers"|newusers
|
||||||
|
|
|
@ -7,9 +7,25 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Remove user from this server."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename username"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set username
|
# check for and set username
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
username=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
username="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "username not set"
|
echo "username not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -7,9 +7,25 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Rebuild jail for specified user."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename username [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set username
|
# check for and set username
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
username=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
username="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "username not set"
|
echo "username not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -7,9 +7,25 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
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
|
# check for and set username
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
username=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
username="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "username not set"
|
echo "username not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -7,9 +7,25 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Add file to all existing jails."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename pathtofile"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set file to be copied in to jails
|
# check for and set file to be copied in to jails
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
cpfile=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
cpfile=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "file to copy in to jails not set"
|
echo "file to copy in to jails not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -7,6 +7,23 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Rebuilds all existing jails by running vhost-user-jail-reset.sh for each jailed user."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# make sure jails dir exists
|
# make sure jails dir exists
|
||||||
if [[ ! -e /usr/jails/ ]]; then
|
if [[ ! -e /usr/jails/ ]]; then
|
||||||
echo "/usr/jails does not exist"
|
echo "/usr/jails does not exist"
|
||||||
|
|
|
@ -7,6 +7,31 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Updates all existing jails."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo ""
|
||||||
|
echo " Cycles through all existing jails and runs jk_update"
|
||||||
|
echo " for each one. This updates all software installed in"
|
||||||
|
echo " the jails to match the latest versions installed on"
|
||||||
|
echo " the host server. e.g. if php-cli gets update on the"
|
||||||
|
echo " host this syncs that update to all the jails."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# check for -h
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# make sure jails dir exists
|
# make sure jails dir exists
|
||||||
if [[ ! -e /usr/jails/ ]]; then
|
if [[ ! -e /usr/jails/ ]]; then
|
||||||
echo "/usr/jails does not exist"
|
echo "/usr/jails does not exist"
|
||||||
|
|
|
@ -7,11 +7,28 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
# varnish-disable.sh virtualhost
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Disables Varnish config for specified virtualhost."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo ""
|
||||||
|
echo " Varnish is proxied through Apache. This disables the"
|
||||||
|
echo " Apache proxy to Varnish and removes the varnish config."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set virtualhost
|
# check for and set virtualhost
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
virtualhost=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
echo "virtualhost not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -41,7 +58,11 @@ if [[ "$macro_name" == *"Subdomain"* ]] || [[ "$macro_name" == *"Alias"* ]]; the
|
||||||
vhost_enable="$vhost_enable $macro_var"
|
vhost_enable="$vhost_enable $macro_var"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# uncomment to flush varnish cache
|
/usr/local/bin/vhost-enable.sh $vhost_enable
|
||||||
# systemctl is-active --quiet varnish && systemctl reload --quiet varnish
|
|
||||||
|
|
||||||
echo /usr/local/bin/vhost-enable.sh $vhost_enable
|
if [ -f /etc/varnish/sites.d/$virtualhost ]; then
|
||||||
|
rm /etc/varnish/sites.d/$virtualhost
|
||||||
|
/usr/local/bin/vhost-varnish-update-sites.sh $vhost_enable
|
||||||
|
# uncomment to flush varnish cache
|
||||||
|
# systemctl is-active --quiet varnish && systemctl reload --quiet varnish
|
||||||
|
fi
|
||||||
|
|
|
@ -7,9 +7,29 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Enables Varnish for specified virtualhost."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename virtualhost. [OPTIONS]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo ""
|
||||||
|
echo " Creates Varnish config, loads it in Varnish and then"
|
||||||
|
echo " enables Apache proxy to Varnish for virtualhost."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# check for and set virtualhost
|
# check for and set virtualhost
|
||||||
|
# check for and set username
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
virtualhost=$1
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
virtualhost="${1,,}"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "virtualhost not set"
|
echo "virtualhost not set"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -7,6 +7,32 @@
|
||||||
# load include file
|
# load include file
|
||||||
source $(dirname $0)/vhost.sh
|
source $(dirname $0)/vhost.sh
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
thisfilename=$(basename -- "$0")
|
||||||
|
echo "Makes sure all existing varnish configs are loaded."
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo ""
|
||||||
|
echo " The varnish config is broken down in to individual"
|
||||||
|
echo " configurations for each virtualhost. Each config has"
|
||||||
|
echo " to be included by the master sites.vcl. This tool makes"
|
||||||
|
echo " sure all existing virtualhost varnish configs are"
|
||||||
|
echo " properly included in sites.vcl, and removes includes"
|
||||||
|
echo " for varnish virtualhost configs that have been deleted."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# check for -h
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -f /etc/varnish/sites.d/example.com.vcl ]; then
|
if [ ! -f /etc/varnish/sites.d/example.com.vcl ]; then
|
||||||
|
|
||||||
echo "ERROR: example.vlc does not exist"
|
echo "ERROR: example.vlc does not exist"
|
||||||
|
|
|
@ -36,3 +36,8 @@ function vhost::validate_domain () {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check for local config, which can be used to override any of the above
|
||||||
|
if [[ -f /usr/local/etc/vhost.conf ]]; then
|
||||||
|
source /usr/local/etc/vhost.conf
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user