Last active
June 15, 2017 13:04
-
-
Save svedova/e66f48304c15cd778253296ba1117af9 to your computer and use it in GitHub Desktop.
Running this bash script will create a var/www folder to host different projects in a Ubuntu environment. It will also set the permissions properly for the current user and www group.
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 | |
# run this file with sudo permissions, example: | |
# bash www-perms.bash <group-name> <username> | |
echo "Creating group if it is not there..." | |
getent group $1 || groupadd $1 | |
echo "Adding user $2 to group..." | |
usermod -a -G $1 $2 | |
echo "Creating the folder if it is not there..." | |
mkdir -p /var/www | |
echo "Altering permissions for var/www..." | |
chown -R root:$1 /var/www | |
# 2 = set group id | |
# 7 = rwx for owner | |
# 7 = rwx for group | |
chmod 2775 /var/www | |
find /var/www -type d -exec chmod 2775 {} + | |
find /var/www -type f -exec chmod 0664 {} + | |
echo "umask 0002" >> /etc/profile | |
echo "Setup completed successfully. Logout/in for changes to your groups to take effect." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment