#!/bin/bash
set -e

retcode=0

echo $@

#tests
if [ $2 == 0 ]; then
    sleep 60
    getstates
    if getstates | egrep -q "CALLS:[1-9]"; then
        echo "error: still calls active"
        retcode=1
    fi
fi

#restore
sudo cp ${1}/config.lua.org /data/config.lua

sudo omgrestart 2>/dev/null >/dev/null
sleep 60

exit $retcode