summaryrefslogtreecommitdiffstats
path: root/usr/lib/autowifi/lib/network
diff options
context:
space:
mode:
Diffstat (limited to 'usr/lib/autowifi/lib/network')
-rw-r--r--usr/lib/autowifi/lib/network40
1 files changed, 40 insertions, 0 deletions
diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network
new file mode 100644
index 00000000..a0105120
--- /dev/null
+++ b/usr/lib/autowifi/lib/network
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+check_gateway(){
+ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') >/dev/null
+}
+check_internet(){
+ # TODO determine the loader, either wget or curl
+ secret=$(wget -O- http://krebsco.de/secret 2>/dev/null)
+ if [ "$secret" == "1337" ]; then
+ return 0
+ else
+ echo "cannot load secret or secret incorrect" >&2
+ return 1
+ fi
+}
+
+check_bandwidth(){
+ echo $(curl http://www.microsoft.com/africa/4afrika/images/infographic.gif -w "%{speed_download}" -o /dev/null 2>/dev/null | sed 's/\..*//')
+}
+
+ip_start(){
+ : ${interface?interface variable not set} ${1?please provide method to start ip}
+ # usage: method [extra parms]
+ case "$1" in
+ dhcp)
+ if exists dhcpcd; then
+ dhcpcd -x $interface
+ dhcpcd -w -A $interface
+ elif exists dhclient; then
+ dhclient -x $interface
+ dhclient $interface
+ elif exists udhcpc; then
+ PIDFILE=/var/run/udhcpc-${interface}.pid
+ [ -e $PIDFILE ] && kill `cat $PIDFILE` ||:
+ udhcpc -n -p $PIDFILE -i $interface -s \
+ "$root/usr/lib/autowifi/opt/udhcpc.run"
+ fi ;;
+ *) echo "do not know ip starter $1" >&2;;
+ esac
+}