forked from mikexstudios/dokku-nginx-alt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands
executable file
·80 lines (69 loc) · 1.87 KB
/
commands
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# domains [appname] - list all domain names
# domains:help
# domains:add [appname] DOMAIN
# domains:clear [appname]
# domains:remove [appname] DOMAIN
APP_NAME="$2"
APP_PATH="$DOKKU_ROOT/$APP_NAME"
VHOST_PATH="$APP_PATH/VHOST"
if [[ $1 == 'domains' ]] || [[ $1 == 'domains:*' ]]; then
# Check that app name is passed
if [[ -z $APP_NAME ]]; then
echo "You must specify an app name."
exit 1
fi
# Check that app exists
if [[ ! -d $APP_PATH ]]; then
echo "App $APP_NAME does not exist."
exit 1
fi
# Make sure VHOST file exists. Create empty file if not.
if [[ ! -f $VHOST_PATH ]]; then
echo "-----> Creating new $VHOST_PATH..."
touch $VHOST_PATH
fi
fi
case "$1" in
# List all domain names for given app
domains)
echo "=== $APP_NAME Domain Names"
cat $VHOST_PATH
;;
domains:add)
if [[ -z $3 ]]; then
echo "Usage: dokku $1 $2 DOMAIN"
echo "Must specify DOMAIN."
exit 1
fi
# TODO: Check if domain already exists
# Append domain to VHOST
echo "$3" >> $VHOST_PATH
echo "-----> Added $3 to $VHOST_PATH..."
;;
domains:clear)
echo '' > $VHOST_PATH
echo "-----> Cleared domains in $VHOST_PATH..."
;;
domains:remove)
if [[ -z $3 ]]; then
echo "Usage: dokku $1 $2 DOMAIN"
echo "Must specify DOMAIN."
exit 1
fi
# Remove domain from VHOST
sed -i "/^$3$/d" $VHOST_PATH
echo "-----> Removed $3 from $VHOST_PATH..."
;;
help | domains:help)
cat <<EOF
domains <appname> # list custom domains for app
domains:help <appname> # this help message
domains:add <appname> DOMAIN # add a custom domain to app
domains:clear <appname> # clear all custom domains for app
domains:remove <appname> DOMAIN # remove a custom domain from app
EOF
;;
esac
cat