-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostalation.sh
132 lines (116 loc) · 5.3 KB
/
postalation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
domain=$1;
# This will install everything required to run a basic Postal installation.
# This should be run on a clean Ubuntu 16.04 server.
#
# Once the installation has completed you will be able to access the Postal web
# interface on port 443. It will have a self-signed certificate.
#
# * Change the MySQL & RabbitMQ passwords
# * Create your first admin user with 'postal make-user'
# * Replace the self-signed certificate in /etc/nginx/ssl/postal.cert
# * Make appropriate changes to the configuration in /opt/postal/config/postal.yml
# * Setup your DNS [ https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration ]
# * Configure the click & open tracking [ https://github.com/atech/postal/wiki/Click-&-Open-Tracking ]
# * Configure spam & virus checking [ https://github.com/atech/postal/wiki/Spam-&-Virus-Checking ]
set -e
#
# Dependencies
#
apt update;
apt-get install apt-transport-https;
apt install -y software-properties-common;
apt-add-repository ppa:brightbox/ruby-ng -y;
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8;
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.coreix.net/mariadb/repo/10.1/ubuntu xenial main';
curl -sL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add -;
add-apt-repository 'deb http://www.rabbitmq.com/debian/ testing main';
apt update;
export DEBIAN_FRONTEND=noninteractive;
apt install -y libnetcdf-dev libssl-dev libcrypto++-dev libgmp-dev ruby-mysql2 ruby2.3 ruby2.3-dev build-essential mariadb-server libmysqlclient-dev rabbitmq-server nodejs git nginx wget nano;
gem install bundler procodile --no-rdoc --no-ri;
#
# MySQL
#
echo 'CREATE DATABASE `postal` CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;' | mysql -u root;
echo 'GRANT ALL ON `postal`.* TO `postal`@`127.0.0.1` IDENTIFIED BY "p0stalpassw0rd";' | mysql -u root;
echo 'GRANT ALL PRIVILEGES ON `postal-%` . * to `postal`@`127.0.0.1` IDENTIFIED BY "p0stalpassw0rd";' | mysql -u root;
#
# RabbitMQ
#
rabbitmqctl add_vhost /postal;
rabbitmqctl add_user postal p0stalpassw0rd;
rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*";
#
# System prep
#
useradd -r -m -d /opt/postal -s /bin/bash postal;
setcap 'cap_net_bind_service=+ep' /usr/bin/ruby2.3;
#
# Application Setup
#
sudo -i -u postal mkdir -p /opt/postal/app;
wget https://postal.atech.media/packages/stable/latest.tgz -O - | sudo -u postal tar zxpv -C /opt/postal/app;
ln -s /opt/postal/app/bin/postal /usr/bin/postal;
postal bundle /opt/postal/vendor/bundle;
postal initialize-config;
sed -i -e "s/example.com/$1/g" /opt/postal/config/postal.yml;
postal initialize;
postal start;
#
# nginx
#
#cp /opt/postal/app/resource/nginx.cfg /etc/nginx/sites-available/default;
#mkdir /etc/nginx/ssl/;
#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=1Example/L=2Example/O=3Example/CN=postal.$1";
#service nginx reload;
cd /etc/systemd/system;
curl -O https://raw.githubusercontent.com/layen67/docker-postal-ubuntu/master/postal.service;
systemctl daemon-reload;
systemctl enable postal;
systemctl start postal;
apt-get -y install software-properties-common;
add-apt-repository -y ppa:certbot/certbot;
apt-get -y update;
apt-get -y install spamassassin;
systemctl restart spamassassin;
systemctl enable spamassassin;
#apt-get -y install certbot;
#apt-get -y install python-certbot-nginx;
#certbot certonly \
# --nginx \
# --non-interactive \
# --agree-tos \
# --email [email protected] \
# --domains postal.$1
#sed -i -r "s/.*postal.cert.*/ ssl_certificate \/etc\/letsencrypt\/live\/postal.$1\/fullchain.pem;/g" /etc/nginx/sites-available/default;
#sed -i -r "s/.*postal.key.*/ ssl_certificate_key \/etc\/letsencrypt\/live\/postal.$1\/privkey.pem;/g" /etc/nginx/sites-available/default;
#sed -i -e "s/yourdomain.com/$1/g" /etc/nginx/sites-available/default;
service nginx restart;
sleep 10
postal start
postal make-user;
chown -R postal:postal /etc/letsencrypt
echo '' | sudo tee -a /opt/postal/config/postal.yml;
echo 'spamd:' | sudo tee -a /opt/postal/config/postal.yml;
echo ' enabled: true' | sudo tee -a /opt/postal/config/postal.yml;
echo ' host: 127.0.0.1' | sudo tee -a /opt/postal/config/postal.yml;
echo ' port: 783' | sudo tee -a /opt/postal/config/postal.yml;
# sed -i -e "s/use_ip_pools: false/use_ip_pools: true/g" /opt/postal/config/postal.yml;
echo '' | sudo tee -a /opt/postal/config/postal.yml;
echo 'smtp_server:' | sudo tee -a /opt/postal/config/postal.yml;
echo ' port: 2525' | sudo tee -a /opt/postal/config/postal.yml;
echo ' tls_enabled: true' | sudo tee -a /opt/postal/config/postal.yml;
echo ' tls_certificate_path: /etc/letsencrypt/live/postal.yourdomain.com/fullchain.pem' | sudo tee -a /opt/postal/config/postal.yml;
echo ' tls_private_key_path: /etc/letsencrypt/live/postal.yourdomain.com/privkey.pem' | sudo tee -a /opt/postal/config/postal.yml;
echo ' proxy_protocol: false' | sudo tee -a /opt/postal/config/postal.yml;
echo ' log_connect: true' | sudo tee -a /opt/postal/config/postal.yml;
echo ' strip_received_headers: true' | sudo tee -a /opt/postal/config/postal.yml;
sed -i -e "s/yourdomain.com/$1/g" /opt/postal/config/postal.yml;
echo 'postal.$1' > /etc/hostname;
#
# All done
#
echo
echo "Installation complete your server reboot now https://postal.$1"
reboot;