aboutsummaryrefslogtreecommitdiffstats
path: root/security/sshguard/pkg-install
blob: 09b275c4066942e4ce9c499e9c87b758b03f6c10 (plain) (blame)
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
#!/bin/sh

# If:
#   1) syslog.conf exists
#   2) it doesn't already contain some (uncommented) sshguard directive
# then add $SSHGUARDCONFLINE (commented) right at the end of the header
# comments section in syslog.conf

# real syslog.conf configuration file path
SYSLOGCONF=/etc/syslog.conf
# configuration line to add
SSHGUARDCONFLINE="auth.info;authpriv.info     |exec $PKG_PREFIX/sbin/sshguard"

case "$2" in
    "POST-INSTALL")
        if test "x$SSHGUARDFW" = xhosts
        then
            touch /etc/hosts.allow
        fi
        if (test -f "$SYSLOGCONF" && ! grep -q sshguard "$SYSLOGCONF")
        then
            # append default sshguard entry in syslog.conf (first line after comments header)
        TMPFILE=`mktemp -q /tmp/syslogcXX`
        # make sure our file has the same permissions as the original, since we mv it back
        cp -p $SYSLOGCONF ${TMPFILE}
        echo > ${TMPFILE}
            inheader=1
            cat "$SYSLOGCONF" | while read cline ;
            do
                if (test $inheader -eq 1 && !(echo "$cline" | grep -q "^[[:space:]]*#"))
                then
                    # got off of header comments
                    inheader=0
                    echo "#$SSHGUARDCONFLINE" >> $TMPFILE
                fi
                echo "$cline" >> $TMPFILE
            done
            mv $TMPFILE "$SYSLOGCONF"
        fi
;;
esac