Bash Scripting for Web Hosting Setups

This week I worked on creating a script that will be of great use for me.

When I have to setup a new customer or delete an old customer, there were many steps, and one of which I might forget or even setup wrong in the first place.  When a new customer signs up, the following things have to take place:

  • Setup the domain in my mail server to allow the servers to accept relaying for the new domain
  • Setup a web directory
  • Setup an e-mail account
  • Setup a mailbox directory 
  • If the user needs a database for their website, this needs to be created
  • If the user needs a database for their website, a SQL user needs to be created with privileges to their database
  • A primary zone needs to be added to the DNS servers for their domain
  • Configuration on both servers for a new VirtualHost

Much of the information that is needed is redundant as well – such as the domain name in question.  So, I finally finished up a 641-line bash shell script that will do all of these things!

While it would be nice to post the code here, I cannot do so because I have some proprietary code in it for my specific setup – such as the IP addresses for the servers.

Originally the goal was to use it as just a new user setup, but after tinking with the scripting a bit more, I was able to figure out how to find a specific line in a file using grep and cut, and then finding an ending line in a file using grep and cut as well, then using sed to delete between the two lines.

After this, I was thinking, "boy it would be nice if I could also use the same script to update both servers simultaneously".  Well sure enough, more research led me to how to send commands through an ssh tunnel to the other server!  So, this one script will do everything needed now in a matter of minutes.  It would take quite a while to set everything up for a new user, or to delete an old user.

I never was much of a person to get into programming – just because there wasn't too much I could think of to program.  Well after this, I now have thought of trying to make a PHP page that will allow customers to recover their e-mail password, or even a page that will allow them to create more e-mail accounts for their domain.  I allow up to five free e-mail addresses per domain, then there is an additional $1 fee for any additional.