#!/bin/sh


locale_echo()
{
    lang_l=`echo $LANG|awk -F"." '{print $1}'`
    if [ x"$lang_l" == x"" ];then
        echo $1
        return
    fi
    lang_f="/usr/share/libkylin-activation/locale/"$lang_l
    if [ ! -f $lang_f ];then
        echo $1
        return
    fi

    est=`grep "^$1==" $lang_f|head -1|awk -F"==" '{print $2}'`
    if [ x"$est" != x"" ];then
        echo "$est"
	else
        echo $1
    fi

}


if [[ $1 = "--help" ]] || [[ $1 = "-h" ]]
then
    locale_echo "Usage: kylin-system-verify"
    locale_echo "This program is used to system verify!"
    exit 0
fi

user=$(whoami)

if [ $user != "root" ]; then
	locale_echo "Please use sudo or switch to the root user to execute the program"
	exit 1;
fi

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

	echo ""
	locale_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 file has no valid service serial number"
	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 file has no valid service serial number"
	fi
else
	stay_message "No LICENSE file"
fi
