Skip to content

Instantly share code, notes, and snippets.

@jesusgoku
Created June 7, 2014 22:42
Show Gist options
  • Save jesusgoku/751b90945bf860e13c1a to your computer and use it in GitHub Desktop.
Save jesusgoku/751b90945bf860e13c1a to your computer and use it in GitHub Desktop.
Setting up Permissions
#!/usr/bin/env bash
SYMFONY_FOLDER=$1
METHOD=$2
HTTPDUSER=$3
if [[ ! -d $SYMFONY_FOLDER || ! -e ${SYMFONY_FOLDER}/app/AppKernel.php ]]
then
echo "No es una capeta Symfony"
exit 1
fi
echo "Symfony folder: ${SYMFONY_FOLDER}"
echo "Remove log and cache files"
rm -rf ${SYMFONY_FOLDER}/app/cache/* ${SYMFONY_FOLDER}/app/logs/*
echo "Find httpd user"
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
if [[ -z $HTTPDUSER || $HTTPDUSER == "" ]]
then
echo "Not found httpd user"
echo "Execute ${0} ${SYMFONY_FOLDER} chmodplusa|setfacl HTTPDUSER"
exit 1
else
echo "HTTPD User: ${HTTPDUSER}"
fi
echo "Set permission"
if [[ -z $METHOD || $METHOD == "chmodplusa" ]]
then
sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" ${SYMFONY_FOLDER}/app/cache ${SYMFONY_FOLDER}/app/logs
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" ${SYMFONY_FOLDER}/app/cache ${SYMFONY_FOLDER}/app/logs
fi
if [[ -n $METHOD && $METHOD == "setfacl" ]]
then
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX ${SYMFONY_FOLDER}/app/cache ${SYMFONY_FOLDER}/app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX ${SYMFONY_FOLDER}/app/cache ${SYMFONY_FOLDER}/app/logs
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment