Skip to content

Instantly share code, notes, and snippets.

@karschsp
Created February 22, 2015 03:02
Show Gist options
  • Save karschsp/0832819dd3c37a3de648 to your computer and use it in GitHub Desktop.
Save karschsp/0832819dd3c37a3de648 to your computer and use it in GitHub Desktop.
fix perms
#! /bin/bash
#
# From anywhere within a Drupal site,
# this will set the correct permissions
# to keep Drupal happy.
#
CURRENT_USER=`who am i | awk '{print $1}'`
USER=${1:-$CURRENT_USER}
dir=`drush status --fields=root |cut -f2 -d: |sed s/\ //g`
if [ -d "$dir" ]; then
echo "Drupal root is $dir"
echo "Fixing permisisons and setting owner to ${USER}. Standby..."
cd $dir
chown -R ${USER}.www-data .
find -type f -exec chmod 644 {} \;
find -type d -exec chmod 755 {} \;
if [ -d "$dir/sites/default/files" ]; then
cd sites/default/files/
find -type f -exec chmod 664 {} \;
find -type d -exec chmod 775 {} \;
cd ..
chmod 640 settings*php
fi
echo "All Done. Happy Coding"
else
echo "Sorry, can't find your Drupal root."
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment