mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Add this point you only get information that "something" happend on the given hook. By adding more information to the hook, plugin creators can do more interesting stuff. * The first params remains the $APP name (to maintain backwards compatability) * The second params sends in the action that happend, for domain this can be: "add", "clear" or "remove" * The third param sends in the argument that was passed to the original function, for domain that would be a list of all the domains that was given. One reason this addition would be great for plugin owners, is that when you have a web tool over Dokku, and someone creates a domain over the CLI, we a plugin can send back information about the event to the webapp over an API. That way the webapp is always up-to-date with the Dokku installation. Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
134 lines
3.7 KiB
Bash
Executable File
134 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
[[ " domains domains:setup domains:add domains:clear domains:remove help domains:help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"
|
|
|
|
case "$1" in
|
|
domains)
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
verify_app_name "$2"
|
|
APP="$2"
|
|
|
|
dokku domains:setup $APP
|
|
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
|
dokku_log_info2_quiet "$APP Domain Names"
|
|
get_app_domains "$APP"
|
|
else
|
|
dokku_log_fail "No domain names set for $APP"
|
|
fi
|
|
;;
|
|
|
|
domains:setup)
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
verify_app_name "$2"
|
|
APP="$2"; VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
|
RE_IPV4="$(get_ipv4_regex)"; RE_IPV6="$(get_ipv6_regex)"
|
|
|
|
if [[ ! -f $VHOST_PATH ]]; then
|
|
if [[ -f "$DOKKU_ROOT/VHOST" ]]; then
|
|
VHOST=$(< "$DOKKU_ROOT/VHOST")
|
|
else
|
|
VHOST=$(< "$DOKKU_ROOT/HOSTNAME")
|
|
fi
|
|
if [[ "$VHOST" =~ $RE_IPV4 ]] || [[ "$VHOST" =~ $RE_IPV6 ]]; then
|
|
dokku_log_info2 "unsupported vhost config found. disabling vhost support"
|
|
disable_app_vhost $APP --no-restart $APP
|
|
else
|
|
if [[ -f "$DOKKU_ROOT/VHOST" ]]; then
|
|
dokku_log_info1 "Creating new $VHOST_PATH..."
|
|
SUBDOMAIN=${APP/%\.${VHOST}/}
|
|
hostname=$(: | plugn trigger 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
|
|
fi
|
|
fi
|
|
;;
|
|
|
|
domains:add)
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
verify_app_name "$2"
|
|
APP="$2"
|
|
|
|
if [[ -z "${*:3}" ]]; then
|
|
echo "Usage: dokku $1 $APP DOMAIN [DOMAIN ...]"
|
|
echo "Must specify DOMAIN."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $(egrep -w "^{$3}$" "$DOKKU_ROOT/$APP/VHOST" > /dev/null 2>&1; echo $?) -eq 0 ]]; then
|
|
echo "$3 is already defined for $APP"
|
|
exit 1
|
|
fi
|
|
|
|
shift 2
|
|
dokku domains:setup $APP
|
|
for DOMAIN in "$@"; do
|
|
echo "$DOMAIN" >> "$DOKKU_ROOT/$APP/VHOST"
|
|
done
|
|
plugn trigger post-domains-update $APP "add" "$@"
|
|
for DOMAIN in "$@"; do
|
|
dokku_log_info1 "Added $DOMAIN to $APP"
|
|
done
|
|
|
|
;;
|
|
|
|
domains:clear)
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
verify_app_name "$2"
|
|
APP="$2"
|
|
|
|
rm -f "$DOKKU_ROOT/$APP/VHOST"
|
|
dokku domains:setup $APP
|
|
plugn trigger post-domains-update $APP "clear"
|
|
dokku_log_info1 "Cleared domains in $APP"
|
|
|
|
;;
|
|
|
|
domains:remove)
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
verify_app_name "$2"
|
|
APP="$2"
|
|
|
|
if [[ -z "${*:3}" ]]; then
|
|
echo "Usage: dokku $1 $APP DOMAIN [DOMAIN ...]"
|
|
echo "Must specify DOMAIN."
|
|
exit 1
|
|
fi
|
|
|
|
shift 2
|
|
dokku domains:setup $APP
|
|
for DOMAIN in "$@"; do
|
|
sed -i "/^$DOMAIN$/d" "$DOKKU_ROOT/$APP/VHOST"
|
|
done
|
|
plugn trigger post-domains-update $APP "remove" "$@"
|
|
for DOMAIN in "$@"; do
|
|
dokku_log_info1 "Removed $DOMAIN from $APP"
|
|
done
|
|
|
|
;;
|
|
|
|
help | domains:help)
|
|
cat<<EOF
|
|
domains <app>, List custom domains for app
|
|
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
|