# Copyright (C) 2015 OpenWrt.org

. /lib/upgrade/common.sh

move_config() {
	local partdev partnum

	case $(board_name) in
	bananapi,bpi-r2)
		partnum=2
		;;
	unielec,u7623-02-emmc-512m)
		if grep -q root=/dev/mmcblk0p2 /proc/cmdline; then
			partnum=1;
		else
			partnum=2;
		fi
		;;
	*)
		return 1
		;;
	esac

	if export_bootdevice && export_partdevice partdev $partnum; then
		insmod nls_cp437
		insmod nls_iso8859-1
		insmod fat
		insmod vfat
		mkdir -p /recovery
		mount -o rw,noatime "/dev/$partdev" -t vfat /recovery
		[ -f "/recovery/$BACKUP_FILE" ] && mv -f "/recovery/$BACKUP_FILE" /
		umount /recovery
	fi
}

boot_hook_add preinit_mount_root move_config
