#!/bin/bash # Last updated on 2014-11-21 # Version 7.x-2.4 # # List of all Functions # # error: captures errors throughout the script and exits # basicinfo: collects download location and feature choice from user # logcreate: creates Log file # setdirs: set full paths for download types and create subdomain folder # downloadall: calls functions and sets variables for each download # downloaduncompress: downloads and expands a file, then cleans up # enddownloads: outputs final script messages and instructions for user # # # List of all Variables # # Root Directory and Web Hosting variables CURRENT_DIR="${PWD}" MY_HOST=${HOSTNAME:0:9} if [ "${MY_HOST}" == 'web-plesk' ] ; then ON_WEBHOSTING='y' WEBHOSTNAME=$(tail -1 /etc/passwd | awk '{split($0,usertail,":"); print usertail[1]}') ROOT_DIR='/httpdocs' else ON_WEBHOSTING='n' WEBHOSTNAME="not-on-web-hosting" ROOT_DIR="${CURRENT_DIR}" fi # Version, Name and Label variables for Basic & Feature files VERSION_BASIC='7-20141120' NAME_BASIC='gtd-basic' LABEL_BASIC='Basic GT Drupal' VERSION_MULTISITE='7-20141120' NAME_MULTISITE='gtd-basic' LABEL_MULTISITE='Basic GT Drupal (for a multi-site)' VERSION_SLIDESHOW='7-20141120' NAME_SLIDESHOW='gtd-slideshow' LABEL_SLIDESHOW='GT Carousel Slideshow' VERSION_CALENDAR='7-20141120' NAME_CALENDAR='gtd-calendar' LABEL_CALENDAR='GT Calendar' VERSION_CT_TOOLKIT='7-20141120' NAME_CT_TOOLKIT='gtd-ct-toolkit' LABEL_CT_TOOLKIT='Content Type Toolkit' # Feature Choice variables FEATURE_CHOICE='0' FEATURE_SLIDESHOW='n' FEATURE_CALENDAR='n' FEATURE_CT_TOOLKIT='n' # Script Step variables BACKUP_DONE='n' IN_CURRENT='y' # File Download variables SEPARATOR='-' DOWN_DIR=${ROOT_DIR} DOWN_PATH_START='http://drupal.gatech.edu/sites/default/files/resources/' DOWN_PATH_END='.zip' DOWN_MESSAGE_START=' We are now: Downloading files for ' DOWN_MESSAGE_END='...' SUCCESS_MESSAGE_START='FINISHED!' # # Function: Call this after every file operation to capture failures and exit # function error () { echo "ERROR -- $@" exit } # # Function: create Log file # function logcreate () { # Prepare Log file in root downloads directory cd "${ROOT_DIR}" || error echo "Cannot change directories to ${ROOT_DIR} to create Log file." touch "${ROOT_DIR}"/LOG.log || error "Failed to create LOG.log file in ${ROOT_DIR}." # Capture all subsequent stdout and stderr to ${LOG} LOG="${ROOT_DIR}/LOG.log" || error "Cannot add a message to the LOG file at ${ROOT_DIR}/LOG.log" } # # Function: set full directory paths for downloaduncompress function to use # function setdirs () { # Set global download paths for values that are context-independent FULL_PROFILES_DIR="${ROOT_DIR}/profiles" FULL_SITES_DIR="${ROOT_DIR}/sites" FULL_ALL_DIR="${FULL_SITES_DIR}/all" # Set global download paths for values that might differ FULL_DEFAULT_DIR="${FULL_SITES_DIR}"'/'"${MULTISITE_DIR}" FULL_FILE_DIR="${FULL_DEFAULT_DIR}/files" FULL_THEMES_DIR="${FULL_ALL_DIR}/themes" FULL_LIBRARIES_DIR="${FULL_ALL_DIR}/libraries" FULL_MOD_DIR="${FULL_ALL_DIR}/modules" # Multi-site specific locations, commented out for now # FULL_THEMES_DIR="${FULL_DEFAULT_DIR}/themes" # FULL_LIBRARIES_DIR="${FULL_DEFAULT_DIR}/libraries" # FULL_MOD_DIR="${FULL_DEFAULT_DIR}/modules" # If multi-site, create subdomain directory under sites folder if [[ "${MULTISITE}" == 'y' && ! -d "${FULL_DEFAULT_DIR}" ]]; then mkdir -p "${FULL_DEFAULT_DIR}" >> ${LOG} 2>&1 || error " Failed to create multi-site subdomain folder at ${FULL_DEFAULT_DIR}" fi } # # Function: gather download location and feature choices for GT Drupal from user # function basicinfo () { # # User Interface questions to control download process # cat <> ${LOG} 2>&1 || error " Failed to change directories to ${DOWN_DIR} before downloading ${DOWN_PATH_FULL}." # Grab latest compressed file wget "${DOWN_PATH_FULL}" >> ${LOG} 2>&1 || error " Cannot wget compressed file from ${DOWN_PATH_FULL}" # Expand compressed file if [ "${DOWN_PATH_END}" == '.zip' ] ; then unzip "${NAME_FILE}" >> ${LOG} 2>&1 || error " Cannot unzip ${NAME_FILE} file from ${DOWN_PATH_START} into ${DOWN_DIR}" else error "InCorrect file compression type (${DOWN_PATH_END}) given for expansion of ${NAME_FILE} from ${DOWN_PATH_START} into ${DOWN_DIR} Only the .zip file type is currently supported." fi # Delete compressed file if [[ "${NAME_FILE}" != '*' && "${NAME_FILE}" != '.*' && "${NAME_FILE}" != '*.*' ]] ; then rm "${NAME_FILE}" >> ${LOG} 2>&1 || error "-- ERROR: Could not rm the compressed file (${NAME_FILE}, downloaded via ${DOWN_PATH_START} ) from this directory: ${DOWN_DIR}" else error "InCorrect File (${NAME_FILE}) given for rm, when cleaning compressed file from ${DOWN_DIR}" fi # If mac remnant exists, delete it MAC_REMNANT='__MACOSX' if [[ "${MAC_REMNANT}" != '*' && "${MAC_REMNANT}" != '.*' && "${MAC_REMNANT}" != '*.*' && -d "${MAC_REMNANT}" ]] ; then rm -rf "${MAC_REMNANT}" fi # For basic site files, move files up one level and delete expanded folder if [[ "${DOWN_NAME}" == "${NAME_BASIC}" || "${DOWN_NAME}" == "${NAME_MULTISITE}" ]] ; then # Copy files from expanded folder into download directory cp -rf "${NAME_FOLDER}"/* . >> ${LOG} 2>&1 || error " Could not copy expanded files from (${NAME_FOLDER}) into ${DOWN_DIR} from versioned Subfolder." cp -f "${NAME_FOLDER}"/.htaccess . >> ${LOG} 2>&1 || error " Could not copy .htaccess file into ${DOWN_DIR} from versioned Subfolder." cd "${DOWN_DIR}" >> ${LOG} 2>&1 || error " Failed to move up a directory into ${DOWN_DIR} from versioned Subfolder for ${NAME_FOLDER}." # Delete expanded folder if [[ "${NAME_FOLDER}" != '*' && "${NAME_FOLDER}" != '.*' && "${NAME_FOLDER}" != '*.*' ]] ; then rm -r "${NAME_FOLDER}" >> ${LOG} 2>&1 || error "-- ERROR: Could not rm the expanded folder for (${NAME_FOLDER}) from ${DOWN_DIR}" else error "InCorrect Folder Name (${NAME_FOLDER}) given for rm, when cleaning this expanded folder from ${DOWN_DIR}" fi fi echo "${SUCCESS_MESSAGE}" } # # Function: set variables and call other functions for each download # function downloadall () { # Automatically do Basic site download # Set download variables for basic packages if [ "${MULTISITE}" == 'n' ] ; then DOWN_NAME="${NAME_BASIC}" DOWN_LABEL="${LABEL_BASIC}" DOWN_VERSION="${VERSION_BASIC}" DOWN_DIR="${ROOT_DIR}" elif [ "${MULTISITE}" == 'y' ] ; then DOWN_NAME="${NAME_MULTISITE}" DOWN_LABEL="${LABEL_MULTISITE}" DOWN_VERSION="${VERSION_MULTISITE}" DOWN_DIR="${ROOT_DIR}" else error 'MESSAGE goes here.' fi downloaduncompress # Set folder & file permissions FOLDER_PERM="${FULL_DEFAULT_DIR}" FILE_PERM="${FULL_DEFAULT_DIR}"'/'"settings.php" # Check if any other features were chosen if [ "${FEATURE_CALENDAR}" == 'y' ] ; then DOWN_NAME="${NAME_CALENDAR}-modules" DOWN_LABEL="${LABEL_CALENDAR}" DOWN_VERSION="${VERSION_CALENDAR}" DOWN_DIR="${FULL_MOD_DIR}" downloaduncompress fi if [ "${FEATURE_SLIDESHOW}" == 'y' ] ; then DOWN_NAME="${NAME_SLIDESHOW}-modules" DOWN_LABEL="${LABEL_SLIDESHOW} - Modules" DOWN_VERSION="${VERSION_SLIDESHOW}" DOWN_DIR="${FULL_MOD_DIR}" downloaduncompress DOWN_NAME="${NAME_SLIDESHOW}-libraries" DOWN_LABEL="${LABEL_SLIDESHOW} - Libraries" DOWN_VERSION="${VERSION_SLIDESHOW}" DOWN_DIR="${FULL_LIBRARIES_DIR}" downloaduncompress fi if [ "${FEATURE_CT_TOOLKIT}" == 'y' ] ; then DOWN_NAME="${NAME_CT_TOOLKIT}" DOWN_LABEL="${LABEL_CT_TOOLKIT}" DOWN_VERSION="${VERSION_CT_TOOLKIT}" DOWN_DIR="${FULL_MOD_DIR}" downloaduncompress fi # Call script's ending function enddownloads } basicinfo