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