-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·298 lines (266 loc) · 8.14 KB
/
install.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
INSTALL_PATH="/opt/haraka"
CONFIG_PATH="$INSTALL_PATH/config"
IN_PATH="$INSTALL_PATH/haraka-in"
OUT_PATH="$INSTALL_PATH/haraka-out"
NUX_PATH="$INSTALL_PATH/nuxMail"
PLUGIN_PATH="$NUX_PATH/plugins"
main() {
echo "Welcome! -- Install nuxMail --"
# Install haraka
if [[ ! $(npm list -g Haraka | grep Haraka) ]]; then
echo "Please install Haraka globally via: sudo npm install -g Haraka"
echo "You will need the sha512crypt-node package too: sudo npm install -g sha512crypt-node"
exit 1
fi
# Install haraka default configs
echo "Cleaning and creating top-level install dir.."
rm -rf "$INSTALL_PATH" || exit 1
mkdir -p "$CONFIG_PATH" || exit 1
echo "Creating default inbound config in $IN_PATH.."
haraka -i "$IN_PATH" || exit 1
echo "Creating default outbound config in $OUT_PATH.."
haraka -i "$OUT_PATH" || exit 1
git clone https://github.com/Joeasaurus/nuxMail.git "$NUX_PATH" || exit 1
# Main logic
ask_hostDomain
echo "$FQDN" > "$CONFIG_PATH/me"
createLinks "$CONFIG_PATH/me" "config/me" true || exit 1
ask_certCreate
create_SmtpGreeting
create_SmtpIni
create_InboundPlugins
create_OutboundPlugins
create_AliasesConfig
create_MailboxesConfig
link_nuxMailPlugins
edgeConfigs
set_Permissions
install_Hcont
}
createLinks() {
local delete="$3"
local inout="$4"
if [[ ! "$delete" =~ ^(true|false)$ ]]; then
inout="$delete"
delete="false"
fi
if [[ ! "$inout" =~ ^(in|out)$ ]]; then
inout="both"
fi
if [[ "$delete" == "true" ]]; then
rm -rf "$IN_PATH/$2" "$OUT_PATH/$2"
fi
case "$inout" in
in)
ln -s "$1" "$IN_PATH/$2";;
out)
ln -s "$1" "$OUT_PATH/$2";;
both)
ln -s "$1" "$IN_PATH/$2"
ln -s "$1" "$OUT_PATH/$2"
;;
esac
}
ask_hostDomain() {
read -p "What is your domain? " DOMAIN
read -p "What is my FQDN? [$(hostname).$DOMAIN] " FQDN
if [[ "$FQDN" == "" ]]; then
FQDN="$(hostname).$DOMAIN"
fi
echo "Proceeding with $FQDN.."
}
ask_certCreate() {
local tls_cert_name="$DOMAIN.tls_cert.pem"
local tls_key_name="$DOMAIN.tls_key.pem"
echo "Creating symlinks.."
createLinks "$CONFIG_PATH/$tls_cert_name" "config/$tls_cert_name" || exit 1
createLinks "$CONFIG_PATH/$tls_key_name" "config/$tls_key_name" || exit 1
read -p "Do you have your own SSL certificates? [y/n] " CERT_CREATE
if [[ "$CERT_CREATE" != [YyNn] ]]; then
echo "Please answer yes or no."
ask_certCreate
elif [[ "$CERT_CREATE" == [Yy] ]]; then
echo "Fair play man, just put the cert at $CONFIG_PATH/$tls_cert_name and the key at $CONFIG_PATH/$tls_key_name"
elif [[ "$CERT_CREATE" == [Nn] ]]; then
echo "Please answer the below to generate a key and cert."
echo "!!!!!The important bit is the CN should be this server's FQDN ($FQDN)!!!!!!"
openssl req -x509 -nodes -days 2190 -newkey rsa:2048 \
-keyout "$CONFIG_PATH/$tls_key_name" -out "$CONFIG_PATH/$tls_cert_name" || exit 1
fi
}
create_SmtpGreeting() {
echo "Setting SMTP greeting message.."
cat > "$CONFIG_PATH/smtpgreeting" <<EOF
Welcome to $DOMAIN!
EOF
createLinks "$CONFIG_PATH/smtpgreeting" "config/smtpgreeting" true
}
create_SmtpIni() {
echo "Creating smtp.ini configs.."
for direction in inbound outbound; do
[[ "$direction" == "inbound" ]] && \
local port=25 && \
local filePath="$CONFIG_PATH/$direction.smtp.ini" && \
local targetFile="$IN_PATH/config/smtp.ini"
[[ "$direction" == "outbound" ]] && \
local port=587 && \
local filePath="$CONFIG_PATH/$direction.smtp.ini" && \
local targetFile="$OUT_PATH/config/smtp.ini"
cat > "$filePath" <<EOF
; address to listen on (default: all IPv6 and IPv4 addresses, port 25)
; use "[::0]:25" to listen on IPv6 and IPv4 (not all OSes)
listen=[::0]:$port
; Note you can listen on multiple IPs/ports using commas:
;listen=127.0.0.1:2529,127.0.0.2:2529,127.0.0.3:2530
; public IP address (default: none)
; If your machine is behind a NAT, some plugins (SPF, GeoIP) gain features
; if they know the servers public IP. If 'stun' is installed, Haraka will
; try to figure it out. If that doesn't work, set it here.
;public_ip=N.N.N.N
; Time in seconds to let sockets be idle with no activity
inactivity_timeout=300
; Drop privileges to this user/group
user=haraka
group=haraka
; Don't stop Haraka if plugins fail to compile
;ignore_bad_plugins=0
; Run using cluster to fork multiple backend processes
;nodes=cpus
; Daemonize
daemonize=true
daemon_log_file=/var/log/haraka/haraka-$direction.log
daemon_pid_file=/var/run/haraka-$direction.pid
; Spooling
; Save memory by spooling large messages to disk
spool_dir=/var/spool/haraka/haraka-$direction
; Specify -1 to never spool to disk
; Specify 0 to always spool to disk
; Otherwise specify a size in bytes, once reached the
; message will be spooled to disk to save memory.
spool_after=1024
EOF
rm -rf "$targetFile" || exit 1
ln -s "$filePath" "$targetFile" || exit 1
done
}
create_InboundPlugins() {
echo "Creating inbound plugins config.."
cat > "$CONFIG_PATH/in.plugins" <<EOF
process_title
tls
access
dnsbl
data.headers
helo.checks
mail_from.is_resolvable
max_unrecognized_commands
rcpt_to.max_count
jme.rcpt_to.disposable
jme.rcpt_to.aliases
jme.rcpt_to.mailboxes
queue/discard
EOF
rm -rf "$IN_PATH/config/plugins" || exit 1
ln -s "$CONFIG_PATH/in.plugins" "$IN_PATH/config/plugins" || exit 1
}
create_OutboundPlugins() {
echo "Creating outbound plugins config.."
cat > "$CONFIG_PATH/out.plugins" <<EOF
process_title
tls
auth/jme.auth.flat_file.sha512crypt
jme.queue_outbound.accounts
EOF
rm -rf "$OUT_PATH/config/plugins" || exit 1
ln -s "$CONFIG_PATH/out.plugins" "$OUT_PATH/config/plugins" || exit 1
}
create_AliasesConfig() {
echo "Creating default aliases.."
local rootAddress
local rootAlias
read -p "What is your root email address? [root@$DOMAIN] " rootAddress
if [[ "$rootAddress" == "" ]]; then
rootAddress="root@$DOMAIN"
echo "Keeping default $rootAddress.."
else
if [[ "$rootAddress" =~ (.+)@.* ]]; then
if [[ "${BASH_REMATCH[1]}" != "root" ]]; then
rootAlias=",
\"root\": \"$rootAddress\""
fi
else
rootAddress="root@$DOMAIN"
echo "Invalid email address, defaulting to $rootAddress.."
rootAlias=",
\"root\": \"$rootAddress\""
fi
fi
cat > "$CONFIG_PATH/jme.rcpt_to.aliases" <<EOF
{
"authMethod": "file",
"aliases": {
"$DOMAIN": {
"admin": "root",
"postmaster": "root",
"dev": "root"$rootAlias
}
}
}
EOF
createLinks "$CONFIG_PATH/jme.rcpt_to.aliases" "config/jme.rcpt_to.aliases" || exit 1
}
create_MailboxesConfig() {
echo "Creating mailbox accounts.."
cat > "$CONFIG_PATH/jme.mailbox_accounts" <<EOF
{
"authMethod": "file",
"accounts": {
"$DOMAIN": {
"root": {}
}
}
}
EOF
createLinks "$CONFIG_PATH/jme.mailbox_accounts" "config/jme.mailbox_accounts" || exit 1
}
link_nuxMailPlugins() {
echo "Linking nuxMail plugins.."
createLinks "$PLUGIN_PATH/jme.auth.flat_file.sha512crypt.js" "plugins/auth/jme.auth.flat_file.sha512crypt.js" "out" || exit 1
createLinks "$PLUGIN_PATH/jme.queue_outbound.accounts.js" "plugins/jme.queue_outbound.accounts.js" "out" || exit 1
createLinks "$PLUGIN_PATH/jme.rcpt_to.disposable.js" "plugins/jme.rcpt_to.disposable.js" "in" || exit 1
createLinks "$PLUGIN_PATH/jme.rcpt_to.aliases.js" "plugins/jme.rcpt_to.aliases.js" "in" || exit 1
createLinks "$PLUGIN_PATH/jme.rcpt_to.mailboxes.js" "plugins/jme.rcpt_to.mailboxes.js" "in" || exit 1
}
edgeConfigs() {
echo "Configuring edge settings.."
# Log level
echo "LOGPROTOCOL" > "$CONFIG_PATH/loglevel"
createLinks "$CONFIG_PATH/loglevel" "config/loglevel" true
# Set size limit of emails
echo "20971520" > "$CONFIG_PATH/databytes"
createLinks "$CONFIG_PATH/databytes" "config/databytes" true
}
install_Hcont() {
echo "Configuring hcont.."
# TODO: sed the IN_ and OUT_ locations in hcont
ln -s "$NUX_PATH/hcont" "$INSTALL_PATH/hcont"
chmod +x "$INSTALL_PATH/hcont"
read -p "Would you like to start Haraka now? [Y/n]" startNow
if [[ "$startNow" != [Nn] ]]; then
"$INSTALL_PATH/hcont" start both
else
echo "Haraka not started. To do so, please use '$INSTALL_PATH/hcont start both'"
fi
}
set_Permissions() {
# Create haraka user
useradd -d "$INSTALL_PATH" -M -s /bin/false haraka
# Create log dir
mkdir -p /var/log/haraka
# Chown stuff + 755 it
chown -R haraka.haraka "$INSTALL_PATH" /var/log/haraka
chmod -R 755 "$INSTALL_PATH" /var/log/haraka
}
# Go
main