new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / init / init.sh
1 #!/bin/sh
2 # Init functions for the OSSEC HIDS
3 # Author: Daniel B. Cid <daniel.cid@gmail.com>
4
5 UN=${NUNAME};
6
7 runInit()
8 {
9     echo ""
10     echo ""
11     # Checking if it is a Redhat system.
12     if [ -r "/etc/redhat-release" ]; then
13         if [ -d /etc/rc.d/init.d ]; then
14             echo " - ${systemis} Redhat Linux."
15             echo " - ${modifiedinit}"
16             cp -pr ./src/init/ossec-hids-rh.init /etc/rc.d/init.d/ossec
17             chmod 555 /etc/rc.d/init.d/ossec
18             chown root:ossec /etc/rc.d/init.d/ossec
19             /sbin/chkconfig --add ossec > /dev/null 2>&1
20             return 0;
21         fi
22     fi
23     # Checking for Gentoo
24     if [ -r "/etc/gentoo-release" ]; then
25         echo " - ${systemis} Gentoo Linux."
26         echo " - ${modifiedinit}"
27         cp -pr ./src/init/ossec-hids-gentoo.init /etc/init.d/ossec
28         chmod 555 /etc/init.d/ossec
29         chown root:ossec /etc/init.d/ossec
30         rc-update add ossec default
31         return 0;
32     fi
33
34     # Suse
35     if [ -r "/etc/SuSE-release" ]; then
36         echo " - ${systemis} Suse Linux."
37         echo " - ${modifiedinit}"
38
39         cp -pr ./src/init/ossec-hids-suse.init  /etc/init.d/ossec
40         chmod 555 /etc/init.d/ossec
41         chown root:ossec /etc/init.d/ossec
42
43         /sbin/chkconfig --add ossec > /dev/null 2>&1
44         return 0;
45     fi
46
47     # Checking for slackware (by Jack S. Lai)
48     if [ -r "/etc/slackware-version" ]; then
49         echo " - ${systemis} Slackware Linux."
50         echo " - ${modifiedinit}"
51         cp -pr ./src/init/ossec-hids.init /etc/rc.d/rc.ossec
52         chmod 555 /etc/rc.d/rc.ossec
53         chown root:ossec /etc/rc.d/rc.ossec
54
55         grep ossec /etc/rc.d/rc.local > /dev/null 2>&1
56         if [ $? != 0 ]; then
57             echo "if [ -x /etc/rc.d/rc.ossec ]; then" >> /etc/rc.d/rc.local
58             echo "      /etc/rc.d/rc.ossec start" >>/etc/rc.d/rc.local
59             echo "fi" >>/etc/rc.d/rc.local
60         fi
61
62         return 0;
63     fi
64
65     # Darwin init script (by Lorenzo Costanzia di Costigliole <mummie@tin.it>)
66     if [ "X${NUNAME}" = "XDarwin" ]; then
67         # Generating darwin init script.
68
69         echo " - ${systemis} Darwin."
70         echo " - ${modifiedinit}"
71         sh ./src/init/darwin-init.sh
72         return 0;
73     fi
74
75     if [ "X${UN}" = "XSunOS" ]; then
76         echo " - ${systemis} Solaris (SunOS)."
77         echo " - ${modifiedinit}"
78         cp -pr ./src/init/ossec-hids-solaris.init /etc/init.d/ossec
79         chmod 755 /etc/init.d/ossec
80         ln -s /etc/init.d/ossec /etc/rc2.d/S97ossec
81         ln -s /etc/init.d/ossec /etc/rc3.d/S97ossec
82         return 0;
83     fi
84
85     if [ "X${UN}" = "XAIX" ]; then
86         echo " - ${systemis} AIX."
87         echo " - ${modifiedinit}"
88         cp -pr ./src/init/ossec-hids-aix.init /etc/rc.d/init.d/ossec
89         chmod 755 /etc/rc.d/init.d/ossec
90         ln -s /etc/rc.d/init.d/ossec /etc/rc.d/rc2.d/S97ossec
91         ln -s /etc/rc.d/init.d/ossec /etc/rc.d/rc3.d/S97ossec
92         return 0;
93     fi
94
95     if [ "X${UN}" = "XOpenBSD" -o "X${UN}" = "XNetBSD" -o "X${UN}" = "XFreeBSD" -o "X${UN}" = "XDragonFly" ]; then
96         # Checking for the presence of ossec-control on rc.local
97         grep ossec-control /etc/rc.local > /dev/null 2>&1
98         if [ $? != 0 ]; then
99             echo "echo \"${starting}\"" >> /etc/rc.local
100             echo "${INSTALLDIR}/bin/ossec-control start" >> /etc/rc.local
101         fi
102         echo " - ${systemis} ${NUNAME}."
103         echo " - ${modifiedinit}"
104         return 0;
105     elif [ "X${NUNAME}" = "XLinux" ]; then
106         if [ -e "/etc/rc.d/rc.local" ]; then
107             echo " - ${systemis} Linux."
108             echo " - ${modifiedinit}"
109
110             grep ossec-control /etc/rc.d/rc.local > /dev/null 2>&1
111             if [ $? != 0 ]; then
112                 echo "echo \"${starting}\"" >> /etc/rc.d/rc.local
113                 echo "${INSTALLDIR}/bin/ossec-control start" >> /etc/rc.d/rc.local
114             fi
115             return 0;
116         elif [ -d "/etc/rc.d/init.d" ]; then
117             echo " - ${systemis} Linux (SysV)."
118             echo " - ${modifiedinit}"
119             cp -pr ./src/init/ossec-hids.init  /etc/rc.d/init.d/ossec
120             chmod 555 /etc/rc.d/init.d/ossec
121             chown root:ossec /etc/rc.d/init.d/ossec
122             return 0;
123         # Taken from Stephen Bunn ossec howto.
124         elif [ -d "/etc/init.d" -a -f "/usr/sbin/update-rc.d" ]; then
125             echo " - ${systemis} Debian (Ubuntu or derivative)."
126             echo " - ${modifiedinit}"
127             cp -pr ./src/init/ossec-hids-debian.init  /etc/init.d/ossec
128             chmod +x /etc/init.d/ossec
129             chmod go-w /etc/init.d/ossec
130             chown root:ossec /etc/init.d/ossec
131             update-rc.d ossec defaults > /dev/null 2>&1
132             return 0;
133         elif [ -e "/etc/alpine-release" ]; then
134             echo " - ${systemis} Alpine Linux."
135             echo " - ${modifiedinit}"
136             cp -pr ./src/init/ossec-hids-alpine.init /etc/init.d/ossec
137             chmod +x /etc/init.d/ossec
138             chmod go-w /etc/init.d/ossec
139             chown root:ossec /etc/init.d/ossec
140             return 0;
141         else
142             echo " - ${noboot}"
143         fi
144     else
145         echo " - ${noboot}"
146     fi
147
148     return 1;
149 }
150