summaryrefslogtreecommitdiffstats
path: root/usr/lib/autowifi/opt/udhcpc.run
blob: 2e1b919f1d707fdb88933870b5aa3aff29828a30 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# shamelessly stolen from http://www.doit.org/udhcpc/S50default

PATH=/bin:/usr/bin:/sbin:/usr/sbin

RESOLV_CONF="/etc/resolv.conf"

update_interface()
{
  [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
  [ -n "$subnet" ] && NETMASK="netmask $subnet"
  ifconfig $interface $ip $BROADCAST $NETMASK
}

update_routes()
{
  if [ -n "$router" ]
  then
    echo "deleting routes"
    while route del default gw 0.0.0.0 dev $interface
    do :
    done

    for i in $router
    do
      route add default gw $i dev $interface
    done
  fi
}

update_dns()
{
  echo -n > $RESOLV_CONF
  [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
  for i in $dns
  do
    echo adding dns $i
    echo nameserver $i >> $RESOLV_CONF
  done
}

deconfig()
{
  ifconfig $interface 0.0.0.0
}

case "$1" in
  bound)
    update_interface;
    update_routes;
    update_dns;
  ;;

  renew)
    update_interface;
    update_routes;
    update_dns;
  ;;

  deconfig)
    deconfig;
  ;;

  *)
    echo "Usage: $0 {bound|renew|deconfig}"
    exit 1
    ;;
esac

exit 0