Skip to content

Instantly share code, notes, and snippets.

@mikesorae
Created June 30, 2014 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesorae/81e5e84fe059c097c402 to your computer and use it in GitHub Desktop.
Save mikesorae/81e5e84fe059c097c402 to your computer and use it in GitHub Desktop.
prepare new user and config file for apache
#!/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