01-setup 2.15 KB
Newer Older
1
2
#!/bin/bash

3
# Prepare the system for runnign the sympl-test suite
Paul Cammish's avatar
Paul Cammish committed
4

5
6
sympl-filesystem-security

7
8
export LC_ALL="en_GB.UTF-8"

Paul Cammish's avatar
Paul Cammish committed
9
echo "I: Creating local system user for testing if it doesnt exist."
10
if [ ! -d '/home/sympl-test' ]; then
Paul Cammish's avatar
Paul Cammish committed
11
  # Create a local system user to deliver test mail to
12
  /usr/sbin/useradd --create-home sympl-test
Paul Cammish's avatar
Paul Cammish committed
13
14
fi

Paul Cammish's avatar
Paul Cammish committed
15
16
if [ $( grep -c public_ip /etc/hosts ) == 0 ]; then echo $(sympl-ip) public_ip >> /etc/hosts ; fi

Paul Cammish's avatar
Paul Cammish committed
17
# remove any existing definations
18
touch /srv/$(hostname -f)/config/antivirus
Paul Cammish's avatar
Paul Cammish committed
19
20
21
22
23
24

# Start freshclam to download new definitions, whatever state it's in
systemctl unmask clamav-freshclam
service clamav-freshclam stop
rm -rf /run/clamav
service clamav-freshclam start
25

26
27
sleep 3

Paul Cammish's avatar
Paul Cammish committed
28
echo -n "I: Waiting for clamav to download databases."
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
for i in $(seq 1 100) ; do
  if [ -f "/var/lib/clamav/main.cvd" -o -f "/var/lib/clamav/main.cld" ] ; then
    echo -n ' 1/3 '
    break
  fi
  echo -n "."
  sleep 1
done
for i in $(seq 1 100) ; do
  if [ -f "/var/lib/clamav/daily.cvd" -o -f "/var/lib/clamav/daily.cld" ] ; then
    echo -n ' 2/3 '
    break
  fi
  echo -n "."
  sleep 1
done
for i in $(seq 1 100) ; do
  if [ -f "/var/lib/clamav/bytecode.cvd" -o -f "/var/lib/clamav/bytecode.cld" ] ; then
    echo " 3/3 done."
Paul Cammish's avatar
Paul Cammish committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    invoke-rc.d clamav-daemon restart
    break
  fi
  echo -n "."
  sleep 1
done

# Start clamav, whatever state it's currently in
systemctl unmask clamav-daemon
service clamav-daemon stop
service clamav-daemon start

# Enable antispam and antivirus as default, otherwise monit would stop them.
echo "I: Enabling Antivirus and Antispam config"
62
touch /srv/$(hostname -f)/config/anti{spam,virus}
63
64
65

# We need to wait a little while for spamd and clamd to start properly before testing.

Paul Cammish's avatar
Paul Cammish committed
66
67
echo -n 'I: Waiting for ClamAV to start.'
while [ `ps -ef | grep "^clamav" | grep -v -c 'grep'` -lt 2 ]; do
68
69
70
  echo -n '.'
  sleep 1
done
Paul Cammish's avatar
Paul Cammish committed
71
72
73
74
echo ' done.'

# Start spamassassin, from whatever state

75
touch /srv/$(hostname -f)/config/antispam
Paul Cammish's avatar
Paul Cammish committed
76
77
78
systemctl unmask spamassassin
service spamassassin stop
service spamassassin start
79

Paul Cammish's avatar
Paul Cammish committed
80
81
echo -n 'I: Waiting for SpamAssassin to start.'
while [ `ps -ef | grep 'spamd child' | grep -v -c grep` -lt 2 ]; do
82
83
84
  echo -n '.'
  sleep 1
done
Paul Cammish's avatar
Paul Cammish committed
85
echo ' done.'
86

87