Inject a new environment variable YNH_INTERFACE to test inside helpers if we're using Yunohost from the CLI or API

This commit is contained in:
Alexandre Aubin 2019-05-18 18:31:02 +02:00
parent a4f3248545
commit 95d2c8f799
2 changed files with 5 additions and 12 deletions

View file

@ -1,14 +1,5 @@
#!/bin/bash
# Determine whether the scripts is executed from a terminal or the admin JS.
#
# [internal]
ynh_is_term () {
# Return true if $TERM return xterm
# Which means the script is executed from a terminal, not from the admin JS
[[ "$TERM" =~ "xterm" ]]
}
# Manage a fail of the script
#
# [internal]
@ -36,8 +27,8 @@ ynh_exit_properly () {
ynh_print_err --message="!!\n $app's script has encountered an error. Its execution was cancelled.\n!!"
# If the script is executed from a terminal, dump the end of the log that precedes the crash.
if ynh_is_term
# If the script is executed from the CLI, dump the end of the log that precedes the crash.
if [ "$YNH_INTERFACE" == "cli" ]
then
# Unset xtrace to not spoil the log
set +x

View file

@ -28,7 +28,7 @@ import re
import tempfile
from glob import iglob
from moulinette import m18n
from moulinette import m18n, msettings
from yunohost.utils.error import YunohostError
from moulinette.utils import log
from moulinette.utils.filesystem import read_json
@ -337,6 +337,8 @@ def hook_exec(path, args=None, raise_on_error=False, no_trace=False,
env = {}
env['YNH_CWD'] = chdir
env['YNH_INTERFACE'] = msettings.get('interface')
stdinfo = os.path.join(tempfile.mkdtemp(), "stdinfo")
env['YNH_STDINFO'] = stdinfo