Skip to content

Instantly share code, notes, and snippets.

@amineasli
Last active February 24, 2016 17:50
Show Gist options
  • Save amineasli/65d16989ddda9e71aad8 to your computer and use it in GitHub Desktop.
Save amineasli/65d16989ddda9e71aad8 to your computer and use it in GitHub Desktop.
Temporarily set permissive privileges and ownership for your Magento installation directory.
#!/bin/bash
#Check root access
if [ "$UID" != 0 ]
then
echo "This shell script must be run as root."
exit 2
fi
#Variables declaration
GROUP_ACCESS=
ROOT_DIR='.' #Web root directory
if [ -n "$1" ] && [ -d "$1" ]
then
ROOT_DIR="$1"
fi
#Functions declaration
check_magento_dir()
{
if [ ! -f "$1/app/Mage.php" ]
then
error 'Magento installation directory not found!'
fi
}
error()
{
echo "$@" 1>&2
exit 1
}
set_user_perms()
{
find "$ROOT_DIR" -type d \! -perm 700 -exec chmod 700 {} \;
find "$ROOT_DIR" -type f \! -perm 600 -exec chmod 600 {} \;
}
set_user_and_group_perms()
{
find "$ROOT_DIR" -type d \! -perm 770 -exec chmod 770 {} \;
find "$ROOT_DIR" -type f \! -perm 660 -exec chmod 660 {} \;
}
#Main
check_magento_dir "$ROOT_DIR"
read -r -p "Allow group access ? [y/N] " answer
if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]
then
GROUP_ACCESS=true
fi
echo -n "Setting permissions for : $ROOT_DIR ..."
if [ -z $GROUP_ACCESS ]
then
set_user_perms
else
set_user_and_group_perms
fi
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment