Create Site Script

This is one of the most comprehensive bash scripts I’ve ever written.
Over 760 lines of code, but it allows an Ubuntu System Admin to create a new Website, Mailman mailing list, FTP account and/or  WordPress Blog by typing an email address, and pressing ‘y’ or ‘n’ a couple of times as they are answering some basic questions.

It will let you create the Apache config file with multiple top level domains (e.g anat.org.au anat.com anat.com.au, etc..).
It also does a decent, although not insane, amount of error checking.

Download it here : http://w00t.anat.org.au/files/scripts/create_site/create_site.sh

Or with the download link below

Download

Assumptions

This is important. I’ve made a number of sweeping assumptions when creating this script. DO NOT USE THIS SCRIPT UNLESS YOU HAVE READ THE INFORMATION BELOW!

  • Linux Distro : I assume you are using Ubuntu. If you aren’t, you’ll have to adjust this script yourself. It might still work, but advanced things like automated FTP account creation, will likely fail. It will also fail if Apache is configured differently on different distro’s.
  • Not a shared host : I’ve assumed that you are running this on a VPS (Virtual Private Server) and not a shared host.. Which usually won’t give you root access and has the apache web folders in different locations.
  • Sudo/Root Access : Some of the commands being run, such as changing Apache configs and restarting programs require root or sudo access.
  • FTP is a custom compiled version of PureFTPd : The default apt-get install of Pure-FTPd doesn’t include the ability to create virtual users, which is what most small time VPS admins want to be able to give their users. FTP access but not SSH.
  • Expects : Unfortunately with PureFTP you can’t send it the password on the command line or get it to pull it from a file. As such I had to use Expects to allow it to try and replace someone’s human hands having to type the FTP password. If you don’t have expects installed it’ll try and apt-get install it, if that fails you’ll have to type the ftp password in yourself (the script will warn you as such).
  • WordPress : The install of WordPress is whatever the latest on the site is. It assumes you can download the install file, that you have added the MySQL details, and that you are installing a single isolated setup of WordPress and not using an existing WordPress Multi-Site config. If you want this domain to share another WordPress’s multi-site, then you’ll have to configure that yourself.
  • MySQL user/pass : As mentioned above
  • Mailman : You are using Mailman for mailing list software. If you are using something else or haven’t installed it before then you’ll want to say ‘n’ to this.
  • Exim4 : If you aren’t using Exim4 for your SMTP server then you won’t get all the benefits out of the Mailman config.

[Please note : This script is not 100% finished. It currently doesn’t edit the Mailman mailing list’s Exim4 config for you]

Command line format

sudo ./create_site $DOMAIN_WITHOUT_TLD

e.g
sudo ./create_site anat
# Note that the $DOMAIN is the main name without the top level domain (it will ask you if you want to change from the default .com TLD, and you can have a whole list of space separated top level domains as alias’s.

Example Usage

I suggest putting the script in a scripts directory.

mkdir ~/scripts
cd ~/scripts
wget http://w00t.anat.org.au/files/scripts/create_site/create_site.sh
chmod u+x create_site.sh

# Now to run it. e.g For a domain called testing, with the primary top level domain being .org.au, but also having some other domains you would run the following.
sudo ./create_site.sh testing
[sudo] password for anat:
[Note] Creating site www.testing.com
[Note] If run correctly this script will output a nice list of configuration details, including passwords, and also email it to the requested email address
[Note] You will now be asked a number of questions about configuration and optional installs

* What email address would you like to send the final information to (e.g [email protected]) ? [email protected]
* The default domain is testing.com would you like to change the top level domain from ‘.com’ ? [y/n] : y
– Changing TLD
[Note] The when entering the top level domains the first TLD is the primary, and used for Mailman, etc.. the others will be aliases

* Please enter the new TLDs e.g ‘.org.au .com .biz’ without quotes  : .org.au .com.au .com .jp

[Note] You’ve requested 4 TLDs which are :
[0] www.testing.org.au
[1] www.testing.com.au
[2] www.testing.com
[3] www.testing.jp

* Would you like to install a mailman mailing list to list.testing.org.au ? [y/n] : y
– Will attempt to add the mailing lists [email protected] and [email protected]

– Setting Mailing list Email to [email protected] and the PASSWORD to 32678

* Would you like to configure an FTP user account for this domain? [y/n] : y
– Will attempt to add the FTP account testing with a password of 32678

