]> granicus.if.org Git - icinga2/blob - tools/selinux/icinga2.sh
added chcon to systemd safe-reload script
[icinga2] / tools / selinux / icinga2.sh
1 #!/bin/sh -e
2
3 DIRNAME=`dirname $0`
4 cd $DIRNAME
5 USAGE="$0 [ --update ]"
6 if [ `id -u` != 0 ]; then
7 echo 'You must be root to run this script'
8 exit 1
9 fi
10
11 if [ $# -eq 1 ]; then
12         if [ "$1" = "--update" ] ; then
13                 time=`ls -l --time-style="+%x %X" icinga2.te | awk '{ printf "%s %s", $6, $7 }'`
14                 rules=`ausearch --start $time -m avc --raw -se icinga2`
15                 if [ x"$rules" != "x" ] ; then
16                         echo "Found avc's to update policy with"
17                         echo -e "$rules" | audit2allow -R
18                         echo "Do you want these changes added to policy [y/n]?"
19                         read ANS
20                         if [ "$ANS" = "y" -o "$ANS" = "Y" ] ; then
21                                 echo "Updating policy"
22                                 echo -e "$rules" | audit2allow -R >> icinga2.te
23                                 # Fall though and rebuild policy
24                         else
25                                 exit 0
26                         fi
27                 else
28                         echo "No new avcs found"
29                         exit 0
30                 fi
31         else
32                 echo -e $USAGE
33                 exit 1
34         fi
35 elif [ $# -ge 2 ] ; then
36         echo -e $USAGE
37         exit 1
38 fi
39
40 echo "Building and Loading Policy"
41 set -x
42 make -f /usr/share/selinux/devel/Makefile icinga2.pp || exit
43 /usr/sbin/semodule -i icinga2.pp
44
45 # Generate a man page off the installed module
46 sepolicy manpage -p . -d icinga2_t
47 # Fixing the file context on /usr/sbin/icinga2
48 /sbin/restorecon -F -R -v /usr/sbin/icinga2
49 # Fixing the file context on /etc/rc\.d/init\.d/icinga2
50 #/sbin/restorecon -F -R -v /etc/rc\.d/init\.d/icinga2
51 # Fixing the file context on /etc/icinga2/scripts
52 /sbin/restorecon -F -R -v /etc/icinga2/scripts
53 # Fixing the file context on /var/log/icinga2
54 /sbin/restorecon -F -R -v /var/log/icinga2
55 # Fixing the file context on /var/lib/icinga2
56 /sbin/restorecon -F -R -v /var/lib/icinga2
57 # Fixing the file context on /var/run/icinga2
58 /sbin/restorecon -F -R -v /var/run/icinga2
59 # Fixing the file context on /var/cache/icinga2
60 /sbin/restorecon -F -R -v /var/cache/icinga2
61 # Fixing the file context on /var/spool/icinga2
62 /sbin/restorecon -F -R -v /var/spool/icinga2
63
64 # Fix dir permissions until we have it in the package
65 chown root /etc/icinga2
66 chown root /etc/icinga2/init.conf
67
68 # Label the port 5665
69 /sbin/semanage port -a -t icinga2_port_t -p tcp 5665
70
71 # Generate a rpm package for the newly generated policy
72 pwd=$(pwd)
73 #rpmbuild --define "_sourcedir ${pwd}" --define "_specdir ${pwd}" --define "_builddir ${pwd}" --define "_srcrpmdir ${pwd}" --define "_rpmdir ${pwd}" --define "_buildrootdir ${pwd}/.build"  -ba icinga2_selinux.spec