mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Small changes to env prepending in hook_exec
This commit is contained in:
parent
c5d1ef981b
commit
aae59b1d6e
1 changed files with 7 additions and 7 deletions
|
@ -329,18 +329,18 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
else:
|
else:
|
||||||
cmd_script = path
|
cmd_script = path
|
||||||
|
|
||||||
envcli = ''
|
|
||||||
if env is not None:
|
|
||||||
envcli = ' '.join([ '{key}="{val}"'.format(key=key, val=val) for key,val in env.items()])
|
|
||||||
|
|
||||||
# Construct command to execute
|
# Construct command to execute
|
||||||
command = ['sudo', '-n', '-u', 'admin', '-H', 'sh', '-c']
|
command = ['sudo', '-n', '-u', 'admin', '-H', 'sh', '-c']
|
||||||
if no_trace:
|
if no_trace:
|
||||||
cmd = '{envcli} /bin/bash "{script}" {args}'
|
cmd = '/bin/bash "{script}" {args}'
|
||||||
else:
|
else:
|
||||||
# use xtrace on fd 7 which is redirected to stdout
|
# use xtrace on fd 7 which is redirected to stdout
|
||||||
cmd = '{envcli} BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
|
cmd = 'BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
|
||||||
command.append(cmd.format(envcli=envcli, script=cmd_script, args=cmd_args))
|
if env:
|
||||||
|
# prepend environment variables
|
||||||
|
cmd = '{0} {1}'.format(
|
||||||
|
' '.join(['{0}="{1}"'.format(k, v) for k, v in env.items()]), cmd)
|
||||||
|
command.append(cmd.format(script=cmd_script, args=cmd_args))
|
||||||
|
|
||||||
if logger.isEnabledFor(log.DEBUG):
|
if logger.isEnabledFor(log.DEBUG):
|
||||||
logger.info(m18n.n('executing_command', command=' '.join(command)))
|
logger.info(m18n.n('executing_command', command=' '.join(command)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue