Last active
December 20, 2015 12:59
-
-
Save BenMorel/6135471 to your computer and use it in GitHub Desktop.
Creates a user account with correct permissions to host a website with Apache.
This file contains 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/sh | |
if [ -z $1 ]; then | |
echo "Usage: $(basename $0) [name]" | |
exit 1 | |
fi | |
message() { | |
printf '%-60s' "$*" | |
} | |
success() { | |
printf "[\033[32mSUCCESS\033[0m]\n" | |
} | |
failure() { | |
printf "[\033[31mFAILURE\033[0m]\n" | |
} | |
try() { | |
result=$($* 2>&1) | |
if [ $? -ne 0 ]; then | |
failure | |
echo $result | |
exit 1 | |
fi | |
success | |
} | |
message "Creating user $1" | |
try useradd "$1" | |
message "Chmoding home dir" | |
try find "/home/$1" -type d -exec chmod 2770 {} \; | |
message "Making apache user belong to this user's group" | |
try usermod -aG "$1" apache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment