#!/bin/bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 set -euo pipefail BUS_COUNT=1 parse_args() { while [ "$#" -gt 0 ]; do case $1 in --bus-count) BUS_COUNT=$2 shift ;; --help) echo "Usage: $0 [OPTION]" echo " --bus-count Number of CAN buses" exit 0 ;; esac shift done } parse_args "$@" if ! command -v cansend > /dev/null; then # Install packages apt update && apt install -y can-utils fi # For EC2, the SocketCAN modules vcan and can-gw are included in a separate package: if uname -r | grep -q aws; then apt update && apt install -y linux-modules-extra-aws fi # Install can-isotp kernel module if not installed # can-isotp module is part of the mainline Linux kernel since version 5.10 MODULE="can_isotp" echo "Installing kernel module: $MODULE" if modinfo $MODULE &> /dev/null ; then echo "$MODULE is already in system. There is no need to install it." else apt update && apt install -y build-essential dkms git git clone https://github.com/hartkopp/can-isotp.git cd can-isotp git checkout beb4650660179963a8ed5b5cbf2085cc1b34f608 cd .. if [ -d /usr/src/can-isotp-1.0 ]; then dkms remove can-isotp/1.0 --all rm -rf /usr/src/can-isotp-1.0 fi mv can-isotp /usr/src/can-isotp-1.0 sed -e s/else// -e s/shell\ uname\ \-r/KERNELRELEASE/ -i /usr/src/can-isotp-1.0/Makefile cat > /usr/src/can-isotp-1.0/dkms.conf < /etc/modules-load.d/can.conf # Install setup-socketcan for ((i=0; i<${BUS_COUNT}; i++)); do printf "ip link add dev vcan${i} type vcan; ip link set up vcan${i}\n" \ >> /usr/local/bin/setup-socketcan.sh done cat > /lib/systemd/system/setup-socketcan.service <