-
Notifications
You must be signed in to change notification settings - Fork 0
/
subsite_add_domain.sh
executable file
·51 lines (42 loc) · 1.19 KB
/
subsite_add_domain.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -o errexit
set -o nounset
DEBUG=true
SCRIPTDIR="$(dirname "$0")"
if [ -v USE_ENV_CONFIG ]; then
echo "Using environment configuration. Make sure that all variables from config.sh are set in .env file of proper environment settings."
else
if [ -f "$SCRIPTDIR"/config.sh ]; then
echo "Using configuration from file"
source "$SCRIPTDIR"/config.sh
else
echo "ERROR: please create a config.sh file"
exit 10
fi
fi
if [ -f "$SCRIPTDIR"/functions.sh ]; then
source "$SCRIPTDIR"/functions.sh
else
echo "ERROR: functions.sh missing"
exit 10
fi
if [ $# -ne 2 ]; then
echo "ERROR: Usage: $0 <sitename> <domainname>"
exit 10
fi
SITENAME=$(echo "$1" | tr -d ' ')
NEWDOMAIN=$(echo "$2" | tr -d ' ')
VHOST="/etc/apache2/sites-available/$SITENAME.conf"
# only allow root to run this script - because of special sudo rights and permissions
if [[ "$USER" != "root" ]]; then
echo "ERROR: Run with sudo or as root"
exit 10
fi
validate_domainname "$NEWDOMAIN"
check_existence_add
init "$SITENAME"
add_to_vhost
add_to_hosts "$NEWDOMAIN"
add_to_sites
# Print successful status in the end of the line.
echo "complete_status:{\"provisioning_state\": \"completed\", \"status\": 1}"