diff --git a/README.md b/README.md index 738262d1..e8c327e1 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ Subscribe to Mailtrain Newsletter [here](http://mailtrain.org/subscription/EysIv ## Installation +### Automatic install (Ubuntu 14.04) + +You can download and run [install.sh](setup/install.sh) in your blank Ubuntu 14.04 VPS to set up +Mailtrain and all required dependencies (including MySQL). + +If you are using DigitalOcean then you can copy the contents of the [installation script](setup/install.sh) to the User Data textarea field when creating a new VPS (select Ubuntu 14.04 as the droplet Distribution image). After your droplet is created it should already have Mailtrain up and running. Navigate to http://droplet-hostname-or-ip/ and authenticate as `admin`:`test`. Do not forget to replace your account email and set up SMTP settings. + +### Manual (any OS that supports Node.js) + 1. Download Mailtrain files using git: `git clone git://github.com/andris9/mailtrain.git` and open Mailtrain folder `cd mailtrain` 2. Run `npm install` in the Mailtrain folder to install required dependencies 3. Copy [config/default.toml](config/default.toml) as `config/production.toml` and update MySQL and any other settings in it diff --git a/setup/install.sh b/setup/install.sh new file mode 100755 index 00000000..2486228f --- /dev/null +++ b/setup/install.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# This installation script works on Ubuntu 14.04 + +set -e + +export DEBIAN_FRONTEND=noninteractive + +apt-add-repository -y ppa:chris-lea/redis-server + +curl -sL https://deb.nodesource.com/setup_6.x | bash - +apt-get -q -y install mysql-server pwgen redis-server nodejs git ufw +apt-get clean + +HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname) +MYSQL_PASSWORD=`pwgen -1` + +# Setup MySQL user for Mailtrain +mysql -u root -e "CREATE USER 'mailtrain'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';" +mysql -u root -e "GRANT ALL PRIVILEGES ON mailtrain.* TO 'mailtrain'@'%' WITH GRANT OPTION;" +mysql -u mailtrain --password="$MYSQL_PASSWORD" -e "CREATE database mailtrain;" + +# Enable firewall, allow connections to SSH, HTTP, HTTPS and SMTP +ufw allow 22/tcp +ufw allow 80/tcp +ufw allow 443/tcp +ufw allow 25/tcp +ufw --force enable + +# Fetch Mailtrain files +cd /opt +git clone git://github.com/andris9/mailtrain.git +cd mailtrain + +# Set up upstart service script +cp setup/mailtrain.conf /etc/init + +# Add new user for the daemon to run as +useradd mailtrain || true + +# Setup installation configuration +cat >> config/production.toml < /etc/logrotate.d/mailtrain +/var/log/mailtrain.log { + daily + rotate 12 + compress + delaycompress + missingok + notifempty + copytruncate + nomail +} +EOM + +# Start the service +service mailtrain start + +echo "Success!";