#!/bin/bash # Sets up directory / file permissions that work for most server installations. # # General strategy: # Default: # All dirs get chmod'ed 0755 # All files get chmod`ed 0644 # Site 'files' exceptions: # Site 'files' dir (and all subdirs) get chmod'ed 0771 # All files in site 'files' dir (and below) get chmod'ed 0664 # Site 'backups' exceptions: # Site 'backups' dir (and all subdirs) get chmod'ed 0700 # All files in 'backups' dir (and below) get chmod'ed 0600 # # On some installations, it is necessary to set the 'files' directory group owner. # This can be done with the commands (run as root): # chgrp apache ; chmod g+ws # include library file . "`dirname ${0}`/drupalLibrary.sh" printUsage() { echo -e " " echo -e "Sets up Drupal install permissions. (See script header for specifics.)" echo -e " " echo -e "Usage:" echo -e "$0 -quiet ( | all ) [install group root dir]" echo -e "where:" echo -e " " echo -e "-quiet suppresses extra script output." echo -e " " outputInstallGroupUsage foo echo -e " " } ######### # 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 # 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}"`" 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 first="yup" for site in ${pInstall}; do if [ -z "${pQuiet}" ]; then if [ -n "${first}" ]; then echo " " fi echo -e "Processing site '${site}'" fi targetDir="`getTargetDir "${site}" "${pRootDir}"`" filesDir="`getFileUploadDir "${site}" "${pRootDir}"`" backupDir="`getBackupDir "${site}" "${pRootDir}"`" # For each directory, run 'radchmod' process. Returns error if dir doesn't exist. radchmod 0755 0644 "${targetDir}" || { echo -e "\t** Site target dir '${targetDir}' does not exist. Skipping ${site}."; continue; } # TODO Hide chmod errors from this command (and add flag '-showwarnings' to to show them) radchmod 0775 0664 "${filesDir}" || { echo -e "\t** Site files dir '${filesDir}' does not exist. Proceeding." } radchmod 0700 0600 "${backupDir}" || { echo -e "\t** Site backup dir '${backupDir}' does not exist. Proceeding." } if [ -z "${pQuiet}" ]; then echo -e "Done with site '${site}'" echo -e "\tRemember, it might be required to set 'files' dir group ownership." echo -e "\t\tRun as root:" echo -e "\t\tchgrp apache \"${filesDir}\" ; chmod g+ws \"${filesDir}\" ; pushd \"${filesDir}\" ; find . -exec chmod g+w {} \\; -exec chgrp apache {} \\; ; find . -type d -exec chmod g+s {} \\; ; popd" echo -e " " fi first="" done # Done if [ -z "${pQuiet}" ]; then echo -e "\n** Done." fi