diff --git a/ovos_PHAL_plugin_system/__init__.py b/ovos_PHAL_plugin_system/__init__.py index 6552865..91e1642 100644 --- a/ovos_PHAL_plugin_system/__init__.py +++ b/ovos_PHAL_plugin_system/__init__.py @@ -85,6 +85,10 @@ def use_external_factory_reset(self): return True return external_requested or False + @property + def use_sudo_for_power(self) -> bool: + return self.config.get("use_sudo_for_power", True) + def handle_reset_register(self, message): if not message.data.get("skill_id"): LOG.warning(f"Got registration request without a `skill_id`: " @@ -230,7 +234,10 @@ def handle_reboot_request(self, message): if script and os.path.isfile(script): subprocess.call(script, shell=True) else: - subprocess.call("systemctl reboot -i", shell=True) + command = "systemctl reboot -i" + if self.use_sudo_for_power: + command = f"sudo {command}" + subprocess.call(command, shell=True) def handle_shutdown_request(self, message): """ @@ -245,7 +252,10 @@ def handle_shutdown_request(self, message): if script and os.path.isfile(script): subprocess.call(script, shell=True) else: - subprocess.call("systemctl poweroff -i", shell=True) + command = "systemctl poweroff -i" + if self.use_sudo_for_power: + command = f"sudo {command}" + subprocess.call(command, shell=True) def handle_configure_language_request(self, message): language_code = message.data.get('language_code', "en_US")