connman: add patch to create read-only device when using nfsroot
[opendreambox.git] / meta-opendreambox / recipes-connectivity / connman / connman / connmand-env
1 #!/bin/sh
2
3 ip=
4 nfsroot=
5 root=
6
7 set -- $(cat /proc/cmdline)
8 for arg do
9         key=${arg%%=*}
10         if [ "$arg" = "$key" ]; then
11                 val=
12         else
13                 val=${arg#*=}
14         fi
15         case "$key" in
16                 ip)
17                         ip=${val%%:*}
18                         ;;
19                 nfsroot)
20                         nfsroot=$val
21                         ;;
22                 root)
23                         root=$val
24                         ;;
25         esac
26 done
27
28 options=
29
30 if [ "$root" = "/dev/nfs" -o -n "$nfsroot" -a -n "$ip" ]; then
31         set -- $(ip -4 -o addr show | awk '{print $2}' | grep -v '^lo$')
32         for dev do
33                 case "$ip" in
34                         any|bootp|both|dhcp|on|rarp)
35                                 options="-I $dev $options"
36                                 ;;
37                         *)
38                                 dev_addr=`ip -4 -o addr show $dev | awk '{print $4}' | grep -o '^[0-9.]\+'`
39                                 if [ "$ip" = "$dev_addr" ]; then
40                                         options="-I $dev"
41                                         break
42                                 fi
43                                 ;;
44                 esac
45         done
46 fi
47
48 [ -d /run/connmand ] || mkdir -p /run/connmand
49 echo "CONNMAND_OPTS=$options" >/run/connmand/connmand.env