#!/bin/sh

prefix=/usr

echo "Creating /newroot"
mkdir -p /newroot || exit 1

echo "Mounting /newroot to tempfs"
if ! awk '$2 == "/newroot" && $3 == "tmpfs" { found=1 } END { exit found ? 0 : 1 }' /proc/mounts; then
	mount -t tmpfs tmpfs /newroot || exit 1
fi

if [ -e /tmp/backup_flash.tar.gz ]; then
	echo "Moving /tmp/backup_flash.tar.gz to /newroot"
	mv /tmp/backup_flash.tar.gz /newroot/
fi

echo "Copying ofgwrite_bin to /newroot"
cp -p $prefix/bin/ofgwrite_bin /newroot/ || exit 1

echo "Calling /newroot/ofgwrite_bin $@"
exec /newroot/ofgwrite_bin "$@"
