#!/bin/sh

clear

USER=$1
shift

[ "$1" = "--auto" ] && AUTO=true

echo You are about to restore this unit to factory settings.
echo All user data will be lost!
echo
echo -n "Enter 'yes' to continue: "

read INPUT

if [ "$INPUT" != "yes" ]; then
    if [ -n $AUTO ]; then
        mount -tproc proc /proc
        mount $USER /mnt
        rm -f /mnt/.autoformat
        umount /mnt
        umount /proc
    fi

    /sbin/busybox.asus reboot -f
fi

echo -n "Formatting user partition, please wait... "

mount -tproc proc /proc
/sbin/mkfs.ext3 -q -L USER $USER

echo "done!"
echo

if [ -z $AUTO ]; then
    umount /proc
    echo "Press <ENTER> to reboot..."
    read
    /sbin/busybox.asus reboot -f
else
    echo "Press <ENTER> to shutdown..."
    read
    echo 5 > /proc/acpi/sleep
fi
