01-setup 2.67 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

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

20
# Start freshclam to download new definitions, whatever state it's in
21
systemctl unmask clamav-freshclam
22
23
service clamav-freshclam stop
rm -rf /run/clamav
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
#service clamav-freshclam start
#
#sleep 3
#
#echo -n "I: Waiting for clamav to download databases."
#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."
#    invoke-rc.d clamav-daemon restart
#    break
#  fi
#  echo -n "."
#  sleep 1
#done
Paul Cammish's avatar
Paul Cammish committed
54

55
# horrible hack
56
57
58
59
60
61
62
63
#if [ -f "/var/lib/clamav/bytecode.cvd" -o -f "/var/lib/clamav/bytecode.cld" ] && [ -f "/var/lib/clamav/daily.cvd" -o -f "/var/lib/clamav/daily.cld" ] && [ -f "/var/lib/clamav/main.cvd" -o -f "/var/lib/clamav/main.cld" ] ; then
#  echo "We have what look to be valid definitions..."
#else
#  echo "Failed to download clamAV definitions, going to fallback."
cd /var/lib/clamav/
wget -qO clamav.tar.gz http://sympl.io/clamav.tar.gz
tar -xvf clamav.tar.gz
#fi
64

Paul Cammish's avatar
Paul Cammish committed
65
66
# Start clamav, whatever state it's currently in
systemctl unmask clamav-daemon
67
service clamav-daemon stop
Paul Cammish's avatar
Paul Cammish committed
68
service clamav-daemon start
69
service clamav-freshclam start
Paul Cammish's avatar
Paul Cammish committed
70
71
72

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

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

Paul Cammish's avatar
Paul Cammish committed
77
78
echo -n 'I: Waiting for ClamAV to start.'
while [ `ps -ef | grep "^clamav" | grep -v -c 'grep'` -lt 2 ]; do
79
80
81
  echo -n '.'
  sleep 1
done
Paul Cammish's avatar
Paul Cammish committed
82
83
84
85
echo ' done.'

# Start spamassassin, from whatever state

86
touch /srv/$(hostname -f)/config/antispam
Paul Cammish's avatar
Paul Cammish committed
87
88
89
systemctl unmask spamassassin
service spamassassin stop
service spamassassin start
90

Paul Cammish's avatar
Paul Cammish committed
91
92
echo -n 'I: Waiting for SpamAssassin to start.'
while [ `ps -ef | grep 'spamd child' | grep -v -c grep` -lt 2 ]; do
93
94
95
  echo -n '.'
  sleep 1
done
Paul Cammish's avatar
Paul Cammish committed
96
echo ' done.'
97

98