#!/bin/sh

if [ ! -f /usr/local/bin ]; then
	ln /tmp/sys/bin /usr/local/bin -s
	ln /tmp/sys/share /usr/share -s
	ln /tmp/sys/firmware /lib/firmware -s
	ln /tmp/sys/modules /lib/modules -s
fi

kv_config=$(cat /proc/version)
kv=${kv_config:14:7}
if [ "$kv" != "5.4.148" ]
then
	chmod 777 /usr/local/bin/upgrade_partition

	/usr/sbin/flash_eraseall /dev/mtd0
	/usr/local/bin/upgrade_partition -p /dev/mtd0 /tmp/sys/bst_release.bin

	/usr/sbin/flash_eraseall /dev/mtd1
	/usr/local/bin/upgrade_partition -p -G /dev/mtd1 /tmp/sys/bld_release.bin

	/usr/sbin/flash_eraseall /dev/mtd3
	/usr/local/bin/upgrade_partition -p -K /dev/mtd3 /tmp/sys/Image

	/usr/local/bin/upgrade_partition -d /tmp/sys/s6lm_pineapple.dtb

	sync
	reboot
	exit 1
fi

rm /tmp/sys/bst_release.bin
rm /tmp/sys/bld_release.bin
rm /tmp/sys/Image
rm /tmp/sys/s6lm_pineapple.dtb

echo $kv
