|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This will install everything required to run a basic Postal installation. |
| 4 | +# This should be run on a clean Ubuntu 16.04 server. |
| 5 | +# |
| 6 | +# Once the installation has completed you will be able to access the Postal web |
| 7 | +# interface on port 443. It will have a self-signed certificate. |
| 8 | +# |
| 9 | +# * Change the MySQL & RabbitMQ passwords |
| 10 | +# * Create your first admin user with 'postal make-user' |
| 11 | +# * Replace the self-signed certificate in /etc/nginx/ssl/postal.cert |
| 12 | +# * Make appropriate changes to the configuration in /opt/postal/config/postal.yml |
| 13 | +# * Setup your DNS [ https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration ] |
| 14 | +# * Configure the click & open tracking [ https://github.com/atech/postal/wiki/Click-&-Open-Tracking ] |
| 15 | +# * Configure spam & virus checking [ https://github.com/atech/postal/wiki/Spam-&-Virus-Checking ] |
| 16 | + |
| 17 | +set -e |
| 18 | + |
| 19 | +# |
| 20 | +# Dependencies |
| 21 | +# |
| 22 | +apt update |
| 23 | +apt install -y software-properties-common |
| 24 | +apt-add-repository ppa:brightbox/ruby-ng -y |
| 25 | +apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 |
| 26 | + |
| 27 | + |
| 28 | +export DEBIAN_FRONTEND=noninteractive |
| 29 | +apt install -y ruby2.3 ruby2.3-dev build-essential libssl-dev mariadb-server libmysqlclient-dev rabbitmq-server nodejs git nginx wget nano |
| 30 | +gem install bundler procodile --no-rdoc --no-ri |
| 31 | + |
| 32 | +# |
| 33 | +# MySQL |
| 34 | +# |
| 35 | +echo 'CREATE DATABASE `postal` CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;' | mysql -u root |
| 36 | +echo 'GRANT ALL ON `postal`.* TO `postal`@`127.0.0.1` IDENTIFIED BY "p0stalpassw0rd";' | mysql -u root |
| 37 | +echo 'GRANT ALL PRIVILEGES ON `postal-%` . * to `postal`@`127.0.0.1` IDENTIFIED BY "p0stalpassw0rd";' | mysql -u root |
| 38 | + |
| 39 | +# |
| 40 | +# RabbitMQ |
| 41 | +# |
| 42 | +rabbitmqctl add_vhost /postal |
| 43 | +rabbitmqctl add_user postal p0stalpassw0rd |
| 44 | +rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*" |
| 45 | + |
| 46 | +# |
| 47 | +# System prep |
| 48 | +# |
| 49 | +useradd -r -m -d /opt/postal -s /bin/bash postal |
| 50 | +setcap 'cap_net_bind_service=+ep' /usr/bin/ruby2.3 |
| 51 | + |
| 52 | +# |
| 53 | +# Application Setup |
| 54 | +# |
| 55 | +sudo -i -u postal mkdir -p /opt/postal/app |
| 56 | +wget https://postal.atech.media/packages/stable/latest.tgz -O - | sudo -u postal tar zxpv -C /opt/postal/app |
| 57 | +ln -s /opt/postal/app/bin/postal /usr/bin/postal |
| 58 | +postal bundle /opt/postal/vendor/bundle |
| 59 | +postal initialize-config |
| 60 | +postal initialize |
| 61 | +postal start |
| 62 | + |
| 63 | +# |
| 64 | +# nginx |
| 65 | +# |
| 66 | +cp /opt/postal/app/resource/nginx.cfg /etc/nginx/sites-available/default |
| 67 | +mkdir /etc/nginx/ssl/ |
| 68 | +openssl req -x509 -newkey rsa:4096 -keyout /etc/nginx/ssl/postal.key -out /etc/nginx/ssl/postal.cert -days 365 -nodes -subj "/C=GB/ST=Example/L=Example/O=Example/CN=example.com" |
| 69 | +service nginx reload |
| 70 | + |
| 71 | +# |
| 72 | +# All done |
| 73 | +# |
| 74 | +echo |
| 75 | +echo "Installation complete" |
0 commit comments