Last active
January 15, 2017 04:36
-
-
Save ronisaha/4c197dc6d374960a3f99 to your computer and use it in GitHub Desktop.
Set folder permision to web-server user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| E_BAD_ARGS=85 | |
| E_BAD_PATH=-1 | |
| if [ ! -n "$1" ] | |
| then | |
| echo "Usage: $0 dir1 dir2 etc." | |
| exit ${E_BAD_ARGS} | |
| fi | |
| ALL_DIRECTORIES=${@%/} | |
| #Get the user name for webserver | |
| HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | grep -v apache- | head -1 | cut -d\ -f1` | |
| echo | |
| #Make sure all directories exists | |
| for arg in "$@" | |
| do | |
| DIRECTORY_PATH=${arg%/} | |
| if [[ "${DIRECTORY_PATH}" = /* ]] | |
| then | |
| echo "Only relative path are allowed" | |
| exit ${E_BAD_PATH} | |
| else | |
| #echo "Creating : ${DIRECTORY_PATH}" | |
| mkdir -p "${DIRECTORY_PATH}" | |
| fi | |
| done | |
| echo "Changing permission for : ${ALL_DIRECTORIES}" | |
| sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX ${ALL_DIRECTORIES} | |
| sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX ${ALL_DIRECTORIES} | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment