#!/bin/bash # Copies an installed drupal theme, either a downloaded # # This script helps maintain a drupal installation group. # include library file . "`dirname ${0}`/drupalLibrary.sh" # Dumps out script usage printUsage() { echo -e " " echo -e "Copies existing, but versioned, themes for local modification." echo -e " " echo -e "Usage: " echo -e "\t`basename $0` [-noconfirm] [ -copyname ] [install group root dir]" echo -e " " echo -e " is the name of an existing theme to copy." echo -e "\tThis can be a core theme (part of the drupal install, found in /themes) or" echo -e "\ta contrib theme (downloaded, found in the 'themes/contrib' dir for a site)." echo -e " " echo -e " is the target name of the dir." echo -e "\tIf -copyname is specified, this will be the resulting theme." echo -e "\tIf not specified, the target name is the install name." echo -e " " outputInstallGroupUsage echo -e " " echo -e "-noconfirm supresses comfirmation request on non-reporting operations" echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi echo " " # Handle flags while (true); do case "${1}" in -noconfirm ) pNoConfirm="-noconfirm" shift ;; -copyname ) shift pTargetName="$1" shift ;; * ) break; ;; esac done if [ $# -lt 2 -o $# -gt 3 ]; then echo -e "** Invalid number of parameters specified\n" printUsage exit 1 fi pSourceTheme="${1}" pInstall="${2}" if [ -z "${pTargetName}" ]; then pTargetName="${pInstall}" fi # process Group Root Dir pRootDir="`getGroupRootDir "${3}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi ###################### # Validate site errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}\n" exit 1 fi # Find source theme. Look at core themes first. targetDir="`getTargetDir "${pInstall}" "${pRootDir}"`" contribThemeDir="`getContribThemeDir "${pInstall}" "${pRootDir}"`" if [ -d "${targetDir}/themes/${pSourceTheme}" ]; then echo "Copying core theme '${pSourceTheme}' as (new) theme '${pTargetName}'" themeSourceDir="${targetDir}/themes/${pSourceTheme}" elif [ -d "${contribThemeDir}/${pSourceTheme}" ]; then echo "Copying contrib theme '${pSourceTheme}' as (new) theme '${pTargetName}'" themeSourceDir="${contribThemeDir}/${pSourceTheme}" else echo -e "** Theme '${pSourceTheme}' not found in core or contrib directories. Aborting.\n" exit 1 fi # Destination themeDestDir="`getThemeDir "${pInstall}" "${pRootDir}"`/${pTargetName}" if [ -d "${themeDestDir}" ]; then echo -e "** Destination theme directory '${themeDestDir}' already exists. Aborting.\n" exit 1 fi echo "Destination directory: '${themeDestDir}'" if [ -z "${pNoConfirm}" ]; then echo "" echo "Press to continue, or ^C to quit..." read fi # Copy cp -r "${themeSourceDir}" "${themeDestDir}" || { echo -e "** Unable to copy theme directory. Aborting.\n" exit 1 } # Remove .git directory if it exists cd "${themeDestDir}" || { echo -e "** Cannot cd to (just created) theme target directory '${themeDestDir}'. Aborting.\n" } rm -rf .git # Done echo -e "\n** Done."