From 6bec6a35998e74a11aae6662f5e4032ed9eda16a Mon Sep 17 00:00:00 2001 From: David Marco Date: Tue, 28 Jan 2020 16:54:12 +0000 Subject: [PATCH 1/5] Fix adding and deleting keys by using named variables Initial positional parameters have already been parsed and stored in named variables early, so use them instead of positional parameters Some wrong conditions have been fixed, and this fixes cedricziel/dokku-hostkeys-plugin#30. --- commands | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/commands b/commands index d5e7634..fbe4f13 100755 --- a/commands +++ b/commands @@ -131,7 +131,7 @@ EOF add_shared_key() { check_install - if [[ ! -n "$2" ]]; then + if [[ -n "$SHARED_KEY_TO_ADD" ]]; then echo $SHARED_KEY_TO_ADD >> "$SHARED_HOSTKEYS_FILE" echo "Added $SHARED_KEY_TO_ADD to the list of shared hostkeys" else @@ -141,7 +141,7 @@ add_shared_key() { delete_shared_keys() { check_install - if [[ ! -n "$2" ]]; then + if [[ -n "$HOSTNAME_TO_REMOVE" ]]; then ssh-keygen -f "$SHARED_HOSTKEYS_FILE" -R "$HOSTNAME_TO_REMOVE" rm "$SHARED_HOSTKEYS_FOLDER/known_hosts.old" echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup." @@ -165,7 +165,7 @@ add_app_key() { check_app check_exists check_install_app - if [[ ! -n "$3" ]]; then + if [[ -n "$SHARED_KEY_TO_ADD_APP" ]]; then echo $SHARED_KEY_TO_ADD_APP >> "$APP_SPECIFIC_HOSTKEYS_FILE" echo "Added $SHARED_KEY_TO_ADD_APP to the list of shared hostkeys" else @@ -189,7 +189,7 @@ delete_app_keys() { check_app check_exists check_install_app - if [[ -n "$3" ]]; then + if [[ -n "$HOSTNAME_TO_REMOVE_APP" ]]; then ssh-keygen -f "$APP_SPECIFIC_HOSTKEYS_FILE" -R "$HOSTNAME_TO_REMOVE_APP" rm "$APP_SPECIFIC_HOSTKEYS_FOLDER/known_hosts.old" echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup." @@ -227,11 +227,11 @@ case "$1" in ;; hostkeys:shared:add) - add_shared_key "$@" + add_shared_key ;; hostkeys:shared:delete) - delete_shared_keys "$@" + delete_shared_keys ;; hostkeys:shared:autoadd) @@ -243,11 +243,11 @@ case "$1" in ;; hostkeys:app:add) - add_app_key "$@" + add_app_key ;; hostkeys:app:delete) - delete_app_keys "$@" + delete_app_keys ;; hostkeys:app:autoadd) From 22c4d98d779e29d1c0802f0ee831fa9ffcd82eda Mon Sep 17 00:00:00 2001 From: David Marco Date: Tue, 28 Jan 2020 17:50:33 +0000 Subject: [PATCH 2/5] Fix "Can't follow non-constant source" linter warning (SC1090) See https://github.com/koalaman/shellcheck/wiki/SC1090 --- pre-build | 1 + 1 file changed, 1 insertion(+) diff --git a/pre-build b/pre-build index e21f9c4..e2f9887 100755 --- a/pre-build +++ b/pre-build @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +# shellcheck source=/dev/null source "$PLUGIN_ENABLED_PATH/common/functions" APP="$1" IMAGE=$(get_app_image_name $APP) From eb21953aeec59f494cb84e967c15596e11761f7a Mon Sep 17 00:00:00 2001 From: David Marco Date: Tue, 28 Jan 2020 22:38:41 +0000 Subject: [PATCH 3/5] Fix "redirection without command" linter warning (SC2188) See https://github.com/koalaman/shellcheck/wiki/SC2188 --- commands | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands b/commands index fbe4f13..5dc1c10 100755 --- a/commands +++ b/commands @@ -146,7 +146,7 @@ delete_shared_keys() { rm "$SHARED_HOSTKEYS_FOLDER/known_hosts.old" echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup." else - > $SHARED_HOSTKEYS_FILE + true > $SHARED_HOSTKEYS_FILE echo "Emptied the shared hostkey file. All apps will loose the shared keys on next push. Make sure you add the required ones" fi } @@ -194,7 +194,7 @@ delete_app_keys() { rm "$APP_SPECIFIC_HOSTKEYS_FOLDER/known_hosts.old" echo "Deleted hostkey for $HOSTNAME_TO_REMOVE as well as the backup." else - > $APP_SPECIFIC_HOSTKEYS_FILE + true > $APP_SPECIFIC_HOSTKEYS_FILE echo "Emptied the app specific hostkey file. Your app looses the specific keys on the next push. Make sure you add the required ones" fi } From 7580971fb86d45a28a43f61a599df31d58aab5fe Mon Sep 17 00:00:00 2001 From: David Marco Date: Tue, 4 Feb 2020 11:40:03 +0000 Subject: [PATCH 4/5] Fix "superfluous (..) around condition" linter warning (SC2233) See https://github.com/koalaman/shellcheck/wiki/SC2233 --- pre-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-build b/pre-build index e2f9887..fb6eb99 100755 --- a/pre-build +++ b/pre-build @@ -21,7 +21,7 @@ fi if [[ -f "$SHARED_KEY_FOLDER/known_hosts" ]]; then dokku_log_verbose_quiet "Adding shared keys" - if ([[ -z "$KNOWN_HOSTS_COMBINED" ]]); then + if [[ -z "$KNOWN_HOSTS_COMBINED" ]]; then KNOWN_HOSTS_COMBINED="$KNOWN_HOSTS_COMBINED"$(cat "$SHARED_KEY_FOLDER/known_hosts") else KNOWN_HOSTS_COMBINED="$KNOWN_HOSTS_COMBINED"$'\n'$(cat "$SHARED_KEY_FOLDER/known_hosts") From 5b61149decbcf9811b61ac353e89c07cbf18a932 Mon Sep 17 00:00:00 2001 From: David Marco Date: Tue, 4 Feb 2020 11:41:43 +0000 Subject: [PATCH 5/5] Fix "Use -n instead of ! -z" linter warning (SC2236) See https://github.com/koalaman/shellcheck/wiki/SC2236 --- pre-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-build b/pre-build index fb6eb99..f699f58 100755 --- a/pre-build +++ b/pre-build @@ -28,7 +28,7 @@ if [[ -f "$SHARED_KEY_FOLDER/known_hosts" ]]; then fi fi -if [[ ! -z "$KNOWN_HOSTS_COMBINED" ]]; then +if [[ -n "$KNOWN_HOSTS_COMBINED" ]]; then # 1. Create the .ssh folder id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $IMAGE /bin/bash -c "mkdir -p -m 700 /app/.ssh") test $(docker wait $id) -eq 0