#!/bin/sh

ubootcfg=/config/u-boot/u-boot.cfg
upgradedir=/config/upgrade
root=$1

partitions=`ubinfo -a  |grep Name: | sed -e 's%Name: *%%'`
found=NO

for p in $partitions; do
	if [ "$p" = "$root" ]; then
		found=YES;
		break;
	else
		continue;
	fi;
done

if [ "$found" = "YES" ]; then
	echo Partition $root found ...
	#cat $ubootcfg | sed -e 's%^root=.*$%root='$root'%' > $ubootcfg.new
	cat $ubootcfg | grep -v '^root=' | grep -v '^$' > $ubootcfg.new
	echo "root="$root >> $ubootcfg.new
	mv $ubootcfg.new $ubootcfg
	sync
	echo Booting into it on next reboot
	mkdir -p $upgradedir
	return 0
else
	echo partition $root not found, aborting
	return 1
fi

