#! /bin/bash # Rocky9 compatible . /usr/src/k_framework/main.sh SCRIPT_NAME="Selinux Disable" VERSION="1.1.2" k_start selinux_installed() { # Author: Mindaugas Mardosas # Company: Kolmisoft # Year: 2011 # About: This function detects if selinux is installed if [ -f "/usr/sbin/sestatus" ]; then return 0 else report "SELinux not present" 3 return 1 fi } #------------------- selinux_check_if_disabled() { SEL=`sestatus | grep "disabled"` if [ -n "$SEL" ]; then return 0; else return 1; fi } #------------------- selinux_disable() { setenforce 0 echo -e "SELINUX=disabled\nSELINUXTYPE=targeted" > /etc/selinux/config if [ -f /selinux/enforce ]; then echo 0 > /selinux/enforce fi } #------------------- selinux_test_and_fix() { if [ ! -f "/etc/redhat-release" ]; then report "Test is written for CentOS/RedHat, please get one of those distributions" 1 k_exit 1 fi selinux_check_if_disabled if [ "$?" == "0" ]; then report "SElinux is disabled" 0 k_exit 0 else selinux_disable selinux_check_if_disabled if [ "$?" == "0" ]; then report "SElinux disabled" 0 k_exit 0 else report "SElinux is not disabled" 1 k_exit 1 fi fi } #------------ MAIN ----------------- selinux_installed if [ "$?" == "0" ]; then selinux_test_and_fix fi k_exit $EXIT_CODE