#!/bin/sh
# Support an "extras" mtd partition, mount it and run a hook script from
# it.

mtddev() {
	grep "$1" /proc/mtd | cut -d: -f 1 | sed 's/mtd/\/dev\/mtdblock/'
}

mtd_device=$(mtddev extras)
mountpoint=/mnt/mtd_extras

if [ -n "$mtd_device" ]; then
	if [ ! -d $mountpoint ]; then
		mkdir $mountpoint
	fi
	if mount $mtd_device $mountpoint; then
		if [ -e $mountpoint/hook.sh ]; then
			cd $mountpoint
			./hook.sh
			umount $mountpoint 2>/dev/null || true
		fi
	fi
fi
