mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers2.1: remove legacy/unecessary/underused helpers: ynh_print_log, ynh_print_err, ynh_exec_err, ynh_exec_quiet, ynh_exec_fully_quiet, ynh_print_OFF, ynh_print_ON
This commit is contained in:
parent
0eda746af5
commit
67477473e8
7 changed files with 13 additions and 148 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue