From 164f48913f99750544ea336af5589eae28592885 Mon Sep 17 00:00:00 2001 From: Mirko Geissler Date: Wed, 29 Jun 2016 09:11:04 +0200 Subject: [PATCH] Add domains_add_global and domains_remove_global --- plugins/domains/commands | 2 ++ plugins/domains/functions | 30 +++++++++++++++++++++++ plugins/domains/subcommands/add-global | 15 ++++++++++++ plugins/domains/subcommands/remove-global | 15 ++++++++++++ 4 files changed, 62 insertions(+) create mode 100755 plugins/domains/subcommands/add-global create mode 100755 plugins/domains/subcommands/remove-global diff --git a/plugins/domains/commands b/plugins/domains/commands index 42ce3a8c3..95dfdee9d 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -9,10 +9,12 @@ case "$1" in cat<], List domains domains:add DOMAIN, Add a domain to app + domains:add-global DOMAIN, Add global domain name domains:clear , Clear all domains for app domains:disable , Disable VHOST support domains:enable , Enable VHOST support domains:remove DOMAIN, Remove a domain from app + domains:remove-global DOMAIN, Remove global domain name domains:set-global , Set global domain name help_content } diff --git a/plugins/domains/functions b/plugins/domains/functions index 56caaa0df..ee6f77601 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -131,6 +131,36 @@ domains_enable() { fi } +domains_add_global() { + declare desc="add list of global domains" + local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" + + for DOMAIN in "$@"; do + if ! (is_valid_hostname "$DOMAIN"); then + dokku_log_fail "$DOMAIN is invalid. exiting..." + fi + done + + for DOMAIN in "$@"; do + if [[ $(egrep -w "^$DOMAIN$" "$GLOBAL_VHOST_PATH" > /dev/null 2>&1; echo $?) -eq 0 ]]; then + dokku_log_info1 "Skipping: $DOMAIN already added" + else + echo "$DOMAIN" >> "$GLOBAL_VHOST_PATH" + dokku_log_info1 "Added $DOMAIN" + fi + done +} + +domains_remove_global() { + declare desc="remove list of domains" + local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" + + for DOMAIN in "$@"; do + sed -i "\|^$DOMAIN\$|d" "$GLOBAL_VHOST_PATH" + dokku_log_info1 "Removed $DOMAIN" + done +} + domains_set_global() { declare desc="set global domain name" local NEW_GLOBAL_VHOST="$1"; local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" diff --git a/plugins/domains/subcommands/add-global b/plugins/domains/subcommands/add-global new file mode 100755 index 000000000..d71b27615 --- /dev/null +++ b/plugins/domains/subcommands/add-global @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/domains/functions" + +domains_add_global_cmd() { + declare desc="add global domain name via command line" + local cmd="domains:add-global" + [[ -z $2 ]] && dokku_log_fail "Please specify a domain name. Usage: dokku $1 DOMAIN [DOMAIN ...]" + + shift 1 + domains_add_global "$@" +} + +domains_add_global_cmd "$@" diff --git a/plugins/domains/subcommands/remove-global b/plugins/domains/subcommands/remove-global new file mode 100755 index 000000000..5a7c0ee80 --- /dev/null +++ b/plugins/domains/subcommands/remove-global @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/domains/functions" + +domains_remove_global_cmd() { + declare desc="remove global domain name via command line" + local cmd="domains:remove-global" + [[ -z $2 ]] && dokku_log_fail "Please specify a domain name. Usage: dokku $1 DOMAIN [DOMAIN ...]" + + shift 1 + domains_remove_global "$@" +} + +domains_remove_global_cmd "$@"