From d9dd012a05ae51264bcf4e91cb1677f3f1b67308 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 30 Mar 2014 18:16:32 +0400 Subject: [PATCH] Added script vcan_init --- libuavcan_drivers/linux/scripts/vcan_init | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 libuavcan_drivers/linux/scripts/vcan_init diff --git a/libuavcan_drivers/linux/scripts/vcan_init b/libuavcan_drivers/linux/scripts/vcan_init new file mode 100755 index 0000000000..047262611e --- /dev/null +++ b/libuavcan_drivers/linux/scripts/vcan_init @@ -0,0 +1,38 @@ +#!/bin/sh +# +# Copyright (C) 2014 Pavel Kirienko +# + +HELP="Initializes and brings up a virtual CAN interface. +Usage: + `basename $0` +Example: + `basename $0` 0" + +function die() { echo $@ >&2; exit 1; } + +if [ "$1" == '--help' ] || [ "$1" == '-h' ]; then echo "$HELP"; exit; fi +[ -n "$1" ] || die "Invalid usage. Use --help to get help." +[ "$(id -u)" == "0" ] || die "Must be root" + +# --------------------------------------------------------- + +IFACE="vcan$1" + +if [ $(ifconfig -a | grep -c "^$IFACE") -eq "1" ]; then + ifconfig $IFACE up + exit +fi + +modprobe can +modprobe can_raw +modprobe can_bcm +modprobe vcan + +ip link add dev $IFACE type vcan +ip link set up $IFACE +ip link show $IFACE + +ifconfig $IFACE up || exit 1 + +echo "New iface $IFACE added successfully. To delete: ip link delete $IFACE"