From 9894406dad56aea004f56de94a15d72c0fe69ae9 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 10 Jun 2024 02:56:49 -0700 Subject: [PATCH 1/3] 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 9a944e8a..dc2f944a 100644 --- a/post_install.sh +++ b/post_install.sh @@ -14,8 +14,19 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0058", MODE:="066 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 From 6910b5d7f02e6c757393591ea8fff5700aec9303 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 30 Jul 2024 03:04:33 -0700 Subject: [PATCH 2/3] Configure post-install script to only operate when platform installed on Linux machine The Arduino Boards Manager automatically executes the `post_install.sh` script during installation of the platform on a non-Windows machine. The platform's post-install script is Linux-specific, but no provisions were made in the script code for the fact that it is also executed on macOS machines. Previously, this was fairly innocuous because, although misleading, the message printed to the output during the platform installation was short and cryptic and thus easy for the average macOS user to ignore: ``` Configuring platform. Please run as root ``` Since it is important for Linux users to manually run the script and the previous message did not effectively communicate that, the script was recently modified to print helpful instructions during the Boards Manager installation. The fact that the script is also executed on macOS machines was not considered in that work. This meant that, although an improvement for the Linux user experience was accomplished, the macOS user experience was worsened because those users were then presented with more prominent and detailed inappropriate instructions. For example: ``` Configuring platform. You might need to configure permissions for uploading. To do so, run the following command from the terminal: sudo "/Users/per/Library/Arduino15/packages/arduino/hardware/TODO/42.0.0/post_install.sh" ``` The problem is fixed by adjusting the script so that the script simply returns silently if it is invoked on a non-Linux machine. macOS users will now only see the following benign message in the output during the Boards Manager installation: ``` Configuring platform. ``` The POSIX-compliant shell code for determining the operating system the script is running under was derived from the Arduino CLI application's cross-platform installation script, which has withstood the test of time after years of use by a large user base. --- post_install.sh | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/post_install.sh b/post_install.sh index dc2f944a..69da8d9c 100644 --- a/post_install.sh +++ b/post_install.sh @@ -14,26 +14,31 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0058", MODE:="066 EOF } -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 +OS="$(uname -s)" +case "$OS" in +Linux*) + 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 + exit + fi -megaAVR_rules > /etc/udev/rules.d/60-arduino-megaAVR.rules + megaAVR_rules > /etc/udev/rules.d/60-arduino-megaAVR.rules -# reload udev rules -echo "Reload rules..." -udevadm control --reload-rules -udevadm trigger + # reload udev rules + echo "Reload rules..." + udevadm control --reload-rules + udevadm trigger + ;; +esac From ce9d25e80c1aac86a9a650534851e5e1192ffdcd Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 30 Jul 2024 04:11:13 -0700 Subject: [PATCH 3/3] Give post-install script executable file permissions The file permissions were not correctly configured at the time the script was created. --- post_install.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 post_install.sh diff --git a/post_install.sh b/post_install.sh old mode 100644 new mode 100755