#!/bin/bash # Creates alias symlinks to create site aliases # Symlinks are created both in the group root dir and # the alias target site dir's "sites" directory. # include library file . "`dirname ${0}`/drupalLibrary.sh" printUsage() { echo -e " " echo -e "Creates alias symlinks to create an alias on a drupal installation (or all installations in a group)." echo -e "For more info, see script header." echo -e " " echo -e "Usage:" echo -e "$0 [-quiet] {-remove | } [install group root dir]" echo -e "where:" echo -e " " echo -e "-quiet minimizes output." echo -e " " echo -e "" echo -e "\tIf specified with -remove, removes an existing alias." echo -e " " echo -e "" echo -e "\tThe name of the new alias for the given site." echo -e " " outputInstallGroupUsage echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi # Handle flags while (true); do case "${1}" in -quiet ) pQuiet="-quiet" shift ;; -remove ) if [ $# == 1 ]; then echo -e "** Must specify an alias to remove with -remove. Aborting.\n" printUsage exit 1 fi pRemove="${2}" shift; shift ;; * ) break ;; esac done if [ -z "${pQuiet}" ]; then echo " " fi # Process if [ -z "${pRemove}" ]; then # # New alias # check parameters -- need 2 or 3 parameters if [ $# -lt 2 -o $# -gt 3 ]; then echo -e "** Invalid number of parameters specified. Aborting.\n" printUsage exit 1 fi pNewAlias=${1} # process Group Root Dir pRootDir="`getGroupRootDir "${3}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi # Validate the installation pInstall="${2}" errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}. Aborting.\n" exit 1 fi # process errorStr="`createSiteAlias "${pNewAlias}" "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error creating alias '${pNewAlias}' for site '${pInstall}': ${errorStr}\n" fi else # # Remove alias # check parameters -- can only have one (optional) parameter (the group root dir) if [ $# -gt 1 ]; then echo -e "** Invalid number of parameters specified. Aborting.\n" printUsage exit 1 fi # process Group Root Dir pRootDir="`getGroupRootDir "${1}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi # Validate the alias errorStr="`validateAlias "${pRemove}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified alias: ${errorStr}. Aborting.\n" exit 1 fi # process errorStr="`removeSiteAlias "${pRemove}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error removing symlink: ${errorStr}\n" exit 1 fi fi # Done if [ -z "${pQuiet}" ]; then echo -e "** Done." fi