#!/bin/bash # Enables or disables update functionality for non-logged-in access. # This allows updating the installation w/o being logged in as the site admin. # If this is a Drupal-5 (or earlier) site, this is done by updating # the $access_check variable in a site installation's update.php file. # If this is a Drupal-6 (or later) site, this is done by updating # the $update_free_access variable in the site's settings.php file. # This functionality should remain disabled (must be logged in as admin to update) # during normal operation. # This cooresponds to running this script wth a 'true' parameter. # Note that the script will set the permissions to the file back to their original settings. # include library file . "`dirname ${0}`/drupalLibrary.sh" printUsage() { echo -e " " echo -e "Enables/disables the access check that allows updating a site w/o being logged in as the admin." echo -e "For more info, see script header." echo -e " " echo -e "Usage:" echo -e "$0 ( true | false ) ( | all ) [install group root dir]" echo -e "where:" echo -e " " echo -e "true | false" echo -e "\tSpecifies the state of the access check." echo -e "\t'true' enables the access check, 'false' disables it." echo -e "\t* Should be 'true' for production use." echo -e " " outputInstallGroupUsage foo echo -e " " } ######### # Param handling if [ $# -eq 0 ]; then printUsage exit 0 fi echo " " # Handle true/false case "${1}" in true ) pAccessCheck="TRUE" ;; false ) pAccessCheck="FALSE" ;; * ) echo -e "** Invalid true/false parameter. Aborting.\n" printUsage exit 1 esac shift # process Group Root Dir pRootDir="`getGroupRootDir "${2}"`" errorStr="`validateGroupRootDir "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "${errorStr}\n" printUsage exit 1 fi pInstall="$1" if [ "`toLower "${pInstall}"`" == "all" ]; then pInstall="`getSitesInGroupDir "${pRootDir}"`" # Ensure not specifying all installs if specifying output dir if [ -n "${pOutputDir}" ]; then echo -e "** Cannot specify output dir for all installs. Aborting." printUsage exit 1 fi else # Validate the installation errorStr="`validateSite "${pInstall}" "${pRootDir}"`" if [ -n "${errorStr}" ]; then echo -e "** Error with specified install: ${errorStr}. Aborting.\n" exit 1 fi fi # process for site in ${pInstall}; do echo -en "Processing site '${site}'.... " # If this is a Drupal-5 site (or older), the $access_check variable in the # .../update.php file controls the access check functionality. cd "`getTargetDir "${site}" "${pRootDir}"`" if [ -n "`cat update.php | grep '^\$access'`" ]; then # Get orignal file perms perms="`getChmodParamFromFile update.php`" ( tempFile="`mktemp`" && cat update.php | awk '/^\$access_check = [A-Z]*;$/ { print "$access_check = '${pAccessCheck}';"; next }; {print $0}' > "${tempFile}" && /bin/mv -f "${tempFile}" update.php && chmod ${perms} update.php ) || { echo -e "\n\t** Unable to update update.php file. Skipping site '${site}'" continue } else # Must be a Drupal-6 (or later) site. # Access check is controlled by the $update_free_access variable in the # settings.php in the sites directory. # Also... the value of this variable is exactly opposite of the value of the $access_check variable for Drupal-5 sites. # I.e. if $pAccessCheck is "TRUE", we have to set "FALSE" into the settings.php file and vice-versa. if [[ "${pAccessCheck}" == "TRUE" ]]; then holdCheck="FALSE" else holdCheck="TRUE" fi cd "`getSiteDir "${site}" "${pRootDir}"`" # Get orignal file perms perms="`getChmodParamFromFile settings.php`" ( tempFile="`mktemp`" && cat settings.php | awk '/^\$update_free_access = [A-Z]*;$/ { print "$update_free_access = '${holdCheck}';"; next }; {print $0}' > "${tempFile}" && /bin/mv -f "${tempFile}" settings.php && chmod ${perms} settings.php ) || { echo -e "\n\t** Unable to update settings.php file. Skipping site '${site}'" continue } fi echo -e "Done." done # Done echo -e "\n** Done."