From b0730d8463b5cf63be0b697534ac5270cac897cd Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Thu, 7 Jul 2016 14:30:26 +0200 Subject: [PATCH] [enh] defaulting running hook_exec as root --- src/yunohost/hook.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/yunohost/hook.py b/src/yunohost/hook.py index 137232ed3..6bf515931 100644 --- a/src/yunohost/hook.py +++ b/src/yunohost/hook.py @@ -292,7 +292,7 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None, def hook_exec(path, args=None, raise_on_error=False, no_trace=False, - chdir=None, env=None): + chdir=None, env=None, user=None): """ Execute hook from a file with arguments @@ -303,6 +303,7 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False, no_trace -- Do not print each command that will be executed chdir -- The directory from where the script will be executed env -- Dictionnary of environment variables to export + user -- User with which to run the command """ from moulinette.utils.process import call_async_output @@ -327,7 +328,11 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False, cmd_script = path # Construct command to execute - command = ['sudo', '-n', '-u', 'admin', '-H', 'sh', '-c'] + if user is not None: + command = ['sudo', '-n', '-u', user, '-H', 'sh', '-c'] + else: + command = ['sh', '-c'] + if no_trace: cmd = '/bin/bash "{script}" {args}' else: