#!/bin/sh

# Load ipmodule variables
. /opt/gira/share/devicestack/ipmodule-vars

CONDITION_RESULT=0

case "$1" in
  start)
    echo "Checking factory reset condition ... "
    if [ -x "${CHK_FACTRSTCOND_TOOL}" ]
    then
      ${CHK_FACTRSTCOND_TOOL} 2>&1 > /var/log/check-factory-reset.log
      CONDITION_RESULT=$?
    else
      echo -n "(tool not available)"
    fi
    if [ ${CONDITION_RESULT} -eq 1 ]
    then
      echo "Button press sequence detected, executing factory reset."
      ${FACTORY_RESET}
    elif [ ${CONDITION_RESULT} -eq 2 ]
    then
      echo "Factory reset override detected, executing factory reset."
      ${FACTORY_RESET}
    elif [ ${CONDITION_RESULT} -eq 3 ]
    then
      # The configuration-reset script requires a mounted userdata
      echo "Configuration reset override detected, will reset configuration"
      echo "when the userdata is mounted."
      echo "enabled" > ${CONFIGURATION_RESET_FILE}
    else
      echo "No request detected."
    fi
    ;;
  stop)
    ;;
  *)
    echo "Usage: $0 (start|stop)"
    exit 1
esac
exit 0
