From 892ea0cab20c229de00119ad4474260ac4c6fb81 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 8 Jun 2024 18:46:27 -0700 Subject: [PATCH] Display useful message when Linux post-install script has insufficient permissions The Arduino Boards Manager automatically executes the `post_install.sh` script during installation of the platform on a Linux machine. This platform's post-install script is intended to create a udev rules file that gives write permissions for the USB devices of the platform's boards. These permissions are required in order to upload to the boards. The creation of the udev rules file requires superuser privileges, which are typically not available in the context of the post-install script's execution. The script contains code to check whether the necessary privileges are available. If not, it prints a message and skips the udev rules file creation. Previously the message printed when the udev rules file creation was not possible was "Please run as root". This message was completely meaningless to the user when printed during the Boards Manager installation. Worse, it might cause them to think they must run the Arduino development software as root user, which is a bad idea and also wouldn't result in the udev rules file being created since the installation of the platform to the user's account was already completed. The message is hereby updated to provide a meaningful explanation of the potential problem as well as the specific command the user can run from the terminal to execute the script as superuser. --- post_install.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/post_install.sh b/post_install.sh index b99435e2..632ff6b6 100755 --- a/post_install.sh +++ b/post_install.sh @@ -9,8 +9,19 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", MODE:="0666" EOF } -if [ "$EUID" -ne 0 ] - then echo "Please run as root" +if [ "$EUID" -ne 0 ]; then + if [ -e "${PWD}/post_install.sh" ]; then + 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 + 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