#!/bin/bash # This script will download and a Drupal intallation # template from toddgee.com and install it locally # as a new Drupal installation. # # You can read more about this at http://toddgee.com/node/72 # # This script requires wget to be installed... # Much of this script was taken from drupalSiteCopy.sh # include library file . "`dirname ${0}`/drupalLibrary.sh" # The parameter values used to denote the different drupal versions D6_PARAM="-d6" D7_PARAM="-d7" # The installation names for the template installs D6_TEMPLATE_NAME="d6template.toddgee.com" D7_TEMPLATE_NAME="d7template.toddgee.com" # These are files attached to the page referenced above TEMPLATE_URL="http://toddgee.com/sites/toddgee.com/files" D6_TEMPLATE_FILE="d6template.toddgee.com_.tar_.gz" D7_TEMPLATE_FILE="d7template.toddgee.com_.tar_.gz" printUsage() { echo -e " " echo -e "Downloads and installs a Drupal intallation template from toddgee.com." echo -e " " echo -e "Usage:" echo -e "$0 <-d6 | -d7> [-noconfirm] [install group root dir]" echo -e "where:" echo -e " " echo -e "-d6 | -d7" echo -e "\tSpecifies Drupal version." echo -e "-noconfirm Supresses the confirmation request." echo -e " " echo -e "" echo -e "\tThe name of the new installation." echo -e " " echo -e "\tThe database host, name, and user/password with which to connect to the database for the new site." echo -e " " outputGroupRootDirUsage echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi echo " " # Handle flags while (true); do case "${1}" in ${D6_PARAM} ) if [ -n "${pDrupalVer}" ]; then echo -e "** Can specify only one Drupal version parameter. Aborting.\n" printUsage exit 1 fi pDrupalVer="${1}" shift ;; ${D7_PARAM} ) if [ -n "${pDrupalVer}" ]; then echo -e "** Can specify only one Drupal version parameter. Aborting.\n" printUsage exit 1 fi pDrupalVer="${1}" shift ;; -noconfirm ) pNoConfirm="-noconfirm"; shift ;; * ) break ;; esac done # ensure drupal version parameter set if [ -z "${pDrupalVer}" ]; then echo -e "** No Drupal version parameter specified. Aborting.\n" printUsage exit 1 fi # Save parameters if [ $# -lt 5 ]; then echo -e "** Invalid number of parameters supplied. Aborting\n" printUsage exit 1 fi targetInstall="${1}" targetDbHostName="${2}" targetDbName="${3}" targetDbUsername="${4}" targetDbPassword="${5}" # process Group Root Dir pRootDir="`getGroupRootDir "${6}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi # Set up parameters based on version case "${pDrupalVer}" in ${D6_PARAM} ) whatStr="Drupal 6" templateName="${D6_TEMPLATE_NAME}" tarFile="${D6_TEMPLATE_FILE}" ;; ${D7_PARAM} ) whatStr="Drupal 7" templateName="${D7_TEMPLATE_NAME}" tarFile="${D7_TEMPLATE_FILE}" ;; esac # ensure the template name doesn't already exist if [ -d "${pRootDir}/${templateName}" ]; then echo -e "** Template target directory '${templateName}' already exists. Aborting.\n" exit 1 fi # ensure target installation is not already a site targetDir="`getTargetDir "${targetInstall}" "${pRootDir}"`" if [ -d "${targetDir}" ]; then echo -e "** Site target directory '${targetDir}' already exists. Aborting.\n" exit 1 fi # Ensure wget is installed wgetBinary="`which wget 2>/dev/null`" if [ -z "${wgetBinary}" ]; then echo -e "** wget binary not found. Aborting.\n" exit 1 fi # Check drush drupalScriptLibraryDir="`dirname ${0}`" errorStr="`validateDrushInstallation "${drupalScriptLibraryDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with Drush: ${errorStr}\n" exit 1 fi ######### if [ -z "${pNoConfirm}" ]; then echo "Downloading ${whatStr} template for site '${targetInstall}'." echo "This will clobber the database specified on the command line." echo "Press to continue, or ^C to quit..." read fi # test db connection echo -n "Testing target site db connection information.... " errorStr="`testDBConnectionForParameters "${targetDbHostName}" "${targetDbName}" "${targetDbUsername}" "${targetDbPassword}"`" if [ -n "${errorStr}" ]; then echo -e "\n** Unable to connect to configured target database: ${errorStr}. Aborting.\n" exit 1 fi echo "done." # Download and extract template tarfile echo -n "Downloading and extracting template tarfile.... " cd "${pRootDir}" /bin/rm -f "${tarFile}" "${wgetBinary}" -q "${TEMPLATE_URL}/${tarFile}" if [ ! -f "${tarFile}" ]; then echo "** Unable to log into site to perform reset tasks. Aborting." exit 1 fi tar -xzf "${tarFile}" /bin/rm -f "${tarFile}" echo "done." # Migrate site to new name echo -n "Migrating template site to new name.... " /bin/mv -f "${templateName}" "${targetInstall}" /bin/mv -f "${targetInstall}/sites/${templateName}" "${targetInstall}/sites/${targetInstall}" echo "done." # Set database connection parameters into new site echo -n "Setting db connection info into target site settings file.... " setDBName "${targetInstall}" "${pRootDir}" "${targetDbName}" setDBHost "${targetInstall}" "${pRootDir}" "${targetDbHostName}" setDBUsername "${targetInstall}" "${pRootDir}" "${targetDbUsername}" setDBPassword "${targetInstall}" "${pRootDir}" "${targetDbPassword}" echo "done." # Clobber target database echo -n "Clobbering target database.... " dbConnection="`getDBConnectionString "${targetInstall}" "${pRootDir}"`" dropAllTables "${dbConnection}" echo "done." # Initialize database from dump echo -n "Initializing target database.... " dbDumpFile="${targetInstall}/sites/${targetInstall}/backups/${templateName}.dump" cat "${dbDumpFile}" | ${MYSQL} ${dbConnection} echo "done." # Reset admin password and files directory on target echo -n "Resetting admin password of target install.... " "`dirname $0`/drupalDBQuery.sh" -quiet resetadmin "${targetInstall}" "${pRootDir}" "`dirname $0`/drupalDBQuery.sh" -quiet fileupload "${targetInstall}" "${pRootDir}" echo "done." # Reset permissions on target install echo -n "Resetting permissions of target install.... " "`dirname $0`/drupalSetPerms.sh" "${targetInstall}" "${pRootDir}" echo "done." # Reset content on new site echo -n "Performing content reset tasks.... " cookiesFile="`loginToSiteAsAdmin "${targetInstall}" "${pTargetRootDir}"`" if [ -n "${cookiesFile}" -a -f "${cookiesFile}" ]; then # pages downloaded depend on version case "${pDrupalVer}" in ${D6_PARAM} ) downloadPage "${targetInstall}" "admin/build/themes" "${cookiesFile}" > /dev/null downloadPage "${targetInstall}" "admin/build/modules" "${cookiesFile}" > /dev/null downloadPage "${targetInstall}" "admin/build/menu" "${cookiesFile}" > /dev/null ;; ${D7_PARAM} ) downloadPage "${targetInstall}" "admin/appearance/list" "${cookiesFile}" > /dev/null downloadPage "${targetInstall}" "admin/modules" "${cookiesFile}" > /dev/null downloadPage "${targetInstall}" "admin/structure/menu" "${cookiesFile}" > /dev/null ;; esac rm -f "${cookiesFile}" else echo "** Unable to log into site to perform reset tasks. Continuing." fi echo "done." # Clear caches and do other tasks for the modules enabled in the templates echo -n "Performing tasks required by installed modules.... " # Clear cache "`dirname $0`/drupalDBQuery.sh" clearcache "${targetInstall}" "${pRootDir}" # Disable then re-enable the 'logintoboggan' module executeDrushCommand "${drupalScriptLibraryDir}" "${targetInstall}" "${pRootDir}" -y pm-disable logintoboggan executeDrushCommand "${drupalScriptLibraryDir}" "${targetInstall}" "${pRootDir}" -y pm-enable logintoboggan echo "done." echo -e "\n** Done."