#!/bin/sh

source /etc/utils/shell-utils.sh
DEBUG=0

log "[IM][system init] [+] start execution"

${SPLASH} prg 10
${SPLASH} clear_log
${SPLASH} log "Init UserFS..."

# UserFS
get_flash_type type
[ "$type" == "nand" ] && tmp="ubifs /dev/ubi0_4" || tmp="ext4 /dev/block/mmc0/by-name/Userfs"
mount -t $tmp /mnt/Userfs
if [ "$?" != "0" ] ; then
    /usr/local/share/app/bin/reset_userfs.sh
fi
if [ ! -d /mnt/Userfs/data ] ; then
    mkdir -p /mnt/Userfs/data
fi

if [ "$type" == "nand" ]; then
  result=1
    numb=`ubinfo /dev/ubi0 -N vendor | grep "Volume ID:" | awk '{print $3}'`

    if [ "$numb" == "" ]; then
    ubimkvol -N vendor -s 5079040 -t dynamic /dev/ubi0
    numb=`ubinfo /dev/ubi0 -N vendor | grep "Volume ID:" | awk '{print $3}'`
    fi
    if [ "$numb" != "" ]; then
        [ ! -d /mnt/vendor ] && mkdir -p /mnt/vendor
        mount -t ubifs /dev/ubi0_$numb /mnt/vendor
    result=$?
  fi
  if [ "$result" != "0" ]; then
    log "[IM][system init][i] Unable to mount vendor partition."
  fi
fi
