egscripts/eghostingaccount/eghostingaccount

80 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
#
# create a new account for a hosting customer, spit out the relevant details for an email
# copyright Egressive Ltd, dave@egressive.com, http://egressive.com
#
# rob@egressive.com added directory structure and
#
# $1 short site name (eg egressive, hscr)
# $2 admin userid (owner for directory structure)
#
# create directory structure and ACLs
#
HOMEBASE="/home"
SITENAME=$1
SITEHOME=$HOMEBASE/$SITENAME
ADMINUSER=$2
WEBSERVGROUP="www-data"
WEBDIR=web
if [ $1"xxx" == "xxx" ] || [ $2"xxx" == "xxx" ]
then
echo usage: `basename $0` sitename admin-userid
exit 1
fi
if getent passwd $ADMINUSER >> /dev/null
then
echo "ERROR: Admin user already exists"
exit 1
else
echo . . . Creating admin user, please enter password when prompted
adduser $ADMINUSER
fi
# just in case the site name is different to the admin username
if [ -d $SITEHOME ]
then
if [ -d $SITEHOME/$WEBDIR ]
then
echo "ERROR: Directory structure already exists"
exit 1
fi
else
mkdir $SITEHOME
fi
# set up the site directory
echo . . . Create the site directory and set permissions
chown $ADMINUSER:$ADMINUSER $SITEHOME
chmod u=rwx,g=rwxs,o-rwx $SITEHOME
setfacl --default -m g:$WEBSERVGROUP:rx $SITEHOME
setfacl -m g:$WEBSERVGROUP:x $SITEHOME
setfacl --default -m g:$WEBSERVGROUP:rx $SITEHOME
# set up log and web directories
echo . . . Create the site subdirectories
for i in $WEBDIR log
do
mkdir $SITEHOME/$i
# chmod u=rwx,g=rwxs,o-rwx $SITEHOME/$i
done
# set up web sub directories
echo . . . Create the web subdirectories and set permissions
for i in drupal $SITENAME-files $SITENAME-debug
do
mkdir $SITEHOME/$WEBDIR/$i
setfacl --default -m g:$WEBSERVGROUP:rwx $SITEHOME/$WEBDIR/$i
setfacl -m g:$WEBSERVGROUP:rwx $SITEHOME/$WEBDIR/$i
done
echo Done setting up admin user and directory structure
#
# create databases