#!/bin/bash

if [ ! -e .config ]; then
	echo No .config here
	exit -1
fi

if [ "$1" = "" ]; then
	echo Specify a config option
	exit -1
fi

CONFIG_VALUE=y
if [ "$2" != "" ]; then
	CONFIG_VALUE=$2
fi

cp .config config-orig

echo $1 | grep -q =
if [ $? -ne 0 ]; then
	echo "$1=$CONFIG_VALUE" >> .config
	yes '' | make $MAKE_OPTIONS oldconfig > /dev/null
	TEST=`grep "^$1=$CONFIG_VALUE$" .config`
	if [ "$TEST" = "" ]; then
		echo ERROR: Failed to set config option
		exit -1
	fi
else
	echo "$1" >> .config
	yes '' | make $MAKE_OPTIONS oldconfig > /dev/null
	TEST=`grep "^$1$" .config`
	if [ "$TEST" = "" ]; then
		echo ERROR: Failed to set config option
		exit -1
	fi
fi

exit 0
