-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-dev.sh
48 lines (43 loc) · 894 Bytes
/
init-dev.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Default values
DEV="can0"
BITRATE=125000
# Help message
function print_help {
echo "Usage: $0 [-d device] [-b bitrate]"
echo "Options:"
echo " -d device Specify the CAN device (default: can0)"
echo " -b bitrate Specify the bitrate (default: 125000)"
exit 1
}
# Parse command-line arguments
while getopts "d:b:h" opt; do
case ${opt} in
d )
DEV=$OPTARG
;;
b )
BITRATE=$OPTARG
;;
h )
print_help
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
print_help
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
print_help
;;
esac
done
shift $((OPTIND -1))
# Check if device exists
if ! ip link show $DEV > /dev/null 2>&1; then
echo "Device $DEV does not exist"
exit 1
fi
# Set up device
ip link set $DEV type can bitrate $BITRATE
ifconfig $DEV up