#!/bin/bash
echo "$(date): Connect to Internet..."
ifup --force gprs
sleep 1

x=0
# Wait until connection is established
while ! ping -c 1 -W 1 8.8.8.8 &>/dev/null ; do
  echo "$(date): wait for internet connection to come up" 
  sleep 1 
  if [ $x -gt 60 ]; then
    # Time out here
    echo "$(date): Could not connect to internet (timeout)..."
    exit 1
  fi
  x=$((x+1))
done
/usr/sbin/ntpdate 3.de.pool.ntp.org
echo "$(date): Connected to Internet...- IP: $(/home/pi/root-bin/get_internet_ip)"
