diff --git a/docs/plugins.md b/docs/plugins.md index c67a780cc..c588af695 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -39,7 +39,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in hello) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 - [[ ! -d "$DOKKU_ROOT/$APP" ]] && echo "App $APP does not exist" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2"; echo "Hello $APP" diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index e30fb6eb3..7fd4f9476 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -7,15 +7,9 @@ case "$1" in ;; logs) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -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 [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER) @@ -30,15 +24,10 @@ case "$1" in ;; run) - if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 - fi + [[ -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"; IMAGE="dokku/$APP" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi + shift 2 DOCKER_ARGS=$(: | pluginhook docker-args $APP) @@ -46,11 +35,9 @@ case "$1" in ;; url) + [[ -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 [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then echo $(< "$DOKKU_ROOT/$APP/URL") diff --git a/plugins/apps/commands b/plugins/apps/commands index 8cf943943..2fed52a7e 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -8,35 +8,19 @@ case "$1" in ;; apps:create) - if [[ -z $2 ]]; then - echo "Please specify an app to create" - exit 1 - fi + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ -d "$DOKKU_ROOT/$APP" ]] && echo " ! Name is already taken" && exit 1 APP="$2" - if [[ -d "$DOKKU_ROOT/$APP" ]]; then - echo " ! Name is already taken" - exit 1 - fi mkdir -p "$DOKKU_ROOT/$APP" echo "Creating $APP... done" ;; apps:destroy) - if [[ -z $2 ]]; then - echo "Please specify an app to delete" - exit 1 - fi + [[ -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 + [[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1 APP="$2"; IMAGE="dokku/$APP"; - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi - - if [[ "$APP" == "tls" ]]; then - echo "Unable to destroy tls directory" - exit 1 - fi echo " ! WARNING: Potentially Destructive Action" echo " ! This command will destroy $APP (including all add-ons)." diff --git a/plugins/config/commands b/plugins/config/commands index 2e46d53e4..7592228ee 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -1,28 +1,14 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -# Check if name is specified -if [[ $1 == config ]] || [[ $1 == config:* ]]; then - if [[ -z $2 ]]; then - echo "You must specify an app name" - exit 1 - else - APP="$2" - ENV_FILE="$DOKKU_ROOT/$APP/ENV" - ENV_FILE_TEMP="$DOKKU_ROOT/$APP/ENV.tmp" - - # Check if app exists with the same name - if [ ! -d "$DOKKU_ROOT/$APP" ]; then - echo "App $APP does not exist" - exit 1 - fi - - [ -f $ENV_FILE ] || { - echo "-----> Creating $ENV_FILE" - touch $ENV_FILE - } - fi -fi +ENV_FILE="$DOKKU_ROOT/$2/ENV" +ENV_FILE_TEMP="$DOKKU_ROOT/$2/ENV.tmp" +config_create () { + [ -f $ENV_FILE ] || { + echo "-----> Creating $ENV_FILE" + touch $ENV_FILE + } +} config_styled_hash () { vars="$1" @@ -76,12 +62,12 @@ config_write() { case "$1" in config) + [[ -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 [ ! -f $ENV_FILE ] || [ ! -s $ENV_FILE ] ; then - echo "$APP has no config vars" - exit 1 - fi + config_create + [[ ! -s $ENV_FILE ]] && echo "$APP has no config vars" && exit 1 VARS=`cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | cut -d" " -f2-` @@ -97,14 +83,19 @@ case "$1" in ;; config:get) + [[ -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 config:get APP KEY" echo "Must specify KEY." exit 1 fi - if [ ! -f $ENV_FILE ] || [ ! -s $ENV_FILE ] ; then - exit 1 + config_create + if [[ ! -s $ENV_FILE ]] ; then + exit 0 fi KEY="$3" @@ -113,13 +104,17 @@ case "$1" in ;; config:set) + [[ -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 config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]" echo "Must specify KEY and VALUE to set." exit 1 fi - APP="$2"; APP_DIR="$DOKKU_ROOT/$APP" + config_create ENV_ADD="" ENV_TEMP=`cat "${ENV_FILE}"` RESTART_APP=false @@ -157,13 +152,17 @@ ${var}" ;; config:unset) + [[ -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 config:unset APP KEY1 [KEY2 ...]" echo "Must specify KEY to unset." exit 1 fi - APP="$2"; APP_DIR="$DOKKU_ROOT/$APP" + config_create ENV_TEMP=`cat "${ENV_FILE}"` VARS="${*:3}" diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 97567d2c3..e2b4632ac 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -3,31 +3,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in nginx:import-ssl) - if [[ -z $2 ]]; then - echo "Please specify an app to create" - exit 1 - fi + [[ -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 + [[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1 APP="$2" - if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 - fi - if [[ -t 0 ]]; then - echo "Tar archive containing server.crt and server.key expected on stdin" - exit 1 - fi TEMP_DIR=`mktemp -d` cd $TEMP_DIR tar xvf - <&0 - if [[ -f "$TEMP_DIR/server.crt" ]]; then - echo "Tar archive missing server.crt" - exit 1 - fi - if [[ -f "$TEMP_DIR/server.key" ]]; then - echo "Tar archive missing server.key" - exit 1 - fi + [[ -f "$TEMP_DIR/server.crt" ]] && echo "Tar archive missing server.crt" && exit 1 + [[ -f "$TEMP_DIR/server.key" ]] && echo "Tar archive missing server.key" && exit 1 mkdir -p "$DOKKU_ROOT/$APP/tls" mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt"