#!/bin/sh

[ -e "/etc/config/ubihealthd" ] && exit 0
[ ! -e "/sys/class/ubi" ] && exit 0

touch  "/etc/config/ubihealthd"

for ubidev in /sys/class/ubi/*/total_eraseblocks; do
	ubidev="${ubidev%/*}"
	ubidev="${ubidev##*/}"
	uci batch <<EOF
set ubihealthd.$ubidev=ubi-device
set ubihealthd.$ubidev.device="/dev/$ubidev"
set ubihealthd.$ubidev.enable=1
EOF
done

uci commit ubihealthd
