Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions post_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

arduino_zephyr_rules () {
cat <<EOF
# Arduino Zephyr rules

# Arduino UNO Q
SUBSYSTEM=="usb", ATTR{idVendor}=="2341", ATTR{idProduct}=="0078", MODE="0666"
Comment on lines +7 to +8
Copy link
Collaborator

@per1234 per1234 Nov 23, 2025

Choose a reason for hiding this comment

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

Suggested change
# Arduino UNO Q
SUBSYSTEM=="usb", ATTR{idVendor}=="2341", ATTR{idProduct}=="0078", MODE="0666"
# Arduino UNO Q
# Operating mode
SUBSYSTEM=="usb", ATTR{idVendor}=="2341", ATTR{idProduct}=="0078", MODE="0666"
# EDL mode
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9008", MODE="0666"

Even though it is not required for the specific use case of uploading a sketch to the board, I think it is worth also adding a rule for the "EDL mode" we put the board in when flashing the Linux operating system image to the board.


EOF
}

OS="$(uname -s)"
case "$OS" in
Linux*)
if [ "$EUID" -ne 0 ]; then
if [ -e "${PWD}/post_install.sh" ]; then
if command -v pkexec > /dev/null 2>&1; then
echo "Requesting root privileges via $PKEXEC..."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
echo "Requesting root privileges via $PKEXEC..."
echo "Requesting root privileges..."

The PKEXEC variable is not defined by the script, and at least on my Ubuntu machine, not defined globally. So the previous command would output:

Requesting root privileges via ...

I don't see any need to surface to the user the exact tool that is being used to request the privileges, so I think the best approach is to reword it as in my suggestion above.

pkexec "${PWD}/post_install.sh"
else
echo
echo "You might need to configure permissions for uploading."
echo "To do so, run the following command from the terminal:"
echo "sudo \"${PWD}/post_install.sh\""
echo
exit
fi
else
# Script was executed from another path. It is assumed this will only occur when user is executing script directly.
# So it is not necessary to provide the command line.
echo "Please run as root"
fi

exit
fi

arduino_zephyr_rules > /etc/udev/rules.d/60-arduino-zephyr.rules

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

;;
esac