Created
February 23, 2014 06:54
-
-
Save kevr/9168071 to your computer and use it in GitHub Desktop.
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
[root@coders ~]# cat /usr/local/bin/mkuser | |
#!/usr/bin/env bash | |
if [ $# -lt 3 ]; then | |
echo "usage: $(basename $0) username \"Full Name\" user@email.tld" | |
exit 0 | |
fi | |
tmp="$(pw useradd $1 -w random -o -c "${2}" -s /usr/local/bin/bash -d /usr/home/$1 -m)" | |
www_groups=$(IFS=' ' read -a arr <<< "$(groups www)"; echo "${arr[@]:1}" | sed 's/ /,/g') | |
pw usermod www -G ${www_groups},${1} | |
echo "Creating userdir skeleton..." | |
mkdir /usr/home/$1/public_html | |
chown $1:$1 /usr/home/$1/public_html | |
chmod -R 750 /usr/home/$1 | |
echo "Restarting nginx to reflect new user..." | |
service nginx restart &> /dev/null | |
echo "Done!" | |
echo 'Sending user email...' | |
from="kevr@coders.ccsfcc.net" | |
recipients="${3}" | |
/usr/sbin/sendmail "$recipients" <<EOF | |
Subject:Account created for coders.ccsfcc.net | |
From:$from | |
Your username: ${1} | |
Your email: ${3} | |
Your temporary password: ${tmp} | |
SSH Hostname: coders.ccsfcc.net | |
SSH Port: 22 (Default) | |
HTTPS Address: https://coders.ccsfcc.net/~${1} | |
This account has been setup as a convenience tool to use as you | |
see fit. However, You may absolutely not run any malicious software, | |
heavy-load server applications, or host any abnormally large files. | |
ccsfcc.net Admin | |
Kevin Morris | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment