enigma2: 4.3.2r14
[opendreambox.git] / meta-opendreambox / recipes-connectivity / connman / connman / connmand-nfsroot.in
1 #!/bin/sh
2 #
3 # Copyright (c) 2016 Dream Property GmbH, Germany
4 #                    http://www.dream-multimedia-tv.de/
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23
24 parse_cmdline() {
25         local ip=
26         local nfsroot=
27         local root=
28         local options=
29
30         set -- $(cat /proc/cmdline)
31         for arg do
32                 key=${arg%%=*}
33                 if [ "$arg" = "$key" ]; then
34                         val=
35                 else
36                         val=${arg#*=}
37                 fi
38                 case "$key" in
39                         ip)
40                                 ip=${val%%:*}
41                                 ;;
42                         nfsroot)
43                                 nfsroot=$val
44                                 ;;
45                         root)
46                                 root=$val
47                                 ;;
48                 esac
49         done
50
51         if [ "$root" = "/dev/nfs" -o -n "$nfsroot" -a -n "$ip" ]; then
52                 set -- $(ip -4 -o addr show | awk '{print $2}')
53                 for dev do
54                         if ip -o link show $dev | awk '{print $3}' | grep -qvw -e 'LOOPBACK' -e 'NO-CARRIER'; then
55                                 case "$ip" in
56                                         any|bootp|both|dhcp|on|rarp)
57                                                 options="-I $dev $options"
58                                                 ;;
59                                         *)
60                                                 for dev_addr in $(ip -4 -o addr show dev $dev | awk '{print $4}' | grep -o '^[0-9.]\+'); do
61                                                         if [ "$ip" = "$dev_addr" ]; then
62                                                                 options="-I $dev"
63                                                                 break
64                                                         fi
65                                                 done
66                                                 ;;
67                                 esac
68                         fi
69                 done
70         fi
71
72         echo "$options"
73 }
74
75 nfsroot_options() {
76         if [ ! -f /run/connman/nfsroot.env ]; then
77                 mkdir -p /run/connman
78                 parse_cmdline >/run/connman/nfsroot.env
79         fi
80
81         cat /run/connman/nfsroot.env
82 }
83
84 exec "@sbindir@/connmand.real" "$@" $(nfsroot_options)