Update github.com git:// SRC_URIs
[AGL/meta-agl-demo.git] / recipes-apis / agl-service-can-low-level / files / can-dev-mapping-helper.sh
1 #!/bin/bash
2
3 #
4 # Script to bring up CAN interfaces configured in /etc/dev-mapping.conf
5 # as vcan interfaces if no physical interface is present.
6 #
7
8 vcan_up() {
9     if [ -n "$1" ]; then
10         echo "Bringing up $1 as virtual CAN device"
11         ip link add dev $1 type vcan
12         ip link set up $1
13     fi
14 }
15
16 if [ ! -f /etc/dev-mapping.conf ]; then
17     exit 0
18 fi
19
20 hs=$(grep ^hs= /etc/dev-mapping.conf |cut -d= -f2 |tr -d '"')
21 ls=$(grep ^ls= /etc/dev-mapping.conf |cut -d= -f2 |tr -d '"')
22
23 if [ -n "$hs" ]; then
24     echo "Checking $hs"
25     if ! ifconfig $hs >/dev/null 2>&1; then
26         vcan_up $hs
27     fi
28 fi
29 if [ -n "$ls" -a "$ls" != "$hs" ]; then
30     echo "Checking $ls"
31     if ! ifconfig $ls >/dev/null 2>&1; then
32         vcan_up $ls
33     fi
34 fi
35
36 exit 0