#!/bin/sh

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
CONFIG_DIR="/mnt/mtd/Config"

echo  $script_path >> test
PRODUCTION_TEST_MODE=`cat $script_path/ProductionTestMode.ini | ./busybox grep "ProductionTestMode:" | ./busybox grep -v grep | sed 's/ProductionTestMode://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
FEATURE_ID=`cat $script_path/ProductionTestMode.ini | ./busybox grep "FeatureId:" | ./busybox grep -v grep | sed 's/FeatureId://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
setflag()
{
	if [ "$1" = "yes" ]; then
		[ -e "$2" ] || touch $2
	else
		[ -e "$2" ] && rm $2
	fi
}

if [ $? != 0 ]; then
	echo "cann't found ProductionTestMode in config file"
	exit -1
fi
echo "PRODUCTION_TEST_MODE:$PRODUCTION_TEST_MODE FEATURE_ID:$FEATURE_ID"  

echo PRODUCTION_TEST_MODE = $PRODUCTION_TEST_MODE >> test

if [ "$PRODUCTION_TEST_MODE" = "yes" ] ||
	[ "$PRODUCTION_TEST_MODE" = "no" ]
then
	setflag $PRODUCTION_TEST_MODE /mnt/mtd/Config/ProductTestFeatureId
	if [ "$PRODUCTION_TEST_MODE" = "yes" ];then
		if [ ! -d $CONFIG_DIR ]; then
			mkdir $CONFIG_DIR
		fi
	
		echo "PRODUCTION_TEST_MODE:$PRODUCTION_TEST_MODE" >> test
		echo "FeatureId:$FEATURE_ID" > /mnt/mtd/Config/ProductTestFeatureId
	fi
fi