From 59ff04775c1e92d15b0260e4941e8b00091874d6 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Sat, 19 Oct 2024 11:42:57 +0200 Subject: [PATCH] fixed sudo permission for some commands --- .github/wiki/script-auto-config-linux.sh | 2 +- .../easy_computer_manager/computer/__init__.py | 3 +++ custom_components/easy_computer_manager/const.py | 12 ++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/wiki/script-auto-config-linux.sh b/.github/wiki/script-auto-config-linux.sh index 3d19622..99cdaad 100644 --- a/.github/wiki/script-auto-config-linux.sh +++ b/.github/wiki/script-auto-config-linux.sh @@ -32,7 +32,7 @@ fi # Configure sudoers print_colored "$COLOR_BLUE" "Configuring sudoers..." echo -e "\n# Allow your user to execute specific commands without a password (for EasyComputerManager/HA)" | sudo tee -a /etc/sudoers > /dev/null -echo "$USER_BEHIND_SUDO ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/sbin/pm-suspend, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot, /usr/bin/cat /etc/grub2.cfg, /usr/bin/cat /etc/grub.cfg" | sudo tee -a /etc/sudoers > /dev/null +echo "$USER_BEHIND_SUDO ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/init, /usr/sbin/pm-suspend, /usr/sbin/grub-reboot, /usr/sbin/grub2-reboot, /usr/bin/cat /etc/grub2.cfg, /usr/bin/cat /etc/grub.cfg, /usr/bin/systemctl poweroff, /usr/bin/systemctl reboot, /usr/bin/systemctl suspend" | sudo tee -a /etc/sudoers > /dev/null print_colored "$COLOR_GREEN" "Sudoers file configured successfully." # Firewall Configuration diff --git a/custom_components/easy_computer_manager/computer/__init__.py b/custom_components/easy_computer_manager/computer/__init__.py index f91d18e..d8a3ea9 100644 --- a/custom_components/easy_computer_manager/computer/__init__.py +++ b/custom_components/easy_computer_manager/computer/__init__.py @@ -223,6 +223,9 @@ class Computer: return command_result else: LOGGER.debug(f"Command failed (raise: {raise_on_error}) : {command}") + # LOGGER.debug(f"Output: {command_result.output}") + # LOGGER.debug(f"Error: {command_result.error}") + if raise_on_error: raise ValueError(f"Command failed: {command}") diff --git a/custom_components/easy_computer_manager/const.py b/custom_components/easy_computer_manager/const.py index dde3f47..c7421bb 100644 --- a/custom_components/easy_computer_manager/const.py +++ b/custom_components/easy_computer_manager/const.py @@ -27,23 +27,23 @@ ACTIONS = { }, "shutdown": { "windows": ["shutdown /s /t 0", "wmic os where Primary=TRUE call Shutdown"], - "linux": ["sudo shutdown -h now", "sudo init 0", "systemctl poweroff"] + "linux": ["sudo /sbin/shutdown -h now", "sudo /sbin/init 0", "sudo /usr/bin/systemctl poweroff"] }, "restart": { "windows": ["shutdown /r /t 0", "wmic os where Primary=TRUE call Reboot"], - "linux": ["sudo shutdown -r now", "sudo init 6", "systemctl reboot"] + "linux": ["sudo /sbin/shutdown -r now", "sudo /sbin/init 6", "sudo /usr/bin/systemctl reboot"] }, "sleep": { "windows": ["shutdown /h /t 0", "rundll32.exe powrprof.dll,SetSuspendState Sleep"], - "linux": ["systemctl suspend", "sudo pm-suspend"] + "linux": ["sudo /usr/bin/systemctl suspend", "sudo /usr/sbin/pm-suspend"] }, "get_windows_entry_grub": { - "linux": ["sudo cat /etc/grub2.cfg | awk -F \"'\" '/windows/ {print $2}'", - "sudo cat /etc/grub.cfg | awk -F \"'\" '/windows/ {print $2}'"] + "linux": ["sudo /usr/bin/cat /etc/grub2.cfg | awk -F \"'\" '/windows/ {print $2}'", + "sudo /usr/bin/cat /etc/grub.cfg | awk -F \"'\" '/windows/ {print $2}'"] }, "set_grub_entry": { "linux": { - "commands": ["sudo grub-reboot %grub-entry%", "sudo grub2-reboot %grub-entry%"], + "commands": ["sudo /usr/sbin/grub-reboot %grub-entry%", "sudo /usr/sbin/grub2-reboot %grub-entry%"], "params": ["grub-entry"], } },