automation.
I’m trying to get Sourceworx’s hosting infrastructure back up and running, whilst using CodeIgniter for a front-end. The idea is that a user can sign up for free hosting with a possibility to upgrade to additional features such as e-mail for a small fee. The sign-up itself, though, is a matter of providing just a domain name and email address.
In the course of this I created a script which sets up the apache vhost and ftp user in one, nothing special but it works.
Requirements:
- Ubuntu (I’m using Natty but it may work on other versions with a bit of tweaking).
- Apache 2.x
- bash 2.x or later
- Sendmail
Here’s the code:
#!/bin/bash
USERNAME=$1;
EMAIL=$2;
read PASSWORD;
mkdir -p /home/$USERNAME/public_html;
useradd $USERNAME;
chown -R $USERNAME /home/$USERNAME;
cat /etc/hosttemplate | sed -e "s/DOMAIN/$USERNAME/g" > /etc/apache2/sites-available/$USERNAME;
ln -s /etc/apache2/sites-available/$USERNAME /etc/apache2/sites-enabled/$USERNAME;
echo "$USERNAME:$PASSWORD" | chpasswd -e;
#
EMF=/tmp/newmail;
echo "Welcome to Sourceworx.rnYour free hosting account is now active. You can upload via FTP by using the following details:" > $EMF;
echo "rnrnHost: $USERNAMErnUsername: $USERNAMErnPassword: $PASSWORDrnrn" >> $EMF;
echo "And of course you can access your page at $USERNAME.rnrnSSH access can be obtained using the same method, although remember any abuse will get your account disabled.rnrnHappy coding! And if you have any questions feel free to email chris@sourceworx.co.uk.rnrnChris" >>$EMF;
#
mail -s "Welcome to Sourceworx Hosting" $EMAIL < $EMF;
service apache2 restart;
I hope someone finds this useful. Save it as “createaccount” and make it executable. The script accepts a crypt()’ed password on standard input, the domain and a recipient email as arguments.
Recent Comments