-
Notifications
You must be signed in to change notification settings - Fork 30
/
setup.sh
executable file
·80 lines (60 loc) · 3.4 KB
/
setup.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
#!/bin/bash
args=("$@")
if [ "$#" -gt "0" ]
then
# foo/bar -> bar
MAILDOMAIN=${args[0]}
HOSTNAME=${args[1]:-$MAILDOMAIN}
echo -e "DOMAINNAME: $MAILDOMAIN, HOSTNAME: $HOSTNAME"
else
echo -e "Got ZERO arguments, please read the readme for help."
exit
fi
if [ ! -d /wildduck-dockerized/config ]; then
echo "Copying default configuration"
cp -r /setup/default-config /wildduck-dockerized/config
fi
if [ ! -e /wildduck-dockerized/docker-compose.yml ]; then
echo "Copying default docker-compose.yml"
cp -r /setup/docker-compose.yml /wildduck-dockerized/docker-compose.yml
fi
if [ ! -e /wildduck-dockerized/.env ]; then
echo "Copying default .env"
cp -r /setup/example.env /wildduck-dockerized/.env
fi
echo "Replacing domains in configuration"
# Zone-MTA
sed -i "s/# name=\"example.com\"/name=\"$HOSTNAME\"/" /wildduck-dockerized/config/zone-mta/pools.toml
sed -i "s/hostname=\"example.com\"/hostname=\"$HOSTNAME\"/" /wildduck-dockerized/config/zone-mta/plugins/wildduck.toml
sed -i "s/rewriteDomain=\"example.com\"/rewriteDomain=\"$MAILDOMAIN\"/" /wildduck-dockerized/config/zone-mta/plugins/wildduck.toml
# Wildduck
sed -i "s/hostname=\"example.com\"/hostname=\"$HOSTNAME\"/" /wildduck-dockerized/config/wildduck/imap.toml
sed -i "s/hostname=\"example.com\"/hostname=\"$HOSTNAME\"/" /wildduck-dockerized/config/wildduck/pop3.toml
sed -i "s/hostname=\"example.com\"/hostname=\"$HOSTNAME\"/" /wildduck-dockerized/config/wildduck/default.toml
sed -i "s/localhost:3000/$HOSTNAME/" /wildduck-dockerized/config/wildduck/default.toml
sed -i "s/#emailDomain=\"mydomain.info\"/emailDomain=\"$MAILDOMAIN\"/" /wildduck-dockerized/config/wildduck/pop3.toml
# Wildduck-webmail
sed -i "s/domain=\"localhost\"/domain=\"$MAILDOMAIN\"/" /wildduck-dockerized/config/wildduck-webmail/default.toml
sed -i "s/domains=\[\"localhost\"\]/domains=\[\"$MAILDOMAIN\"\]/" /wildduck-dockerized/config/wildduck-webmail/default.toml
sed -i "s/#appId=\"https:\/\/127.0.0.1:8080\"/appId=\"https:\/\/$MAILDOMAIN\"/" /wildduck-dockerized/config/wildduck-webmail/default.toml
sed -i "s/hostname=\"localhost\"/hostname=\"$HOSTNAME\"/g" /wildduck-dockerized/config/wildduck-webmail/default.toml
# Haraka
echo "$HOSTNAME" > /wildduck-dockerized/config/haraka/me
# Traefik
sed -i "s/HOSTNAMES=example.com/HOSTNAMES=$HOSTNAME/" /wildduck-dockerized/.env
echo "Generating secrets and placing them in configuration"
SRS_SECRET=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c30`
ZONEMTA_SECRET=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c30`
WEBMAIL_SECRET=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c30`
WEBMAIL_TOTP_SECRET=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c30`
# Zone-MTA
sed -i "s/secret=\"super secret value\"/secret=\"$ZONEMTA_SECRET\"/" /wildduck-dockerized/config/zone-mta/plugins/loop-breaker.toml
sed -i "s/secret=\"secret value\"/secret=\"$SRS_SECRET\"/" /wildduck-dockerized/config/zone-mta/plugins/wildduck.toml
# Wildduck
sed -i "s/#loopSecret=\"secret value\"/loopSecret=\"$SRS_SECRET\"/" /wildduck-dockerized/config/wildduck/sender.toml
# Wildduck-webmail
sed -i "s/secret=\"a cat\"/secret=\"$WEBMAIL_SECRET\"/" /wildduck-dockerized/config/wildduck-webmail/default.toml
sed -i "s/secret=\"a secret cat\"/secret=\"$WEBMAIL_TOTP_SECRET\"/" /wildduck-dockerized/config/wildduck-webmail/default.toml
# Haraka
sed -i "s/#loopSecret=\"secret value\"/loopSecret=\"$SRS_SECRET\"/" /wildduck-dockerized/config/haraka/wildduck.yaml
echo "Done!"