HEX
Server: nginx/1.16.1
System: Linux ecs-04358622 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 #1 SMP Wed Dec 1 19:59:44 CST 2021 x86_64
User: nginx (994)
PHP: 8.0.0
Disabled: NONE
Upload Files
File: //opt/BCLinux/bse/secure_set/s15_disableUnUsedSoft
#!/bin/sh


#=======================================================
InsertSection "Disable the UnUsed software"

rhel78_dis()
{
    needStopSer=$UNUSED_SOFTWARE_VALUE
    system_active_ser_soc=$(systemctl list-units --type=service --type=socket  | grep -v "failed\|exited" | grep  ".socket \|.service "  | awk -F "loaded" '{print $1}' | sed  's/ //g')
    for i in $needStopSer
    do
        rock=`echo $system_active_ser_soc | grep -iw ${i} | wc -l`
        if [ ${rock} -gt 0 ];then
            systemctl is-active $i > /dev/null 2>&1  #make sure $i is running on this system
            if [ $? -eq 0 ];then
                echo "stop ${i}"
                systemctl stop ${i}
                logtext "Stop the unused software:$i, you can use systemctl start ${i} to enable it..."
            fi
            systemctl is-enabled $i > /dev/null 2>&1 #make sure $i is disabled
            if [ $? -ne 1 ];then
                echo "disable ${i}"
                systemctl disable ${i}
                logtext "Disable the unused software:$i, you can use systemctl enable ${i} to enable it..."
            fi
        fi
    done
}


rhel6_dis()
{
    needStopSer=$UNUSED_SOFTWARE_VALUE
    for i in $needStopSer
    do
        if [ -e /etc/init.d/$i ];then
            chkconfig ${i} off
            service ${i} stop
            logtext "Disable the unused software:$i, you can use chkconfig ${i} on to enable it..."
        #else
            #echo "This system has no $i service"
        fi
    done
}

#---------------------------------------------------------------------------------------------------#

if [ $DISABLE_UNUSED_SOFTWARE -eq 1 ]; then

    case ${OS_ID} in
        "\"centos\"" | "centos" |"CentOS" | "\"CentOS\"" | "\"rhel\"" | "rhel" | "\"redhat\"" | "redhat" | "\"bclinux\"" | "bclinux" | "\"BCLinux\"" | "BCLinux" | "\"openEuler\"")
            case ${OS_DISTRO} in
                "\"7\"" | "7" |"8" | "\"8\"")
                #disable the el7 unused software
                rhel78_dis
                logtext "This is RHEL system, disable the unused software..."
                Display --indent 2 --text "- Disable the ${OS_ID}-${OS_DISTRO} unused software... " --result FINISHED --color GREEN
                ;;
	        "\"20.09\"" |"20.12" | "21.10" | "22.10")
		rhel78_dis
		logtext "This is openEuler bclinux system, disable the unused software..."
		Display --indent 2 --text "- Disable the ${OS_ID}-${OS_DISTRO} unused software... " --result FINISHED --color GREEN
		;;
                "\"6\"" | "6")
                #disable the el7 unused software
                rhel6_dis
                logtext "This is RHEL6 system, disable the unused software..."
                Display --indent 2 --text "- Disable the ${OS_ID}-${OS_DISTRO} unused software... " --result FINISHED --color GREEN
                ;;
                *)
                logtext "Detected this system is  ${OS_ID}-${OS_DISTRO}"
                Display --indent 2 --text "- We do not support ${OS_ID}-${OS_DISTRO} at this moment... " --result WARNING --color RED
            esac
        ;;
        *)
            logtext "This is not RHEL Distro, we do not support ${OS_ID}-${OS_DISTRO} at this moment"
            Display --indent 2 --text "- We do not support ${OS_ID}-${OS_DISTRO} at this moment... " --result WARNING --color RED
    esac

else

    Display --indent 2 --text "- Skip disable unused software due to config file... " --result SKIPPING --color YELLOW

fi