Refactored and fixed become

This commit is contained in:
Lutchy Horace 2021-03-17 16:10:32 -04:00
parent 2e865bfa02
commit 185d813c0e
2 changed files with 38 additions and 20 deletions

View file

@ -1,10 +1,10 @@
#!/bin/bash -x
#!/bin/bash
#
# Create Vhosts on VPS3
#
DEBUG=0
set -e
#set -e
function usage
{
@ -37,6 +37,8 @@ function reload_nginx
_cwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_bootstrap=${_cwd}/bootstrap.sh
_bb_myname=$(basename "$0")
_bb_mypath=$(realpath $BASH_SOURCE)
# Init script
if test -f $_bootstrap; then
@ -46,6 +48,9 @@ else
exit 1
fi
# gain priviledges
become "$@"
OPTS=$(getopt -o h -l domain:,root:,backend:,listenip:,desc: -n 'createVhosts' -- "$@")
if [ "$?" -gt '0' ]; then
echo 'Failed to set command line arguments'
@ -85,9 +90,13 @@ if [[ $_domain = false ]]; then
err "You must set domain"
fi
echo -n "Checking if $_root exists?"
if test -n "$_root"; then
if ! test -d $_root; then
err "Path doesn't exists! $_root"
echo " Creating..."
mkdir -p $_root
else
echo " Yes!"
fi
_rootpath="root $_root;"
fi
@ -110,16 +119,13 @@ if test -n "$_listenip"; then
fi
_listenip="$_listenip:"
else
warn "No listen ip specified, listing on all interfaces."
warn "Listen ip not specified, listening on all interfaces."
fi
if test -z "$_root" -a -z "$_backend"; then
err "You must specify either --root or --backend!"
fi
# gain priviledges
become $@
echo -n "Checking if /srv/http-content-combined/ exists?"
if ! test -d /srv/http-content-combined; then
echo " Creating..."
@ -128,7 +134,6 @@ else
echo " Yes!"
fi
echo "Creating Nginx configuration..."
_vhost_conf_file=/etc/nginx/conf.d/${_domain}.conf
echo -n "Checking if $_vhost_conf_file exists? "
@ -139,6 +144,7 @@ else
echo "No!"
fi
echo "Creating Nginx configuration..."
cat << EOF > $_vhost_conf_file
#### Description
## Type: HTTP