From c1a0e0ce68a7a4c68b343e2bb63f9ea0a68559bf Mon Sep 17 00:00:00 2001 From: Adam Vigneaux Date: Tue, 28 Jul 2015 18:48:31 -0400 Subject: [PATCH] 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