#!/bin/sh

msg()
{
    echo "`date \"+%Y-%m-%d %H:%M:%S\"`: $*"
}

if [ -n "$USER" ]; then
    if [ "$USER" == "restoredefaults" ]; then
        msg "Running MC-only restoredefaults on partner controller."
        #Apps will die (including RPC), so we won't get a return code. Just let it run.
        rpcsys othermcinner /app/default/restoreDefaults.sh & 

        #Now do the same for this controller. They should reboot at around the same time.
        msg "Running MC-only restoredefaults on this controller."
        /app/default/restoreDefaults.sh

        #No need to manually reboot: restoreDefaults does it when it's done.
    fi
    if [ "$USER" == "restoreusers" ]; then
        msg "Restoring other controller's users to default"
        rpcsys othermcinner /app/default/restoreUserSymmetric.sh >/dev/null 2>&1
        /app/default/restoreUserSymmetric.sh
        msg "Rebooting now..."
        reboot
    fi
fi

exit
