diff --git a/helpers/helpers.v2.1.d/apps b/helpers/helpers.v2.1.d/apps index c010dab2b..474f5e45f 100644 --- a/helpers/helpers.v2.1.d/apps +++ b/helpers/helpers.v2.1.d/apps @@ -134,7 +134,7 @@ ynh_spawn_app_shell() { # Force Bash to be used to run this helper if [[ ! $0 =~ \/?bash$ ]] then - ynh_print_err --message="Please use Bash as shell" + ynh_print_warn --message="Please use Bash as shell" exit 1 fi @@ -142,13 +142,13 @@ ynh_spawn_app_shell() { local installed_apps_list=($(yunohost app list --output-as json --quiet | jq -r .apps[].id)) if [[ " ${installed_apps_list[*]} " != *" ${app} "* ]] then - ynh_print_err --message="$app is not in the apps list" + ynh_print_warn --message="$app is not in the apps list" exit 1 fi # Make sure the app has its own user if ! id -u "$app" &>/dev/null; then - ynh_print_err --message="There is no \"$app\" system user" + ynh_print_warn --message="There is no \"$app\" system user" exit 1 fi @@ -156,7 +156,7 @@ ynh_spawn_app_shell() { local install_dir=$(ynh_app_setting_get --key=install_dir) if [ -z "$install_dir" ] then - ynh_print_err --message="$app has no install_dir setting (does it use packaging format >=2?)" + ynh_print_warn --message="$app has no install_dir setting (does it use packaging format >=2?)" exit 1 fi diff --git a/helpers/helpers.v2.1.d/apt b/helpers/helpers.v2.1.d/apt index 2e13f1186..24e5b5f99 100644 --- a/helpers/helpers.v2.1.d/apt +++ b/helpers/helpers.v2.1.d/apt @@ -28,7 +28,7 @@ ynh_wait_dpkg_free() { # Check if the name of this file contains only numbers. if echo "$dpkg_file" | grep --perl-regexp --quiet "^[[:digit:]]+$"; then # If so, that a remaining of dpkg. - ynh_print_err --message="dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem." + ynh_print_warn --message="dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem." set -o xtrace # set -x return 1 fi diff --git a/helpers/helpers.v2.1.d/backup b/helpers/helpers.v2.1.d/backup index 21ee091a4..0f34e9bc9 100644 --- a/helpers/helpers.v2.1.d/backup +++ b/helpers/helpers.v2.1.d/backup @@ -108,7 +108,7 @@ ynh_backup() { # Check if dest_path already exists in tmp archive if [[ -e "${dest_path}" ]]; then - ynh_print_err --message="Destination path '${dest_path}' already exist" + ynh_print_warn --message="Destination path '${dest_path}' already exist" return 1 fi diff --git a/helpers/helpers.v2.1.d/fail2ban b/helpers/helpers.v2.1.d/fail2ban index be9f2da95..05fe0ea2b 100644 --- a/helpers/helpers.v2.1.d/fail2ban +++ b/helpers/helpers.v2.1.d/fail2ban @@ -109,7 +109,7 @@ ignoreregex = local fail2ban_error="$(journalctl --no-hostname --unit=fail2ban | tail --lines=50 | grep "WARNING.*$app.*")" if [[ -n "$fail2ban_error" ]]; then - ynh_print_err --message="Fail2ban failed to load the jail for $app" + ynh_print_warn --message="Fail2ban failed to load the jail for $app" ynh_print_warn --message="${fail2ban_error#*WARNING}" fi } diff --git a/helpers/helpers.v2.1.d/logging b/helpers/helpers.v2.1.d/logging index 4af30af85..06b8d5083 100644 --- a/helpers/helpers.v2.1.d/logging +++ b/helpers/helpers.v2.1.d/logging @@ -36,15 +36,6 @@ ynh_print_info() { echo "$message" >&$YNH_STDINFO } -# Main printer, just in case in the future we have to change anything about that. -# -# [internal] -# -# Requires YunoHost version 3.2.0 or higher. -ynh_print_log() { - echo -e "${1}" -} - # Print a warning on stderr # # usage: ynh_print_warn --message="Text to print" @@ -58,65 +49,7 @@ ynh_print_warn() { ynh_handle_getopts_args "$@" # =========================================== - ynh_print_log "${message}" >&2 -} - -# Print an error on stderr -# -# usage: ynh_print_err --message="Text to print" -# | arg: -m, --message= - The text to print -# -# Requires YunoHost version 3.2.0 or higher. -ynh_print_err() { - # ============ Argument parsing ============= - local -A args_array=([m]=message=) - local message - ynh_handle_getopts_args "$@" - # =========================================== - - ynh_print_log "[Error] ${message}" >&2 -} - -# Execute a command and print the result as an error -# -# usage: ynh_exec_err your command and args -# | arg: command - command to execute -# -# Note that you should NOT quote the command but only prefix it with ynh_exec_err -# -# Requires YunoHost version 3.2.0 or higher. -ynh_exec_err() { - # Boring legacy handling for when people calls ynh_exec_* wrapping the command in quotes, - # (because in the past eval was used) ... - # we detect this by checking that there's no 2nd arg, and $1 contains a space - if [[ "$#" -eq 1 ]] && [[ "$1" == *" "* ]] - then - ynh_print_err --message="$(eval $@)" - else - # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 - ynh_print_err --message="$("$@")" - fi -} - -# Execute a command and print the result as a warning -# -# usage: ynh_exec_warn your command and args -# | arg: command - command to execute -# -# Note that you should NOT quote the command but only prefix it with ynh_exec_warn -# -# Requires YunoHost version 3.2.0 or higher. -ynh_exec_warn() { - # Boring legacy handling for when people calls ynh_exec_* wrapping the command in quotes, - # (because in the past eval was used) ... - # we detect this by checking that there's no 2nd arg, and $1 contains a space - if [[ "$#" -eq 1 ]] && [[ "$1" == *" "* ]] - then - ynh_print_warn --message="$(eval $@)" - else - # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 - ynh_print_warn --message="$("$@")" - fi + echo -e "${message}" >&2 } # Execute a command and force the result to be printed on stdout @@ -140,48 +73,6 @@ ynh_exec_warn_less() { fi } -# Execute a command and redirect stdout in /dev/null -# -# usage: ynh_exec_quiet your command and args -# | arg: command - command to execute -# -# Note that you should NOT quote the command but only prefix it with ynh_exec_warn -# -# Requires YunoHost version 3.2.0 or higher. -ynh_exec_quiet() { - # Boring legacy handling for when people calls ynh_exec_* wrapping the command in quotes, - # (because in the past eval was used) ... - # we detect this by checking that there's no 2nd arg, and $1 contains a space - if [[ "$#" -eq 1 ]] && [[ "$1" == *" "* ]] - then - eval $@ > /dev/null - else - # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 - "$@" > /dev/null - fi -} - -# Execute a command and redirect stdout and stderr in /dev/null -# -# usage: ynh_exec_quiet your command and args -# | arg: command - command to execute -# -# Note that you should NOT quote the command but only prefix it with ynh_exec_quiet -# -# Requires YunoHost version 3.2.0 or higher. -ynh_exec_fully_quiet() { - # Boring legacy handling for when people calls ynh_exec_* wrapping the command in quotes, - # (because in the past eval was used) ... - # we detect this by checking that there's no 2nd arg, and $1 contains a space - if [[ "$#" -eq 1 ]] && [[ "$1" == *" "* ]] - then - eval $@ > /dev/null 2>&1 - else - # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 - "$@" > /dev/null 2>&1 - fi -} - # Execute a command and redirect stderr in /dev/null. Print stderr on error. # # usage: ynh_exec_and_print_stderr_only_if_error your command and args @@ -202,32 +93,6 @@ ynh_exec_and_print_stderr_only_if_error() { fi } -# Remove any logs for all the following commands. -# -# usage: ynh_print_OFF -# -# [internal] -# -# WARNING: You should be careful with this helper, and never forget to use ynh_print_ON as soon as possible to restore the logging. -# -# Requires YunoHost version 3.2.0 or higher. -ynh_print_OFF() { - exec {BASH_XTRACEFD}>/dev/null -} - -# Restore the logging after ynh_print_OFF -# -# usage: ynh_print_ON -# -# [internal] -# -# Requires YunoHost version 3.2.0 or higher. -ynh_print_ON() { - exec {BASH_XTRACEFD}>&1 - # Print an echo only for the log, to be able to know that ynh_print_ON has been called. - echo ynh_print_ON >/dev/null -} - # Initial definitions for ynh_script_progression increment_progression=0 previous_weight=0 diff --git a/helpers/helpers.v2.1.d/postgresql b/helpers/helpers.v2.1.d/postgresql index 5423026d2..71be36f8f 100644 --- a/helpers/helpers.v2.1.d/postgresql +++ b/helpers/helpers.v2.1.d/postgresql @@ -195,7 +195,7 @@ ynh_psql_database_exists() { # though it could exists. if ! command -v psql then - ynh_print_err --message="PostgreSQL is not installed, impossible to check for db existence." + ynh_print_warn --message="PostgreSQL is not installed, impossible to check for db existence." return 1 elif ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database"; then return 1 diff --git a/helpers/helpers.v2.1.d/systemd b/helpers/helpers.v2.1.d/systemd index 748c31cfa..8d63006fe 100644 --- a/helpers/helpers.v2.1.d/systemd +++ b/helpers/helpers.v2.1.d/systemd @@ -112,10 +112,10 @@ ynh_systemd_action() { # If the service fails to perform the action if ! systemctl $action $service_name; then # Show syslog for this service - ynh_exec_err journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name + journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name >&2 # If a log is specified for this service, show also the content of this log if [ -e "$log_path" ]; then - ynh_exec_err tail --lines=$length "$log_path" + tail --lines=$length "$log_path" >&2 fi ynh_clean_check_starting return 1 @@ -160,10 +160,10 @@ ynh_systemd_action() { if [ $i -eq $timeout ]; then ynh_print_warn --message="The service $service_name didn't fully executed the action ${action} before the timeout." ynh_print_warn --message="Please find here an extract of the end of the log of the service $service_name:" - ynh_exec_warn journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name + journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name >&2 if [ -e "$log_path" ]; then ynh_print_warn --message="\-\-\-" - ynh_exec_warn tail --lines=$length "$log_path" + tail --lines=$length "$log_path" >&2 fi fi ynh_clean_check_starting