-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcan0_setup_deb11.sh
More file actions
executable file
·72 lines (65 loc) · 2.36 KB
/
can0_setup_deb11.sh
File metadata and controls
executable file
·72 lines (65 loc) · 2.36 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# ------------------------------------------------------------------------------
# Script Name: setup_can0.sh
#
# Description:
# This script configures the CAN0 (Controller Area Network) interface on a Linux
# system by creating a static network configuration file. It ensures safe setup
# by backing up any existing configuration and writing a new one with predefined
# parameters. The script must be run with root privileges.
#
# Functionality:
# 1. Verifies that the script is executed with elevated (root) privileges.
# 2. Checks for an existing CAN0 configuration file.
# 3. If found, backs up the original file to preserve previous settings.
# 4. Writes a new CAN0 configuration with:
# - Static interface setup
# - Bitrate of 500000
# - TX queue length of 1024
# 5. Provides clear status messages for each step.
#
# Variables:
# CAN_FILE - Path to the CAN0 network configuration file.
# BACKUP_FILE - Path to store the backup of the original CAN0 configuration.
#
# Usage:
# Run this script using sudo:
# sudo ./setup_can0.sh
#
# Notes:
# - Designed for Debian-based systems using /etc/network/interfaces.d/
# - Requires root access to modify network configuration files.
#
# Author: SilentWoof [GitHub: https://github.com/SilentWoof]
# ------------------------------------------------------------------------------
# setup_can0.sh - Configure CAN0 interface on Linux
CAN_FILE="/etc/network/interfaces.d/can0"
BACKUP_FILE="/etc/network/interfaces.d/can0.original"
# ✅ Check for root privileges
if [ "$EUID" -ne 0 ]; then
echo "❌ This script must be run with elevated privileges."
echo "🔁 Please rerun it using: sudo ./setup_can0.sh"
exit 1
fi
# 📦 Backup existing can0 file if it exists
if [ -f "$CAN_FILE" ]; then
echo "🔄 Existing can0 file found. Attempting backup..."
if ! mv "$CAN_FILE" "$BACKUP_FILE"; then
echo "❗ Failed to back up $CAN_FILE. Check permissions."
exit 2
fi
echo "✅ Backup successful."
fi
# ✍️ Create new can0 configuration
echo "🛠 Creating new CAN0 configuration..."
if ! cat <<EOF > "$CAN_FILE"
auto can0
iface can0 can static
bitrate 500000
up ifconfig \$IFACE txqueuelen 1024
EOF
then
echo "❗ Error writing to $CAN_FILE. Check permissions or disk space."
exit 3
fi
echo "✅ CAN0 interface configuration completed successfully."