#!/bin/bash # A script to manage the libraries required by various Drupal modules. # # Formerly known as 'drupalManageFCKEditor.sh' but migrated into a larger role. # Many Drupal modules require additional downloaded libraries to get them to work. # Rather than writing a separate 'Manage' script for each module, functionality # was combined here. # # Usage requires that the module cooresponding to a library be installed. # # When a library is installed, the downloaded archive file is left to allow future # executions of the script to know the installed version. When run in install # mode, the script will clobber any existing library installation for that # module. Be Warned. # # The convention is to have only one library archive file in the Drupal # module dir at a time -- the one cooresponding to the current/latest version. # include library file . "`dirname ${0}`/drupalLibrary.sh" # Dumps out script usage printUsage() { echo -e " " echo -e "Manages the installation of the library files required for various Drupal modules." echo -e "For more info, see script header." echo -e " " echo -e "Usage: " echo -e "\t`basename $0` [-quiet] [install group root dir]" echo -e " " echo -e "-quiet minimizes output." echo -e " " echo -e " specifies the operation. Options consist of:" echo -e "\tinstall - Installs the library files to a Drupal installation." echo -e "\t\tThis will overwrite any previously installed library files." echo -e "\tquery - Reports on the library file installed." echo -e "\tfindmods - Finds any modifications made to the installed library files." echo -e " " echo -e " is the Drupal module requiring downloaded library support." echo -e "\tThe following are supported: (note -- same as actual module name)" echo -e "\t\tckeditor" echo -e "\t\tfckeditor" echo -e "\t\tjquery_ui" echo -e " " outputInstallGroupUsage echo -e " " } # A function to get the information about all supported 3rd party libraries. # $1 - the name of the module requiring d/led library support # $2 - the operator, one of: # supported - returns a non-empty string if the supplied module is on the supported list. # currentURL - Returns the URL to the current version of the library. # installDir - Returns the directory, relative to the module dir, the lib file is loaded into. # libraryDir - Returns the directory, relative to the module dir, the library occupies. # This directory will be removed before uploading. # libraryFileRegex - Returns a directory regex that will match the library file in the install dir. # updateAfterRemove - Returns a non-empty string if the libraryDir needs a CVS update # after it is removed before a new version is installed. libraryInfo() { module="${1}" op="${2}" # Turn 'op' operator string into numerical value 'opcode' opsupported=1 opcurrentURL=2 opinstallDir=3 oplibraryDir=4 oplibraryFileRegex=5 opupdateAfterRemove=6 eval opcode=\$op${op} if [ -z "${opcode}" ]; then return fi if [ ${opcode} -lt 1 ]; then return fi # generate information into the 'info' variable # Note: not everyone has bash v4 installed so we'll used # indexed arrays rather than associative arrays. declare -a info info[$opsupported]="yup" case "${module}" in ckeditor ) if [ ${opcode} -eq ${opcurrentURL} ]; then # A page from which we can get the download link CKEDITOR_DL_PAGE="http://ckeditor.com/download" # Parse the download URL out of the fckeditor d/l page. info[$opcurrentURL]="`wget -U Mozilla -O - --quiet "${CKEDITOR_DL_PAGE}" | grep "http://download.cksource.com/CKEditor/CKEditor/CKEditor%20[0-9.]*/ckeditor_[0-9.]*.tar.gz" | head -1 | sed 's|^.*\(http:.*\.tar\.gz\).*$|\1|'`" fi info[$opinstallDir]="." info[$oplibraryDir]="ckeditor" info[$oplibraryFileRegex]="ckeditor_[0-9.]*.tar.gz" info[$opupdateAfterRemove]="yup" ;; fckeditor ) if [ ${opcode} -eq ${opcurrentURL} ]; then # A page from which we can get the download link CKEDITOR_DL_PAGE="http://ckeditor.com/download" # Parse the download URL out of the fckeditor d/l page. info[$opcurrentURL]="`wget -U Mozilla -O - --quiet "${CKEDITOR_DL_PAGE}" | grep "http://sourceforge.net/project/downloading.php?group_id=75348&filename=FCKeditor_[0-9.]*.tar.gz" | head -1 | sed 's|^.*\(http:.*\.tar\.gz\).*$|\1|'`" fi info[$opinstallDir]="." info[$oplibraryDir]="fckeditor" info[$oplibraryFileRegex]="FCKeditor_[0-9.]*.tar.gz" info[$opupdateAfterRemove]="yup" ;; jquery_ui ) # hard coded to the 1.6 version of the library file # as per the module README.txt file info[$opcurrentURL]="http://jquery-ui.googlecode.com/files/jquery.ui-1.6.zip" info[$opinstallDir]="." info[$oplibraryDir]="jquery.ui" info[$oplibraryFileRegex]="jquery.ui-1.6.zip" info[$opupdateAfterRemove]="" ;; * ) # not supported info[$opsupported]="" esac # return echo "${info[$opcode]}" } # Unarchives a library file and performs any other necessary postprocessing steps # to install a downloaded library file. # Called with a cwd of the directory in which the library file is located. # $1 - the name of the module requiring d/led library support # $2 - the name of the library file to unarchive postprocess() { module="${1}" libraryFile="${2}" if [ "${libraryFile:${#libraryFile}-7:7}" == ".tar.gz" -o "${libraryFile:${#libraryFile}-4:4}" == ".tgz" ]; then # Un-tar file tar xzf "${libraryFile}" elif [ "${libraryFile:${#libraryFile}-4:4}" == ".zip" ]; then # unzip file unzip -q "${libraryFile}" else echo -e "\n** Do not know how to expand file '${libraryFile}' for comparison. Aborting.\n" exit 1 fi # Perform any module-specific steps case "${module}" in fckeditor ) # The FCKEditor library installs as read-only which screws up # future executions of this script. chmod the files writable... cd "${module}" find . -type d -exec chmod 0755 {} \; find . -type f -exec chmod 0644 {} \; cd .. ;; jquery_ui ) # rename the install directory to its proper name mv jquery.ui-1.6 jquery.ui ;; esac } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi # Handle flags while (true); do case "${1}" in -quiet ) pQuiet="-quiet" shift ;; * ) break ;; esac done if [ -z "${pQuiet}" ]; then echo " " fi # handle INSTALL parameter pInstall="${3}" if [ -z "${pInstall}" ]; then echo -e "** Incorrect number of parameters specified. Aborting.\n" printUsage exit 1 fi # process Group Root Dir pRootDir="`getGroupRootDir "${4}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi # Validate the installation errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}\n" exit 1 fi # Validate selected module pModule="${2}" if [ -z "`libraryInfo ${pModule} supported`" ]; then echo -e "** Specified module unsupported: '${pModule}' Aborting.\n" printUsage exit 1 fi # Ensure module is installed. if [ -z "`getInstalledContribModuleList "${pInstall}" "${pRootDir}" | grep "^${pModule}$"`" ]; then echo -e "** Site doesn't have ${pModule} module installed. Aborting." exit 1 fi moduleDir="`getDirForContribModule "${pInstall}" "${pRootDir}" ${pModule}`" if [ ! -d "${moduleDir}" ]; then echo -e "** Unable to find module install directory (!!). Aborting.\n" exit 1 fi # All operations require the module dir be our cwd cd "${moduleDir}" || { echo -e "** Unable to 'cd' to module directory '${moduleDir}' (!!!). Aborting.\n" exit 1 } # Perform requested operation pOp="${1}" case "${pOp}" in install ) # Ensure wget is installed wgetBinary="`which wget 2>/dev/null`" if [ -z "${wgetBinary}" ]; then echo -e "** 'wget' not in path. Aborting.\n" exit 1 fi # Remove the library directory within the module dir libraryDir="`libraryInfo ${pModule} libraryDir`" if [ -d "${libraryDir}" ]; then /bin/rm -r "${libraryDir}" || { echo -e "** Unable to remove the library dir ('${libraryDir}') within the module directory (!). Aborting.\n" exit 1 } fi # Have to update the library dir? if [ -n "`libraryInfo ${pModule} updateAfterRemove`" ]; then cvs -q update -d "${libraryDir}" fi # Remove any exisitng library .tar.gz files cd "`libraryInfo ${pModule} installDir`" libraryFileRegex="`libraryInfo ${pModule} libraryFileRegex`" /bin/rm -f `/bin/ls -1 | grep ${libraryFileRegex} 2>/dev/null` # Get the URL of the latest version and download the tar file currentVersionURL="`libraryInfo ${pModule} currentURL`" currentVersionFile="`echo "${currentVersionURL}" | sed 's|^.*[/=&?]\(.*\)$|\1|'`" wget --quiet "${currentVersionURL}" if [ ! -f "${currentVersionFile}" ]; then echo -e "** Library download file ('${currentVersionFile}') not present after download (!). Aborting.\n" exit 1 fi # Untar the file and call any necessary post processing postprocess ${pModule} "${currentVersionFile}" ;; query | findmods ) # Find the .tar.gz file in the Drupal module dir cd "`libraryInfo ${pModule} installDir`" libraryFileRegex="`libraryInfo ${pModule} libraryFileRegex`" fileCount="`/bin/ls -1 | grep ${libraryFileRegex} 2>/dev/null | wc -l`" if [ $fileCount -eq 0 ]; then echo -e "** No library file found (matching regex '${libraryFileRegex}').\n" exit 1 elif [ $fileCount -ne 1 ]; then echo -e "** Expecting to find one library file (matching regex '${libraryFileRegex}'); but found ${fileCount}. Aborting.\n" exit 1 fi file="`ls -1 | grep ${libraryFileRegex}`" case "${pOp}" in query ) echo "Installed library file: ${file}" ;; findmods ) # Create a hold dir tmpDir="`mktemp -d`" || { echo -e "\n** Could not create temp directory for library expansion. Aborting.\n" exit 1 } # expand the library file w/in that temp dir oldwd="`pwd`" pushd "${tmpDir}" >/dev/null 2>&1 postprocess ${pModule} "${oldwd}/${file}" # compare every file foundDiffs="" find . -type f | ( while read file; do if [ -n "`diff "${file}" "${oldwd}/${file}"`" ]; then if [ -z "${foundDiffs}" ]; then echo -e "Differences in the following files found:" echo -e "\t( < original file || > deployed file )" foundDiffs="foo" fi echo "${file}" diff "${file}" "${oldwd}/${file}" | while read line; do echo -e "\t${line}" done fi done if [ -z "${foundDiffs}" ]; then echo -e "No diffs found." fi ) # Remove our temp dir popd >/dev/null 2>&1 rm -rf "${tmpDir}" ;; esac ;; * ) echo -e "** Invalid OP parameter specified: '${pOp}'. Aborting.\n" printUsage exit 1 esac # Done if [ -z "${pQuiet}" ]; then echo -e "\n** Done." fi