Skip to content

Commit

Permalink
Resolve power permissions issues
Browse files Browse the repository at this point in the history
Add configuration option to use `sudo` with power commands
  • Loading branch information
NeonDaniel committed Oct 18, 2024
1 parent 99f68fa commit 81e8ade
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ovos_PHAL_plugin_system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def use_external_factory_reset(self):
return True
return external_requested or False

@property
def sudo_power(self) -> bool:
return self.config.get("use_sudo_for_power") is False

def handle_reset_register(self, message):
if not message.data.get("skill_id"):
LOG.warning(f"Got registration request without a `skill_id`: "
Expand Down Expand Up @@ -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.sudo_power:
command = f"sudo {command}"
subprocess.call(command, shell=True)

def handle_shutdown_request(self, message):
"""
Expand All @@ -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.sudo_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")
Expand Down

0 comments on commit 81e8ade

Please sign in to comment.