#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org

START=02

. /lib/functions/userconfig.sh

mount_userconfig() {
	local USERCONFIG_DEVICE=/dev/mtdblock9
	local USERCONFIG_DIR=/tmp/userconfig
	mkdir -p ${USERCONFIG_DIR}
	/usr/sbin/ubiattach -m 9 -d 1 -b 5 /dev/ubi_ctrl
	if [ $? ==0 ]; then
		/bin/mount -t ubifs -o rw /dev/ubi1_0 /tmp/userconfig -o bulk_read -o sync
	else
		/usr/sbin/ubiformat -y -q /dev/mtd9
		/usr/sbin/ubiattach -m 9 -d 1 -b 5 /dev/ubi_ctrl
		/usr/sbin/ubimkvol /dev/ubi1 -m -N user-config
		/bin/mount -t ubifs -o rw /dev/ubi1_0 /tmp/userconfig -o bulk_read -o sync
	fi
	rootfs_init_etc_ramfs
}

start() {
	mount_userconfig
	defFlag=`grep -o Default /tmp/userconfig/userconfig_default.tmp`
	if [ -n "$defFlag" ] && [ $defFlag = 'Default' ];
	then
		#set dftmac from tddp flash
		/usr/bin/tddpd dftmac
		/lib/cfg_save/config.sh save
	else
	   echo "no"
	fi
}