This helps remove duplication and also ensures that all hosts have a proper setup after running `make copyfiles` Note that this command is not exposed in help as it is not generally useful to developers
101 lines
2.9 KiB
Bash
Executable File
101 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
case "$1" in
|
|
domains)
|
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
|
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
|
|
APP="$2"
|
|
|
|
dokku domains:setup $APP
|
|
echo "=== $APP Domain Names"
|
|
cat "$DOKKU_ROOT/$APP/VHOST"
|
|
;;
|
|
|
|
domains:setup)
|
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
|
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
|
|
APP="$2"
|
|
|
|
[ -f $VHOST_PATH ] || {
|
|
echo "-----> Creating new $VHOST_PATH..."
|
|
if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then
|
|
cat "$DOKKU_ROOT/$APP/URL" > $VHOST_PATH
|
|
else
|
|
VHOST=$(< "$DOKKU_ROOT/VHOST")
|
|
SUBDOMAIN=${APP/%\.${VHOST}/}
|
|
hostname=$(: | pluginhook nginx-hostname $APP $SUBDOMAIN $VHOST)
|
|
if [[ ! -n $hostname ]]; then
|
|
if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then
|
|
hostname="${APP/\//-}"
|
|
else
|
|
hostname="${APP/\//-}.$VHOST"
|
|
fi
|
|
fi
|
|
|
|
echo $hostname > $VHOST_PATH
|
|
fi
|
|
}
|
|
;;
|
|
|
|
domains:add)
|
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
|
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
|
|
APP="$2"
|
|
|
|
if [[ -z $3 ]]; then
|
|
echo "Usage: dokku $1 $APP DOMAIN"
|
|
echo "Must specify DOMAIN."
|
|
exit 1
|
|
fi
|
|
|
|
dokku domains:setup $APP
|
|
echo "$3" >> "$DOKKU_ROOT/$APP/VHOST"
|
|
pluginhook post-domains-update $APP
|
|
echo "-----> Added $3 to $APP"
|
|
;;
|
|
|
|
domains:clear)
|
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
|
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
|
|
APP="$2"
|
|
|
|
dokku domains:setup $APP
|
|
echo '' > "$DOKKU_ROOT/$APP/VHOST"
|
|
pluginhook post-domains-update $APP
|
|
echo "-----> Cleared domains in $APP"
|
|
;;
|
|
|
|
domains:remove)
|
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
|
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
|
|
APP="$2"
|
|
|
|
if [[ -z $3 ]]; then
|
|
echo "Usage: dokku $1 $2 DOMAIN"
|
|
echo "Must specify DOMAIN."
|
|
exit 1
|
|
fi
|
|
|
|
dokku domains:setup $APP
|
|
sed -i "/^$3$/d" "$DOKKU_ROOT/$APP/VHOST"
|
|
pluginhook post-domains-update $APP
|
|
echo "-----> Removed $3 from $APP"
|
|
;;
|
|
|
|
help | domains:help)
|
|
cat && cat<<EOF
|
|
domains <app> List custom domains for app
|
|
domains:help <app> This help message
|
|
domains:add <app> DOMAIN Add a custom domain to app
|
|
domains:clear <app> Clear all custom domains for app
|
|
domains:remove <app> DOMAIN Remove a custom domain from app
|
|
EOF
|
|
;;
|
|
|
|
*)
|
|
exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
|
;;
|
|
|
|
esac
|