#!/bin/bash

function mount_bootcount() {
	mkdir -p /mnt/bootcount
	mount -t vfat /dev/nanda /mnt/bootcount
}

function unmount_bootcount() {
	umount /dev/nanda
	rm -rf /mnt/bootcount
}

function set_bootcount() {
	echo $1 > /mnt/bootcount/bootcnt.txt
}

function do_reset() {
	mount_bootcount
	set_bootcount 3
	unmount_bootcount
	reboot
}

read -r -p "Are you sure? [y/N] " confirm
case "$confirm" in
    [yY][eE][sS]|[yY])
		echo -e "Performing reset. The system will now reboot.\nDO NOT UNPLUG THE BASH BUNNY BEFORE THIS PROCESS HAS COMPLETED"
        do_reset
        ;;
    *)
        exit
        ;;
esac