summaryrefslogtreecommitdiffstats
path: root/recipes-connectivity/kuksa-val/can-dev-helper/can-dev-helper.sh
blob: ecac5cb73ea56d77cfcbb0fae93cc59427b95c3b (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
#!/bin/bash

#
# Script to bring up CAN interface configured for the kuksa.val
# CAN provider in /etc/kuksa-can-provider/dbc_feeder.ini as vcan
# interfaces if no physical interface is present.
#

vcan_up() {
    if [ -n "$1" ]; then
        echo "Bringing up $1 as virtual CAN device"
        ip link add dev $1 type vcan
        ip link set up $1
    fi
}

CONF=/etc/kuksa-can-provider/config.ini
if [ $# -gt 0 ]; then
    CONF=$1
fi

if [ ! -f $CONF ]; then
    exit 0
fi

# Ideally the parsing would take the "[can]" section into
# account, but this should work for now.
interface=$(sed -nr '/\[can\]/,/\[/{s/^port *= *//p}' $CONF)
if [ -n "$interface" ]; then
    echo "Checking $interface"
    if ! ifconfig $interface >/dev/null 2>&1; then
        vcan_up $interface
    fi
fi

exit 0