Fix for fix-permissions.sh - Drupal Quickstart

  1. #!/bin/bash
  2.  
  3. path=${1%/}
  4. user=${2}
  5. group="www-data"
  6. help="\nHelp: This script is used to fix permissions of a drupal installation\nyou need to provide the following arguments:\n\t 1) Path to your drupal installation\n\t 2) Username of the user that you want to give files/directories ownership\nNote: \"www-data\" (apache default) is assumed as the group the server is belonging to, if this is different you need to modify it manually by editing this script\n\nUsage: (sudo) bash ${0##*/} drupal_path user_name\n"
  7.  
  8. if [ -z "${path}" ] || [ ! -d "${path}/sites" ] || [ ! -f "${path}/modules/system/system.module" ]; then
  9.         echo "Please provide a valid drupal path"
  10.         echo -e $help
  11.         exit
  12. fi
  13.  
  14. if [ -z "${user}" ] || [ "`id -un ${user} 2> /dev/null`" != "${user}" ]; then
  15.         echo "Please provide a valid user"
  16.         echo -e $help
  17.         exit
  18. fi
  19.  
  20. cd $path;
  21.  
  22. echo -e "Changing ownership of all contents of \"${path}\" :\n user => \"${user}\" \t group => \"${group}\"\n"
  23. chown -R ${user}:${group} .
  24. echo "Changing permissions of all directories inside \"${path}\" to \"750\"..."
  25. find . -type d -exec chmod u=rwx,g=rx,o= {} \;
  26. echo -e "Changing permissions of all files inside \"${path}\" to \"640\"...\n"
  27. find . -type f -exec chmod u=rw,g=r,o= {} \;
  28.  
  29. cd $path/sites;
  30.  
  31. echo "Changing permissions of \"files\" directories in \"${path}/sites\" to \"770\"..."
  32. find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
  33. echo "Changing permissions of all files inside all \"files\" directories in \"${path}/sites\" to \"660\"..."
  34. find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chmod ug=rw,o= "$FILE"; done
  35. echo "Changing permissions of all directories inside all \"files\" directories in \"${path}/sites\" to \"770\"..."
  36. find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmod ug=rwx,o= "$DIR"; done

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.