Created
June 30, 2014 10:18
-
-
Save mikesorae/81e5e84fe059c097c402 to your computer and use it in GitHub Desktop.
prepare new user and config file for apache
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
#!/bash/bin | |
if [ $# != 2 ]; then | |
echo "usage: $0 app_name app_port" 1>&2 | |
exit 0 | |
fi | |
app_name=$1 | |
port=$2 | |
echo "checking the port" | |
port_used=`lsof -iTCP:${port} | wc -c` | |
if [ $port_used -ne 0 ]; then | |
echo "the port is already used" | |
exit 1 | |
fi | |
echo "checking the user" | |
user_exists=false | |
getent passwd $app_name >/dev/null 2>&1 && user_exists=true | |
if $user_exists; then | |
echo "this user already exists" | |
exit 1 | |
fi | |
echo "preparing user for the site" | |
useradd $app_name | |
gpasswd -a apache $app_name | |
mkdir /home/$app_name/public_html | |
chown -R $app_name:$app_name /home/$app_name | |
chmod -R 775 /home/$app_name | |
echo "preparing setting for apache" | |
apache_conf="/etc/httpd/conf.d" | |
cp $apache_conf/template.conf.org $apache_conf/$app_name.conf | |
sed -i -E "s/\\\$PORT/${port}/g" $apache_conf/$app_name.conf | |
sed -i -E "s/\\\$APP_NAME/${app_name}/g" $apache_conf/$app_name.conf | |
service httpd restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment