Last active
September 11, 2024 10:02
-
-
Save JeanElsner/908af1ccceeccabf1df1103b49c10708 to your computer and use it in GitHub Desktop.
Ethercat install script for Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the correct number of arguments are passed | |
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ]; then | |
echo "Usage: $0 <master0_device> [device_modules]" | |
exit 1 | |
fi | |
# Assign command-line arguments to variables | |
master0_device="$1" | |
device_modules="${2:-generic}" | |
echo "Master0 Device: $master0_device" | |
echo "Device Modules: $device_modules" | |
sudo apt-get install -y git cmake build-essential autoconf libtool kmod | |
git clone https://gitlab.com/etherlab.org/ethercat.git | |
cd ethercat || return | |
git checkout stable-1.5 | |
chmod +x bootstrap | |
./bootstrap | |
./configure --disable-8139too --with-linux-dir=/usr/src/linux-headers-"$(uname -r)" | |
make modules | |
sudo make modules_install install | |
sudo depmod | |
echo "Adding ethercat group..." | |
sudo groupadd ethercat | |
sudo usermod -aG ethercat "$(id -un)" | |
echo "Updating ethercat.conf..." | |
sudo sed -i "s/\(MASTER0_DEVICE=\).*/\1\"$master0_device\"/" "/usr/local/etc/ethercat.conf" | |
sudo sed -i "s/\(DEVICE_MODULES=\).*/\1\"$device_modules\"/" "/usr/local/etc/ethercat.conf" | |
limits_path="/etc/security/limits.conf" | |
limits=" | |
@ethercat soft rtprio 99 | |
@ethercat soft priority 99 | |
@ethercat soft memlock 102400 | |
@ethercat hard rtprio 99 | |
@ethercat hard priority 99 | |
@ethercat hard memlock 102400" | |
echo "Adding ethercat group to limits.conf..." | |
if grep -qF "@ethercat" "$limits_path"; then | |
echo "limits.conf already contains ethercat group." | |
else | |
echo "$limits" | sudo tee -a "$limits_path" >/dev/null | |
fi | |
echo "Setting device access permissions..." | |
sudo sh -c 'echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0660\", GROUP=\"ethercat\" > /lib/udev/rules.d/99-EtherCAT.rules' | |
echo "Registering libraries with dynamic linker..." | |
sudo sh -c 'echo /usr/local/lib > /etc/ld.so.conf.d/etherlab.conf' | |
sudo ldconfig | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment