From 333a634b5fafef2777138c88eb8e88a56d826e3e Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Thu, 6 Apr 2023 14:56:08 -0400 Subject: [PATCH] Add unattended option if not syncing to production --- sync.sh | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/sync.sh b/sync.sh index 76479a5..2882c56 100755 --- a/sync.sh +++ b/sync.sh @@ -16,6 +16,7 @@ STAGSITE="https://staging.example.com" LOCAL=false SKIP_DB=false SKIP_ASSETS=false +UNATTENDED=false POSITIONAL_ARGS=() while [[ $# -gt 0 ]]; do @@ -32,6 +33,10 @@ while [[ $# -gt 0 ]]; do LOCAL=true shift ;; + --unattended) + UNATTENDED=true + shift + ;; --*) echo "Unknown option $1" exit 1 @@ -83,11 +88,28 @@ then exit; fi -echo -echo "Would you really like to " -echo $DB_MESSAGE -echo $ASSETS_MESSAGE -read -r -p " [y/N] " response +# If unattended is true, and the target is production, exit +if [ "$UNATTENDED" = true ] && [ "$TO" = "production" ] +then + echo "You cannot sync to production in unattended mode." + exit; +fi + +# If unattended is false, prompt the user +if [ "$UNATTENDED" = false ] +then + echo + echo "Would you really like to " + echo $DB_MESSAGE + echo $ASSETS_MESSAGE + read -r -p " [y/N] " response +fi + +# If unattended is true, or the user responds with Y or y, continue +if [ "$UNATTENDED" = true ] +then + response="y" +fi if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then # Change to site directory @@ -175,3 +197,5 @@ if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then # fi echo -e "\nšŸ”„ Sync from $FROM to $TO complete.\n\n ${bold}$TOSITE${normal}\n" fi + +fi