uavcan_add_vcan 819 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
  4. #
  5. HELP="Initializes and brings up a virtual CAN interface.
  6. Usage:
  7. `basename $0` <iface-name>
  8. Example:
  9. `basename $0` vcan0"
  10. function die() { echo $@ >&2; exit 1; }
  11. if [ "$1" == '--help' ] || [ "$1" == '-h' ]; then echo "$HELP"; exit; fi
  12. [ -n "$1" ] || die "Invalid usage. Use --help to get help."
  13. [ "$(id -u)" == "0" ] || die "Must be root"
  14. # ---------------------------------------------------------
  15. IFACE="$1"
  16. if [ $(ifconfig -a | grep -c "^$IFACE") -eq "1" ]; then
  17. ifconfig $IFACE up
  18. exit
  19. fi
  20. modprobe can
  21. modprobe can_raw
  22. modprobe can_bcm
  23. modprobe vcan
  24. ip link add dev $IFACE type vcan
  25. ip link set up $IFACE
  26. ifconfig $IFACE up || exit 1
  27. echo "New iface $IFACE added successfully. To delete: ip link delete $IFACE"