-
Notifications
You must be signed in to change notification settings - Fork 2
/
installer.sh
executable file
·159 lines (155 loc) · 5.7 KB
/
installer.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
#!/bin/bash
echo 'This script will install MailGuardian, MailScanner and other required components onto the system'
echo ''
LNX_OS_RELEASE=$(grep '^ID=' < /etc/os-release | sed 's/ID="//g' | sed 's/"//g')
if [ -z "$LNX_OS_RELEASE" ]
then
echo 'Unable to determine Linux version'
exit 255
fi
export LNX_OS_RELEASE
if [ $LNX_OS_RELEASE == 'centos' ];
then
LNX_PKG_MGR='yum'
elif [ $LNX_OS_RELEASE == 'almalinux' ];
then
LNX_PKG_MGR='dnf'
elif [ $LNX_OS_RELEASE == 'rocky' ];
then
LNX_PKG_MGR='dnf'
elif [ $LNX_OS_RELEASE == 'rhel' ];
then
LNX_PKG_MGR='yum'
elif [ $LNX_OS_RELEASE == 'Ubuntu' ];
then
LNX_PKG_MGR='apt'
elif [ $LNX_OS_RELEASE == 'ubuntu' ];
then
LNX_PKG_MGR='apt'
elif [ $LNX_OS_RELEASE == 'debian' ];
then
LNX_PKG_MGR='apt'
else
LNX_OS_RELEASE=$(grep '^ID=' < /etc/os-release | sed 's/ID=//g')
if [ $LNX_OS_RELEASE == 'centos' ];
then
LNX_PKG_MGR='yum'
elif [ $LNX_OS_RELEASE == 'almalinux' ];
then
LNX_PKG_MGR='dnf'
elif [ $LNX_OS_RELEASE == 'rocky' ];
then
LNX_PKG_MGR='dnf'
elif [ $LNX_OS_RELEASE == 'rhel' ];
then
LNX_PKG_MGR='dnf'
elif [ $LNX_OS_RELEASE == 'Ubuntu' ];
then
LNX_PKG_MGR='apt'
elif [ $LNX_OS_RELEASE == 'ubuntu' ];
then
LNX_PKG_MGR='apt'
elif [ $LNX_OS_RELEASE == 'debian' ];
then
LNX_PKG_MGR='apt'
else
echo 'Unable to determine Linux distribution. Only Debian, Ubuntu and CentOS are supported for this script'
exit 255
fi
fi
if ! command -v python3 &> /dev/null
then
HAS_PY3=0
if ! command -v python2 &> /dev/null
then
echo 'Unable to determine installed python version. We will assume that it is not there'
HAS_PY3=0
fi
else
HAS_PY3=1
fi
export LNX_PKG_MGR
echo ''
echo 'Installing...'
if [[ $HAS_PY3 -eq 0 ]]
then
echo 'Installing Python 3...'
if [ $LNX_OS_RELEASE == 'centos' ];
then
$LNX_PKG_MGR install -y epel-release
fi
$LNX_PKG_MGR install -y python3 python3-setuptools
fi
$LNX_PKG_MGR install -y python3-pip
echo 'Creating application user...'
useradd -m mailguardian
chmod 755 /home/mailguardian
echo 'Installing git commandline tools curl and wget...'
$LNX_PKG_MGR install git curl wget -y
echo 'Pulling application sourcecode from GitHub...'
su - mailguardian -c 'git clone https://github.com/KHIT93/mailguardian.git /home/mailguardian/mailguardian --branch master'
cd /home/mailguardian/mailguardian || exit 1
ENV_DB_PASS=$(date +%s | sha256sum | base64 | head -c 32)
export ENV_DB_PASS
pip3 install pytz distro
if ! python3 ./installer/configure.py -f /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but something has gone wrong during initial steps of installation. Please fix the errors above and try again'
exit 1
fi
echo 'Installing required packages...'
if ! touch /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but it appears as if we are unable to create the configuration file for the installation script. Please check the error above and try again'
exit 1
fi
if ! python3 ./installer/deps.py -f /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but something has gone wrong during initial steps of installation. Please fix the errors above and try again'
exit 1
fi
if ! usermod -a -G mtagroup,postfix mailguardian; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
if ! su - mailguardian -c 'cd /home/mailguardian/mailguardian && virtualenv -p python3 . && bin/pip install -r requirements.txt'; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
echo 'Installing MailGuardian...'
if ! echo 'create database mailguardian;' | su - postgres -c psql; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
if ! echo "create user mailguardian with encrypted password '$ENV_DB_PASS';" | su - postgres -c psql; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
if ! echo 'grant all privileges on database mailguardian to mailguardian;' | su - postgres -c psql; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
if ! bin/python ./installer/mailguardian.py -f /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
echo 'Configure Postfix...'
if ! bin/python ./installer/postfix.py -f /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
echo 'Configure MailScanner...'
if ! bin/python ./installer/mailscanner.py -f /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
echo 'Configure SpamAssasson...'
if ! bin/python ./installer/spamassassin.py -f /home/mailguardian/mailguardian/installer.ini; then
echo 'We are really sorry, but something seems to have gone wrong or the script was aborted'
exit 1
fi
echo 'Performing initial compilation of MailGuardian...'
su - mailguardian -c 'cd /home/mailguardian/mailguardian; npm install; npm run production'
echo 'Waiting a short moment to allow startup of virus scanners'
bin/python -c 'import time; time.sleep(10)'
spamassassin -D -p /etc/MailScanner/spamassassin.conf --lint
MailScanner --lint
echo 'Installation has finished. Please reboot your system and finish the application configuration in your web browser'
exit 0