* Would you like to to host a WordPress blog on this domain? [y/n] :y
[Note] Will attempt to create a WordPress blog at www.testing.org.au
[Note] The MySQL DB password WordPress blog (which will be repeated later) will be : ‘6048.timsp]-[13728’

[Note] Will now confirm your settings
=====================================
4 sites being created :
* www.testing.org.au
* www.testing.com.au
* www.testing.com
* www.testing.jp

Create Mailing Lists : Yes
Create FTP : Yes
Create WordPress : Yes
Wordpress DB Password : 6048.timsp]-[13728

Primary Password : 32678
Email : [email protected]
* Are these settings correct? [y/n] : y
– Excelent. Done with the questioning, now to the making
———————————-
– Created directory /var/www/testing/
– Created directory /var/www/testing/www
– Created directory /var/www/testing/staging
– Created directory /var/www/testing/staging/www
– Created directory /var/www/testing/stats
– Created directory /var/log/apache2/testing
– Created directory /var/www/testing/list
– Created the web folders
– Done settings folder permissions
# FTP #
[Note] Now Processing the FTP creation
– Created directory /home/ftpusers/testing
– Created the FTP symbolic links, now creating the FTP account
/usr/bin/expect
/usr/bin/expect
[Note] Trying to add the FTP account in non-interactive mode using Expect
– Done configuring FTP
# WordPress #
[Note] Now Processing the WordPress blog creation
–2011-02-09 21:16:48–  http://wordpress.org/latest.tar.gz
Resolving wordpress.org… 72.233.56.139, 72.233.56.138
Connecting to wordpress.org|72.233.56.139|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified [application/x-gzip]
Saving to: `latest.tar.gz’

[         <=>                                                                                       ] 2,683,820   1.47M/s   in 1.7s

2011-02-09 21:16:50 (1.47 MB/s) – `latest.tar.gz’ saved [2683820]

# Mailman #
[Note] Now Processing the Mailman email lists creation
/usr/sbin/newlist
Enabling site testing.
Run ‘/etc/init.d/apache2 reload’ to activate new configuration!
* Reloading web server config apache2                                                                                               [ OK ]
———————————————-
– Done Processing

===============================================
===============================================
============= Configuration Info ==============
===============================================
===============================================

==== SITE ====
The 4 sites are :
[0] http://www.testing.org.au/
[1] http://www.testing.com.au/
[2] http://www.testing.com/
[3] http://www.testing.jp/
Log files : /var/log/apache2/testing
Apache Config file : /etc/apache2/sites-available/testing
Document Root : /var/www/testing/www/

==== MAILMAN ====
Mailing List 1
————–
Email Address: [email protected]
Subscribe Page : http://list.testing.org.au/mailman/listinfo/testing-announce/
Admin Login : http://list.testing.org.au/mailman/admin/testing-announce/
Admin Email : [email protected]
Admin Password : 32678

Mailing List 2
————–
Email Address: [email protected]
Subscribe Page : http://list.testing.org.au/mailman/listinfo/testing-discuss/
Admin Login : http://list.testing.org.au/mailman/admin/testing-discuss/
Admin Email : [email protected]
Admin Password : 32678

==== FTP ====
FTP User : testing
FTP Host : www.testing.org.au
FTP Password : 32678
[Note] Suggest using Active connection mode (versus PASV) if you can’t view the folder contents

==== WORDPRESS ====
Address : http://www.testing.org.au/
Admin login URL : http://www.testing.org.au/wp-admin/
Admin username : testing
Admin password : 32678
MySQL database User : testing
MySQL database Password : 6048.timsp]-[13728

#—– [MAILMAN : EXIM4 CONFIG] —–#
[Warn] Have not coded this part yet. Did not edit the exim4 config files
[Notice] If you would like to edit the Exim4 configuration use the following commands :
> nano /etc/exim4/update-exim4.conf.conf # Add list.testing.org.au to ‘dc_other_hostnames’
> nano /etc/exim4/conf.d/main/04_exim4-config_mailman # Add list.SITETLD to ‘domainlist mm_domains’
> update-exim4.conf
> nano /etc/init.d/exim4 restart
> exim -bt [email protected] # Confirm the routing is via mailman
### Don’t forget to setup Google Analytics http://www.google.com/analytics/ ###

If you find this script useful comment and say how it could be even better!

Want to add an automated Bind DNS creator bit? If you do create it then email [email protected] with the code and mention this page.

Cheers!

About michaelkubler

Michael Kubler was the Technical officer for ANAT during 2010. He is a Linux system admin, PHP programmer, and innovative geek who wants to change the world using disruptive innovation.
This entry was posted in Code, Downloads, OMFG. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *