Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Linux post install script #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

StarDev-it
Copy link

Added a simple Linux post install script.
This script is useful to set the right UDEV rules in order to deploy/upload the code to Arduino Nano ESP32 from a standard Linux user

@CLAassistant
Copy link

CLAassistant commented Aug 5, 2023

CLA assistant check
All committers have signed the CLA.

@tormodvolden
Copy link

The suggested udev rules are not recommended. Do not use MODE=:"0666" since it is a security liability. Use TAG+="uaccess" to give access to the desktop user.

arduino_esp32_rules () {
echo ""
echo "# Arduino ESP32 bootloader mode udev rules"
echo ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a particularly weird mixture of echo and "here" documents. Simply use one "here" document.

# reload udev rules
echo "Reload rules..."
udevadm trigger
udevadm control --reload-rules

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing EOL on last line. Using a proper text editor avoids this. Unix text files should have a line terminator on every line, including the last line.

@h-b
Copy link

h-b commented Feb 21, 2024

I have successfully implemented the suggested changes (uaccess, EOL, single here doc) and confirmed the script's functionality. As this is my first Arduino project, troubleshooting this issue was particularly challenging due to the increased complexity for beginners. I believe integrating the script would significantly enhance the Arduino setup experience and improve usability for all users.

#!/usr/bin/env bash

# This script creates a udev rule for the Arduino ESP32 bootloader mode
# allowing access without root privileges.

arduino_esp32_rules() {
  echo "# Arduino ESP32 bootloader mode udev rules"
  cat <<EOF  # Use a here document for clean formatting
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0070", TAG+="uaccess"
EOF
}

if [ "$EUID" -ne 0 ]; then
  echo "Please run as root"
  exit
fi

arduino_esp32_rules > /etc/udev/rules.d/60-arduino-esp32.rules

# Reload udev rules
echo "Reload rules..."
udevadm trigger
udevadm control --reload-rules

@tormodvolden
Copy link

There is so much cargo-cult in these scripts, and I don't know where it is started (arduino mbed?).

This is simpler and better IMNSHO:

#!/bin/sh

# This script creates a udev rule for the Arduino ESP32 bootloader mode
# allowing access without root privileges.

if [ ! -w /etc/udev/rules.d ]; then
  echo "Please run as root"
  exit 1
fi

cat << EORULES > /etc/udev/rules.d/60-arduino-esp32.rules
# Arduino ESP32 bootloader mode udev rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0070", TAG+="uaccess"
EORULES

echo "Reloading rules..."
udevadm control --reload-rules

@h-b
Copy link

h-b commented Feb 21, 2024

There is so much cargo-cult in these scripts, and I don't know where it is started (arduino mbed?).

This is simpler and better IMNSHO:

#!/bin/sh

# This script creates a udev rule for the Arduino ESP32 bootloader mode
# allowing access without root privileges.

if [ ! -w /etc/udev/rules.d ]; then
  echo "Please run as root"
  exit 1
fi

cat << EORULES > /etc/udev/rules.d/60-arduino-esp32.rules
# Arduino ESP32 bootloader mode udev rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0070", TAG+="uaccess"
EORULES

echo "Reloading rules..."
udevadm control --reload-rules

Well, I just modified the original script to reflect the comments.

@csarnataro
Copy link

Hi, thanks to this script I was able to successfully configure my Nano ESP32 on Linux.

Unfortunately I'm not an expert in udev rules so I can't comment anything about all the suggestions provided by other reviewers, I can just confirm it's working on my Debian machine.

I think it would be beneficial for other users if this PR got merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants