Skip to content

Add unattended option if not syncing to production #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +33,10 @@ while [[ $# -gt 0 ]]; do
LOCAL=true
shift
;;
--unattended)
UNATTENDED=true
shift
;;
--*)
echo "Unknown option $1"
exit 1
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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