From 14e72ea3379a73332dd534bf92b9955584e87086 Mon Sep 17 00:00:00 2001 From: Adam Vigneaux Date: Sun, 26 Jul 2015 22:21:32 -0400 Subject: [PATCH 1/3] Add better error checking on nginx:import-ssl --- plugins/nginx-vhosts/commands | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index a1d955caa..8e221affd 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -161,12 +161,24 @@ EOF TEMP_DIR=$(mktemp -d) cd $TEMP_DIR tar xvf - <&0 - [[ ! -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 + + crt_count = $(ls -1 *.crt | wc -l) + if [[ $crt_count -lt 1 ]]; then + echo "Tar archive is missing .crt file" && exit 1 + elif [[ $crt_count -gt 1 ]]; then + echo "Tar archive contains more than one .crt file" && exit 1 + fi + + key_count = $(ls -1 *.key | wc -l) + if [[ $key_count -lt 1 ]]; then + echo "Tar archive is missing .key file" && exit 1 + elif [[ $key_count -gt 1 ]]; then + echo "Tar archive contains more than one .key file" && exit 1 + fi mkdir -p "$DOKKU_ROOT/$APP/tls" - mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt" - mv "$TEMP_DIR/server.key" "$DOKKU_ROOT/$APP/tls/server.key" + mv "$TEMP_DIR/*.crt" "$DOKKU_ROOT/$APP/tls/server.crt" + mv "$TEMP_DIR/*.key" "$DOKKU_ROOT/$APP/tls/server.key" cd $DOKKU_ROOT rm -rf $TEMP_DIR dokku nginx:build-config $APP From dc5f34534b05ce11acd195cf85cce895f1cbe6d7 Mon Sep 17 00:00:00 2001 From: Adam Vigneaux Date: Sun, 26 Jul 2015 22:37:56 -0400 Subject: [PATCH 2/3] Improve formatting --- plugins/nginx-vhosts/commands | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 8e221affd..0d9a53125 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -162,17 +162,17 @@ EOF cd $TEMP_DIR tar xvf - <&0 - crt_count = $(ls -1 *.crt | wc -l) - if [[ $crt_count -lt 1 ]]; then + CRT_FILE_COUNT=$(ls -1 ./*.crt | wc -l) + if [[ $CRT_FILE_COUNT -lt 1 ]]; then echo "Tar archive is missing .crt file" && exit 1 - elif [[ $crt_count -gt 1 ]]; then + elif [[ $CRT_FILE_COUNT -gt 1 ]]; then echo "Tar archive contains more than one .crt file" && exit 1 fi - key_count = $(ls -1 *.key | wc -l) - if [[ $key_count -lt 1 ]]; then + KEY_FILE_COUNT=$(ls -1 ./*.key | wc -l) + if [[ $KEY_FILE_COUNT -lt 1 ]]; then echo "Tar archive is missing .key file" && exit 1 - elif [[ $key_count -gt 1 ]]; then + elif [[ $KEY_FILE_COUNT -gt 1 ]]; then echo "Tar archive contains more than one .key file" && exit 1 fi From c1a0e0ce68a7a4c68b343e2bb63f9ea0a68559bf Mon Sep 17 00:00:00 2001 From: Adam Vigneaux Date: Tue, 28 Jul 2015 18:48:31 -0400 Subject: [PATCH 3/3] Improve file searching and variable usage - Count files using find and grep instead of ls and wc - Use the same variable to find files and move files, allowing files to be in a subdirectory --- plugins/nginx-vhosts/commands | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 0d9a53125..ed2a70e6b 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -162,23 +162,30 @@ EOF cd $TEMP_DIR tar xvf - <&0 - CRT_FILE_COUNT=$(ls -1 ./*.crt | wc -l) + CRT_FILE_SEARCH=$(find . -type f -name "*.crt") + CRT_FILE_COUNT=$(printf "%s" "$CRT_FILE_SEARCH" | grep -c '^') if [[ $CRT_FILE_COUNT -lt 1 ]]; then echo "Tar archive is missing .crt file" && exit 1 elif [[ $CRT_FILE_COUNT -gt 1 ]]; then echo "Tar archive contains more than one .crt file" && exit 1 + else + CRT_FILE=$CRT_FILE_SEARCH fi - KEY_FILE_COUNT=$(ls -1 ./*.key | wc -l) + KEY_FILE_SEARCH=$(find . -type f -name "*.key") + KEY_FILE_COUNT=$(printf "%s" "$KEY_FILE_SEARCH" | grep -c '^') if [[ $KEY_FILE_COUNT -lt 1 ]]; then echo "Tar archive is missing .key file" && exit 1 elif [[ $KEY_FILE_COUNT -gt 1 ]]; then echo "Tar archive contains more than one .key file" && exit 1 + else + KEY_FILE=$KEY_FILE_SEARCH fi + mkdir -p "$DOKKU_ROOT/$APP/tls" - mv "$TEMP_DIR/*.crt" "$DOKKU_ROOT/$APP/tls/server.crt" - mv "$TEMP_DIR/*.key" "$DOKKU_ROOT/$APP/tls/server.key" + mv "$CRT_FILE" "$DOKKU_ROOT/$APP/tls/server.crt" + mv "$KEY_FILE" "$DOKKU_ROOT/$APP/tls/server.key" cd $DOKKU_ROOT rm -rf $TEMP_DIR dokku nginx:build-config $APP