#!/bin/bash # A script to update drupal installations. # # This script will either update an installation in place # or optionally copy the site to a development site so the # update process can be performed in a sandbox. # # This script produces lots of console output (mostly because # of the other scripts that are called) so it uses output # prefixes for the lines it generates. # # Requires that Drush be in place -- see drupalManageDrush.sh # include library file . "`dirname ${0}`/drupalLibrary.sh" printUsage() { echo -e " " echo -e "Performs automated updates on drupal sites." echo -e "For more info, see script header." echo -e " " echo -e "Usage:" echo -e "\t`basename $0` [-noconfirm] [-usedev ] ( | all ) [install group root dir]" echo -e " " echo -e "-noconfirm Supresses the confirmation request." echo -e " " echo -e "" echo -e "\tIf specified, the domain of the test site that will be used" echo -e "\tto test updates on the installation before done to the live site." echo -e "\tWill prompt after manual site comparison is made (even if -noconfirm is specified)." echo -e "\tNote: This site will be clobbered in the operation of the script." echo -e " " outputInstallGroupUsage foo echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi # Handle flags while (true); do case "${1}" in -noconfirm ) pNoconfirm="-noconfirm" shift ;; -usedev ) if [ $# == 1 ]; then echo -e "** Must specify a dev site with -usedev. Aborting.\n" printUsage exit 1 fi pUpdateTestSite="${2}" shift; shift ;; * ) break ;; esac done echo " " # process Group Root Dir pRootDir="`getGroupRootDir "${2}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi pInstall="$1" if [ "`toLower "${pInstall}"`" == "all" ]; then pInstall="`getSitesInGroupDir "${pRootDir}"`" else # Validate the installation errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}\n" exit 1 fi fi # Test update test site if [ -n "${pUpdateTestSite}" ]; then errorStr="`validateSite "${pUpdateTestSite}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified update test site: ${errorStr}\n" exit 1 fi fi # Check drush drupalScriptLibraryDir="`dirname ${0}`" errorStr="`validateDrushInstallation "${drupalScriptLibraryDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with Drush: ${errorStr}\n" exit 1 fi ########################## # A script to run the update via drush # Asks for manual intervention if update fails. # $1 - Drupal Script Library installation directory # $2 - the install name # $3 - the install group root dir. # $4 the "notice log prefix" # $5 the "error log prefix" drushUpdateDB() { drupalScriptLibraryDir="${1}" site="${2}" pRootDir="${3}" noticeLogPrefix="${4}" errorLogPrefix="${5}" # Run drush update process executeDrushCommand "${drupalScriptLibraryDir}" "${site}" "${pRootDir}" -y updatedb || { echo -e "\n${errorLogPrefix} Drush update failed. Preparing manual update." echo -e "\n${noticeLogPrefix} Turning off access check for site." "${drupalScriptLibraryDir}/drupalSetAccessCheck.sh" false "${site}" echo -e "\tUpdate site by visiting http://${site}/update.php" echo -e "\tHit when complete or ^C to abort." read echo -e "\n${noticeLogPrefix} Turning access check back on for site." "${drupalScriptLibraryDir}/drupalSetAccessCheck.sh" true "${site}" } } ########################## # Process if [ -z "${pNoconfirm}" ]; then if [ -n "`echo "${pInstall}" | grep " "`" ]; then echo "Updating ALL sites." else echo "Updating site: '${pInstall}'" fi if [ -n "${pUpdateTestSite}" ]; then echo "Using site '${pUpdateTestSite}' as the test update site." echo -e "\tThis site will be clobbered." fi echo "Press to continue, or ^C to quit..." read fi for uipSite in ${pInstall}; do # Create logging output prefixes to include site name. logBase="`basename ${0}`: Site '${uipSite}':" noticeLogPrefix="%%% ${logBase}" warningLogPrefix="%%% !!! ${logBase}" errorLogPrefix="%%% *** ${logBase}" echo -e "\n${noticeLogPrefix} Starting processing." # Take site offline echo -e "\n${noticeLogPrefix} Taking in-process site offline." "`dirname ${0}`/drupalDBQuery.sh" setoffline "${uipSite}" "${pRootDir}" # Are we using the copy-to-test-site method? if [ -n "${pUpdateTestSite}" ]; then # Copy site to update domain echo -e "\n${noticeLogPrefix} Performing site copy from in-process site to test site." "`dirname ${0}`/drupalSiteCopy.sh" -noconfirm "${uipSite}" "${pUpdateTestSite}" "${pRootDir}" # Update test site echo -e "\n${noticeLogPrefix} Performing code update on test site." "`dirname ${0}`/drupalGitDeploy.sh" -noconfirm update all "${pUpdateTestSite}" "${pRootDir}" # Run drush update process echo -e "\n${noticeLogPrefix} Running update.php on test site." drushUpdateDB "${drupalScriptLibraryDir}" "${pUpdateTestSite}" "${pRootDir}" "${noticeLogPrefix}" "${errorLogPrefix}" ## Run comparison tests # For now, we'll just ask user to perform an evaluation of the test site # in the future, it'd be neat to have some sort of automated site comparison test here. # Set test site online (so we can check it for goodness) echo -e "\n${noticeLogPrefix} Restoring test site online." "`dirname ${0}`/drupalDBQuery.sh" setonline "${pUpdateTestSite}" echo -e "\n${noticeLogPrefix} Test site http://${pUpdateTestSite}/ updated. Login info:" "`dirname ${0}`/drupalReport.sh" admin ${pUpdateTestSite} | while read line; do echo -e "\t${line}" done response=""; while [[ "${response}" != "y" && "${response}" != "n" ]]; do echo -e "Enter 'y' to accept update as proper." echo -e "\t(and proceed with update of original site)" echo -e "Enter 'n' to abort update on original site." read response done ## Did tests complete successfully? if [ "${response}" == "n" ]; then echo -e "\n${errorLogPrefix} Site failed comparison test. Leaving site un-updated." # Set site online again echo -e "\n${noticeLogPrefix} Restoring in-process site online." "`dirname ${0}`/drupalDBQuery.sh" setonline "${uipSite}" continue fi echo -e "\n${noticeLogPrefix} Update on test site successful. Proceeding update on in-process site." fi # If here either running: # Update w/o test site support support or # Update w/ test site support that compared correctly # Update site core echo -e "\n${noticeLogPrefix} Performing drupal code update on in-process site." "`dirname ${0}`/drupalGitDeploy.sh" -noconfirm update drupal "${uipSite}" # Update site modules # (grep for module .css updates? if they exist send warning) echo -e "\n${noticeLogPrefix} Performing module code update on in-process site." "`dirname ${0}`/drupalGitDeploy.sh" -noconfirm update allmodules "${uipSite}" # run drush update process echo -e "\n${noticeLogPrefix} Running update.php on in-process site." drushUpdateDB "${drupalScriptLibraryDir}" "${uipSite}" "${pRootDir}" "${noticeLogPrefix}" "${errorLogPrefix}" # Set site online again echo -e "\n${noticeLogPrefix} Restoring in-process site online." "`dirname ${0}`/drupalDBQuery.sh" setonline "${uipSite}" # Done with this site. echo -e "\n${noticeLogPrefix} Done processing.\n" let numprocessed=$numprocessed+1 done # Take test site offline (just cleanup) if [ -n "${pUpdateTestSite}" ]; then echo -e "\n%%% Updating Done. Taking test site offline." "`dirname ${0}`/drupalDBQuery.sh" setoffline "${pUpdateTestSite}" fi echo -e "\n** Done processing ${numprocessed} sites.\n"