#!/bin/bash
declare -i K
declare -i F
declare -i G
declare -i H
K=0
F=0
G=0
H=0

function test()
{
	osinfo=`cat /etc/os-release|grep -w VERSION_ID`
	if [[ $osinfo =~ "v10.1" ]]
	then
		for line in `systemctl list-unit-files|grep "enabled         enabled"|grep -v -i -E @|awk '{print $1}'`
		do
			out=`systemctl status $line  |sed -n '2p'|cut -d \( -f 2|cut -d \; -f 1`
			restult=`ls -l $out |awk -F " " '{print $3}'`
			cap=`ls -l $out |awk -F " " '{print $1}'`
			out1=${cap:0-3}
			if [[ $out1 =~ "w" ]]
			then
				let G+=1
			elif [[ $restult = "root" ]]
			then
				let F+=1
			else
				let G+=1
			fi
		done
		let total=F+G
		let right=F
		let wrong=G
		if [ $right -eq $total ]
		then
			echo 0
		else	
			echo 1
		fi 
	else	
		for line in `systemctl list-unit-files|grep "enabled"|grep -v -i -E @|awk '{print $1}'`
        	do
			out=`systemctl status $line  |sed -n '2p'|cut -d \( -f 2|cut -d \; -f 1`
			restult=`ls -l $out |awk -F " " '{print $3}'`
			cap=`ls -l $out |awk -F " " '{print $1}'`
			out1=${cap:0-3}
			if [[ $out1 =~ "w" ]]
			then
				 let G+=1
				 
			elif [[ $restult = "root" ]]
			then
				let F+=1
			else
				let G+=1
			fi
        	done
		let total=F+G
		let right=F
		let wrong=G
		if [ $right -eq $total ]
		then
			echo 0
		else
			echo 1
		fi
	fi


}
test
