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
This commit is contained in:
@@ -162,23 +162,30 @@ EOF
|
|||||||
cd $TEMP_DIR
|
cd $TEMP_DIR
|
||||||
tar xvf - <&0
|
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
|
if [[ $CRT_FILE_COUNT -lt 1 ]]; then
|
||||||
echo "Tar archive is missing .crt file" && exit 1
|
echo "Tar archive is missing .crt file" && exit 1
|
||||||
elif [[ $CRT_FILE_COUNT -gt 1 ]]; then
|
elif [[ $CRT_FILE_COUNT -gt 1 ]]; then
|
||||||
echo "Tar archive contains more than one .crt file" && exit 1
|
echo "Tar archive contains more than one .crt file" && exit 1
|
||||||
|
else
|
||||||
|
CRT_FILE=$CRT_FILE_SEARCH
|
||||||
fi
|
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
|
if [[ $KEY_FILE_COUNT -lt 1 ]]; then
|
||||||
echo "Tar archive is missing .key file" && exit 1
|
echo "Tar archive is missing .key file" && exit 1
|
||||||
elif [[ $KEY_FILE_COUNT -gt 1 ]]; then
|
elif [[ $KEY_FILE_COUNT -gt 1 ]]; then
|
||||||
echo "Tar archive contains more than one .key file" && exit 1
|
echo "Tar archive contains more than one .key file" && exit 1
|
||||||
|
else
|
||||||
|
KEY_FILE=$KEY_FILE_SEARCH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
mkdir -p "$DOKKU_ROOT/$APP/tls"
|
mkdir -p "$DOKKU_ROOT/$APP/tls"
|
||||||
mv "$TEMP_DIR/*.crt" "$DOKKU_ROOT/$APP/tls/server.crt"
|
mv "$CRT_FILE" "$DOKKU_ROOT/$APP/tls/server.crt"
|
||||||
mv "$TEMP_DIR/*.key" "$DOKKU_ROOT/$APP/tls/server.key"
|
mv "$KEY_FILE" "$DOKKU_ROOT/$APP/tls/server.key"
|
||||||
cd $DOKKU_ROOT
|
cd $DOKKU_ROOT
|
||||||
rm -rf $TEMP_DIR
|
rm -rf $TEMP_DIR
|
||||||
dokku nginx:build-config $APP
|
dokku nginx:build-config $APP
|
||||||
|
|||||||
Reference in New Issue
Block a user