Guest User

Untitled

a guest
Oct 25th, 2017
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ## Refresh database, files, and import configuration
  4. ##
  5. ## Usage: fin d7-refresh
  6.  
  7. # Abort if anything fails
  8. set -e
  9.  
  10. while getopts 'a:s:e:' flag; do
  11. case $flag in
  12. a)
  13. TERMINUS_EMAIL=${OPTARG}
  14. ;;
  15. s)
  16. PANTHEON_SITE=${OPTARG}
  17. ;;
  18. e)
  19. PANTHEON_ENV=${OPTARG}
  20. ;;
  21. esac
  22. done
  23.  
  24. TMP_USER=$(terminus whoami);
  25. DOCROOT=${DOCROOT:-docroot};
  26. SITE_DIRECTORY=${SITE_DIRECTORY:-default};
  27.  
  28. if [ "$TMP_USER" != "$TERMINUS_EMAIL" ]; then
  29. terminus login --email=$TERMINUS_EMAIL
  30. fi;
  31.  
  32. DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}"
  33. SITEDIR_PATH="${DOCROOT_PATH}/sites/${SITE_DIRECTORY}"
  34.  
  35. cd $PROJECT_ROOT
  36.  
  37. cd $SITEDIR_PATH
  38.  
  39. terminus env:wake ${PANTHEON_SITE}.${PANTHEON_ENV}
  40.  
  41. # Rsync all files
  42. echo "Downloading latest set of files from ${PANTHEON_SITE}..."
  43. terminus rsync ${PANTHEON_SITE}.${PANTHEON_ENV}:files .
  44.  
  45. echo "Fixing files directory permissions..."
  46. chmod -R 755 files
  47.  
  48. DBFILE="/tmp/${PANTHEON_SITE}.sql"
  49. if [ ! -f $DBFILE ] || [ ! -z $(find $DBFILE -mmin +3600) ] ; then
  50. echo "$somefile is older then 1 hours"
  51.  
  52. echo 'Exporting latest database...'
  53. if [ -f $DBFILE ] && [ ! -z $(find $DBFILE -mmin +3600) ]; then
  54. rm -rf $DBFILE
  55. fi
  56.  
  57. DBCONN=$(terminus connection:info ${PANTHEON_SITE}.${PANTHEON_ENV} --field="MySQL Command");
  58. DBDUMP=${DBCONN/mysql /mysqldump }
  59. eval $DBDUMP " --result-file=${DBFILE}"
  60. fin db import $DBFILE
  61. else
  62. fin db import $DBFILE
  63. fi
  64.  
  65. fin exec "if [ ! -d ~/tmp ]; then mkdir ~/tmp; fi"
  66.  
  67. cd ${DOCROOT_PATH}
  68.  
  69. echo "Running Update.php..."
  70. fin drush updatedb -y
  71.  
  72. echo "Set User 1s name to admin..."
  73. fin drush sql-query "UPDATE users SET mail=\"admin@example.com\", name=\"admin\" WHERE uid=1"
  74.  
  75. echo "Reseting user 1 password to admin..."
  76. fin drush user-password admin --password=admin
Add Comment
Please, Sign In to add comment