From 95d2c8f79940feb8bf757bec48422bcc484b9253 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 18 May 2019 18:31:02 +0200 Subject: [PATCH] Inject a new environment variable YNH_INTERFACE to test inside helpers if we're using Yunohost from the CLI or API --- data/helpers.d/utils | 13 ++----------- src/yunohost/hook.py | 4 +++- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/data/helpers.d/utils b/data/helpers.d/utils index d24474ebc..a561b2f73 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -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 diff --git a/src/yunohost/hook.py b/src/yunohost/hook.py index 2841dd425..42807fdf7 100644 --- a/src/yunohost/hook.py +++ b/src/yunohost/hook.py @@ -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