Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 1.86 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. DRUPAL_PATH=${1%/}
  4. DRUPAL_USER=${2}
  5. APACHE_GROUP="_www"
  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\" (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 "${DRUPAL_PATH}" ] || [ ! -d "${DRUPAL_PATH}/sites" ] || [ ! -f "${DRUPAL_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 "${DRUPAL_USER}" ] || [ "`id -un ${DRUPAL_USER} 2> /dev/null`" != "${DRUPAL_USER}" ]; then
  15. echo "Please provide a valid user"
  16. echo -e $HELP
  17. exit
  18. fi
  19.  
  20.  
  21. cd $DRUPAL_PATH
  22. echo -e "Changing ownership of all contents of \"${DRUPAL_PATH}\" :\n user => \"${DRUPAL_USER}\" \t group => \"${APACHE_GROUP}\"\n"
  23. chown -R $DRUPAL_USER:$APACHE_GROUP .
  24.  
  25. echo "Changing permissions of all directories inside \"${DRUPAL_PATH}\" to \"rwxr-x---\"..."
  26. find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
  27.  
  28. echo -e "Changing permissions of all files inside \"${DRUPAL_PATH}\" to \"rw-r-----\"...\n"
  29. find . -type f -exec chmod u=rw,g=r,o= '{}' \;
  30.  
  31. echo "Changing permissions of \"files\" directories in \"${DRUPAL_PATH}/sites\" to \"rwxrwx---\"..."
  32. cd $DRUPAL_PATH/sites
  33. find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
  34. echo "Changing permissions of all files inside all \"files\" directories in \"${DRUPAL_PATH}/sites\" to \"rw-rw----\"..."
  35. echo "Changing permissions of all directories inside all \"files\" directories in \"${DRUPAL_PATH}/sites\" to \"rwxrwx---\"..."
  36. for d in ./*/files
  37. do
  38.    find $d -type d -exec chmod ug=rwx,o= '{}' \;
  39.    find $d -type f -exec chmod ug=rw,o= '{}' \;
  40. done