#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications

do_mount_root() {
	mount_root
	boot_run_hook preinit_mount_root
	[ -f /sysupgrade.tgz ] && {
		echo "- config restore -"
		cd /
		echo "clean /etc/rc.d/ from /rom/"
		rm -rf /etc/rc.d/*
		echo "restore backup"
		mv sysupgrade.tgz /tmp
		tar xzf /tmp/sysupgrade.tgz
		rm -f /tmp/sysupgrade.tgz
		echo "clean old uci-defaults"
		mkdir -p /tmp/sysupgrade/
		cp -f /etc/uci-defaults/ingeversion* /tmp/sysupgrade/
		cp -f /etc/uci-defaults/lince* /tmp/sysupgrade/
		rm -rf /etc/uci-defaults/*
		cp /tmp/sysupgrade/* /etc/uci-defaults/
		sync
	}
}

[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root
