#!/bin/sh

user=$(whoami)

if [ $user != "root" ]; then
	echo "请使用sudo或切换到root用户执行该程序"
	exit 1;
fi

stay_message() {
	msg="${1}"

	echo ""
	echo $msg
	while true
	do
		sleep 100
	done
}

if [ -f /etc/LICENSE ]; then
	grep -q "^SERIAL:[0-9][0-9]*$" /etc/LICENSE || stay_message "LICENSE文件无有效服务序列号"
	SERIAL_NO=$(grep "^SERIAL:[0-9][0-9]*$" /etc/LICENSE | head -n 1 | awk -F":" '{print $2}')
	SERIAL_LENGTH=${#SERIAL_NO}
	if [ $SERIAL_LENGTH -eq "6" ]; then
		/usr/bin/kylin-system-verify-legacy
	elif [ $SERIAL_LENGTH -gt "7" ]; then
		/usr/bin/kylin-system-verify-legacy
	elif [ $SERIAL_LENGTH -eq "7" ]; then
		/usr/bin/kylin-system-verify-new
	else
		stay_message "LICENSE文件无有效服务序列号"
	fi
else
	stay_message "无LICENSE文件"
fi
