#!/bin/sh
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Shell script to switch the OS on the Garz & Fricke i.MX platforms using
# the Garz & Fricke xconfig utility
#
# This script expects an configuration file at /etc/switch_os.conf

CONFIG_FILE="/root/switch_os.conf"
XCONFIG="/root/xconfig"

usage() {
	echo "usage: 
$0 CE
    switch to Windows CE
$0 Linux
    switch to Linux"
}

if [ -f ${CONFIG_FILE} ]; then
	. ${CONFIG_FILE}
else
	echo "Error: ${CONFIG_FILE} not found!"
fi

if [ ! -n $1 ]; then
	usage
	exit 1
fi

case $1 in
CE|ce)
	boot_script=${boot_script_ce}
	;;	
Linux|linux)
	boot_script=${boot_script_linux}
	;;	 
*)
	echo "Unrecognized OS: $1"
	exit 1 
esac

echo "switching to $1"

${XCONFIG} addattribute -p /configurationFile/variables/setting\[@key=\'boot_script_data\'\] \
	-n value -v "${boot_script}" 

if [ "$?" -eq 0 ]; then
	echo "Done, Please reboot your system!"
	exit 0
else
	echo "An Error occured..."
	exit 1
fi 