Skip to content

Instantly share code, notes, and snippets.

@sean-e-dietrich
Created October 24, 2017 16:11
Show Gist options
  • Save sean-e-dietrich/f3d4c7ea394f8506a2d35567af7f9954 to your computer and use it in GitHub Desktop.
Save sean-e-dietrich/f3d4c7ea394f8506a2d35567af7f9954 to your computer and use it in GitHub Desktop.
D7 Docksal Refresh
#!/usr/bin/env bash
## Refresh database, files, and import configuration
##
## Usage: fin d7-refresh
# Abort if anything fails
set -e
while getopts 'a:s:e:' flag; do
case $flag in
a)
TERMINUS_EMAIL=${OPTARG}
;;
s)
PANTHEON_SITE=${OPTARG}
;;
e)
PANTHEON_ENV=${OPTARG}
;;
esac
done
TMP_USER=$(terminus whoami);
DOCROOT=${DOCROOT:-docroot};
SITE_DIRECTORY=${SITE_DIRECTORY:-default};
if [ "$TMP_USER" != "$TERMINUS_EMAIL" ]; then
terminus login --email=$TERMINUS_EMAIL
fi;
DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}"
SITEDIR_PATH="${DOCROOT_PATH}/sites/${SITE_DIRECTORY}"
cd $PROJECT_ROOT
cd $SITEDIR_PATH
terminus env:wake ${PANTHEON_SITE}.${PANTHEON_ENV}
# Rsync all files
echo "Downloading latest set of files from ${PANTHEON_SITE}..."
terminus rsync ${PANTHEON_SITE}.${PANTHEON_ENV}:files .
echo "Fixing files directory permissions..."
chmod -R 755 files
DBFILE="/tmp/${PANTHEON_SITE}.sql"
if [ ! -f $DBFILE ] || [ ! -z $(find $DBFILE -mmin +3600) ] ; then
echo "$somefile is older then 1 hours"
echo 'Exporting latest database...'
if [ -f $DBFILE ] && [ ! -z $(find $DBFILE -mmin +3600) ]; then
rm -rf $DBFILE
fi
DBCONN=$(terminus connection:info ${PANTHEON_SITE}.${PANTHEON_ENV} --field="MySQL Command");
DBDUMP=${DBCONN/mysql /mysqldump }
eval $DBDUMP " --result-file=${DBFILE}"
fin db import $DBFILE
else
fin db import $DBFILE
fi
fin exec "if [ ! -d ~/tmp ]; then mkdir ~/tmp; fi"
cd ${DOCROOT_PATH}
echo "Running Update.php..."
fin drush updatedb -y
echo "Set User 1s name to admin..."
fin drush sql-query "UPDATE users SET mail=\"admin@example.com\", name=\"admin\" WHERE uid=1"
echo "Reseting user 1 password to admin..."
fin drush user-password admin --password=admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment