mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add execution dir in env on hook exec (#293)
* [enh] Add execution dir in env on hook exec * [enh] YNH_EXECUTION_DIR become YNH_CWD * [fix] Hook exec with no env fail * [enh] Remove dead condition
This commit is contained in:
parent
caa63f7022
commit
afe28470c0
1 changed files with 10 additions and 5 deletions
|
@ -326,6 +326,11 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
else:
|
else:
|
||||||
cmd_script = path
|
cmd_script = path
|
||||||
|
|
||||||
|
# Add Execution dir to environment var
|
||||||
|
if env is None:
|
||||||
|
env = {}
|
||||||
|
env['YNH_CWD'] = chdir
|
||||||
|
|
||||||
# Construct command to execute
|
# Construct command to execute
|
||||||
if user == "root":
|
if user == "root":
|
||||||
command = ['sh', '-c']
|
command = ['sh', '-c']
|
||||||
|
@ -337,11 +342,11 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
|
||||||
else:
|
else:
|
||||||
# use xtrace on fd 7 which is redirected to stdout
|
# use xtrace on fd 7 which is redirected to stdout
|
||||||
cmd = 'BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
|
cmd = 'BASH_XTRACEFD=7 /bin/bash -x "{script}" {args} 7>&1'
|
||||||
if env:
|
|
||||||
# prepend environment variables
|
# prepend environment variables
|
||||||
cmd = '{0} {1}'.format(
|
cmd = '{0} {1}'.format(
|
||||||
' '.join(['{0}={1}'.format(k, shell_quote(v)) \
|
' '.join(['{0}={1}'.format(k, shell_quote(v)) \
|
||||||
for k, v in env.items()]), cmd)
|
for k, v in env.items()]), cmd)
|
||||||
command.append(cmd.format(script=cmd_script, args=cmd_args))
|
command.append(cmd.format(script=cmd_script, args=cmd_args))
|
||||||
|
|
||||||
if logger.isEnabledFor(log.DEBUG):
|
if logger.isEnabledFor(log.DEBUG):
|
||||||
|
|
Loading…
Add table
Reference in a new issue