#!/bin/sh

# Check if user has "Always ask" for data roaming
# and reset data roaming to "Not allowed" for the
# inserted SIM.
# Try 5 times with 15 sec sleep in between (because
# sim pin input might block this).

XDG_CONFIG_HOME=${XDG_CONFIG_HOME:="$HOME/.config"}

RC=1
grep -q "askForRoaming=true" "$XDG_CONFIG_HOME/nemomobile/connectionagent.conf"
RC=$?

if [ "$RC" -ne "0" ]; then
  exit 0;
fi

for (( i=1; i <= 5; i++ ))
do

  RC=1
  /bin/dbus-send --system --print-reply --dest=org.ofono /ril_0 org.ofono.ConnectionManager.GetProperties
  RC=$?

  if [ "$RC" -eq "0" ]; then
    sed -i '/askForRoaming=true/d' "$XDG_CONFIG_HOME/nemomobile/connectionagent.conf" && \
    /bin/dbus-send --system --print-reply --dest=org.ofono /ril_0 org.ofono.ConnectionManager.SetProperty string:"RoamingAllowed" variant:boolean:false

    exit 0
  fi

  sleep 15
done

exit 1


