summaryrefslogtreecommitdiffstats
path: root/usr/lib/autowifi/lib/network
blob: a0105120d97a2dc47aa4610202277c188b8189e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
}