3 # This script changes selinux file labels for cgi scripts.
4 # It may be useful for Linux installations with SELinux (like CentOS, Fedora,
5 # RedHat among others) and having it enabled (enforcing mode).
7 # Copyright 2012 Rijksmuseum
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 echo "Usage: set-selinux-labels [-h] [-u] [-r] [-s] [-v]"
26 echo " -h prints help information."
27 echo " -u updates the selinux label for scripts in Koha installation."
28 echo " Note: you should be in the root directory of a Koha install."
29 echo " -r uses restorecon on scripts to restore default label."
30 echo " -s shows all files (incl. scripts), not having default label."
31 echo " -v provides (verbose) diagnostics per file (for update/restore)."
33 echo "The output of -s may be confusing, but it does not reset any labels. It only prints informational messages from restorecon with -n flag."
37 #Now set perl scripts to httpd_sys_script_exec_t
38 #We skip scripts in: misc docs t xt and atomicupdate
39 find -name "*.pl" -and ! -path "./docs/*" -and ! -path "./misc/*" -and ! -path "./t/*" -and ! -path "./xt/*" -and ! -path "./installer/data/mysql/atomicupdate/*" |
xargs chcon
$verbose -t httpd_sys_script_exec_t
41 #Handle exceptions to the rule: scripts without .pl
42 chcon
$verbose -t httpd_sys_script_exec_t opac
/unapi
43 find opac
/svc
-type f |
xargs chcon
$verbose -t httpd_sys_script_exec_t
44 find svc
-type f |
xargs chcon
$verbose -t httpd_sys_script_exec_t
48 find -name "*.pl" -and ! -path "./docs/*" -and ! -path "./misc/*" -and ! -path "./t/*" -and ! -path "./xt/*" -and ! -path "./installer/data/mysql/atomicupdate/*" |
xargs restorecon
$verbose
49 restorecon
$verbose opac
/unapi
50 find opac
/svc
-type f |
xargs restorecon
$verbose
51 find svc
-type f |
xargs restorecon
$verbose
58 #First: check on chcon xargs restorecon
59 chcon
--help >/dev
/null
2>&1
61 if [ $retval -ne 0 ]; then
62 echo "Chcon command not found. Exiting script now.";
65 xargs --help >/dev
/null
2>&1
67 if [ $retval -ne 0 ]; then
68 echo "Xargs command not found. Exiting script now.";
71 restorecon
-n >/dev
/null
2>&1
73 if [ $retval -ne 0 ]; then
74 echo "Restorecon command not found. Exiting script now.";
84 #Check command line options
89 while getopts "hrsuv" option
; do
105 #Check if you are on root level of Koha installation
106 if [ ! -e kohaversion.pl
]; then
107 echo "You are not in root directory of Koha install. Cannot continue. Bye.";
111 #Cannot update and restore together
112 if [ $update -eq 1 ] && [ $restore -eq 1 ]; then
113 echo "You cannot run update and restore at the same time."
117 #Now run the job or print usage
118 if [ $update -eq 1 ]; then updatelabel
; exit; fi
119 if [ $restore -eq 1 ]; then restorelabel
; exit; fi
120 if [ $show -eq 1 ]; then showlabel
; exit; fi