script to add domain / ftp user account

Here is a script that does the following :

1. check if domain is present
2. if domain is present then it creates a system user
3. It creates the home directory structure
4 . within the home directory structure it creates  the various dir.
5. sets permission to those dir
6.  write the vhost directive in to the http.conf configuration file
7 . Restart apace ( gracefully )

#!/bin/bash
#steps to set up a website
echo -e " Enter you domain name "
read $1

domain_com=` echo $domain |sed s/\.com//g `
domain_in=`echo $domain |sed s/\.in//g`
domain_net=`echo $domain |sed s/\.net//g`
domain_co_in=`echo $domain |sed s/\.co.in//g`
domain_02=`cat /etc/passwd |grep $domain |sed s/:/\ /g |awk '{print $1}'`

if [ "$domain_com" =  "$domain_02" ]; then
echo -e " the domain exist "
exit 1
fi

echo -e "Please enter  user for for $domain  "
read user
if [ "$user" = "$domain_02" ]; then
echo -e " user exist quiting proces "
else
useradd -d /websites/"$domain" -s /sbin/nologin "$user"
echo -e " created domain $domain "


echo -e "adding ftp user "
echo  "$domain"
(echo $domain_com; echo $domain_com ) | /usr/local/pureftpd/bin/pure-pw useradd "$user" -f /usr/local/pureftpd/etc/pureftpd.passwd  -u "$user" -d /websites/"$domain" -m
echo -e " adding user sucessful "

echo -e "creating directory structure "
mkdir /websites/"$domain"/web /websites/"$domain"/logs /websites/"$domain"/private /websites/"$domain"/data /websites/"$domain"/cgi-bin
echo -e "sucessfully created directory structure   "


echo -e " we chang the permission for the the $user "
chmod 711 /websites/"$domain"/ && chmod 711 /websites/"$domain"/*

echo -e " we change the ownership   for  the $domain "
chown "$user":"$user" /websites/"$domain" && chown "$user":"$user" /websites/"$domain"/*
echo -e " changes for $user was sucessful "


echo -e "Creating the Vhost directive domain $domain "

echo -e "
######################"$domain"2631###################

<VirtualHost 192.168.0.244:80>
ServerAdmin admin@ashish.sys.qualiproj.com
ServerName "$user".sys.qualiproj.qualispace.com
ServerAlias www."$user".sys.qualiproj.qualispace.com
DocumentRoot /websites/"$domain"/web
##############MIME_TYPE_"$domain"2631##################
<Directory /websites/"$domain"/web>
    Options -MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    AllowOverride FileInfo AuthConfig Limit
    Order allow,deny
    Allow from all
</Directory>
ErrorLog /websites/"$domain"/logs/"$user".sys.qualiproj.error_log
CustomLog /websites/"$domain"/logs/$user.sys.qualiproj.access_log common
ScriptAlias /cgi-bin/ "/websites/"$domain"/cgi-bin/"
<Directory "/websites/"$domain"/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
       Order allow,deny
        Allow from all
</Directory>
</VirtualHost>
 " >>  /usr/local/apache2/conf/extra/httpd_vhost.conf

echo -e "Sucessfully created  the Vhost directive domain $domain "

echo -e " restarting httpd "
/etc/init.d/httpd graceful

echo -e "copying test html page to web folder "
cp -R /websites/agnello.com/web/bob.html /websites/"$domain"/web/index.html
echo -e "done "

echo -e " you can now log on to http://www."$user".sys.qualiproj.qualispace.com"

fi

 

--

No comments:

Other Articles

Enter your email address: