#!/bin/sh
#
# Removes firmware completely from NAND
#

echo "---- Removing firmware -----------------"

echo "stopping anthill services"
/etc/init.d/S71monitor stop
/etc/init.d/S70miner stop

if grep config /proc/mounts; then
	echo "unmounting config partition"
	umount /config
fi

if [ -d /nvdata/anthillos ]; then
	echo "cleaning filesystem"
	rm -rf /nvdata/anthillos
fi

# Remove logs
[ -d /tmp/log/miner ] && rm -rf /tmp/log/miner
[ -d /tmp/log/dashd ] && rm -rf /tmp/log/dashd

if ls "/tmp/log/hwscan*" 1> /dev/null 2>&1; then
    rm "/tmp/log/hwscan*"
fi

sync

echo "firmware successfully removed"
reboot