helpers2.1: further simplify logging helpers by removing the --message (ynh_script_progression too, no more args except the message)

This commit is contained in:
Alexandre Aubin 2024-06-19 23:40:53 +02:00
parent 11e2b6d63c
commit 6b6580a919
18 changed files with 124 additions and 204 deletions

View file

@ -22,7 +22,7 @@ ynh_install_apps() {
do
# Retrieve the name of the app (part before ?)
local one_app=$(cut -d "?" -f1 <<< "$one_app_and_its_args")
[ -z "$one_app" ] && ynh_die --message="You didn't provided a YunoHost app to install"
[ -z "$one_app" ] && ynh_die "You didn't provided a YunoHost app to install"
yunohost tools update apps
@ -102,10 +102,10 @@ ynh_remove_apps() {
if [[ -z "$required_by" ]]
then
# Remove $one_app
ynh_print_info --message="Removing of $one_app"
ynh_print_info "Removing of $one_app"
yunohost app remove $one_app --purge
else
ynh_print_info --message="$one_app was not removed because it's still required by${required_by}"
ynh_print_info "$one_app was not removed because it's still required by${required_by}"
fi
done
fi
@ -134,7 +134,7 @@ ynh_spawn_app_shell() {
# Force Bash to be used to run this helper
if [[ ! $0 =~ \/?bash$ ]]
then
ynh_print_warn --message="Please use Bash as shell"
ynh_print_warn "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_warn --message="$app is not in the apps list"
ynh_print_warn "$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_warn --message="There is no \"$app\" system user"
ynh_print_warn "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_warn --message="$app has no install_dir setting (does it use packaging format >=2?)"
ynh_print_warn "$app has no install_dir setting (does it use packaging format >=2?)"
exit 1
fi

View file

@ -49,7 +49,7 @@ ynh_apt_install_dependencies() {
then
# Cover a small edge case where a packager could have specified "php7.4-pwet php5-gni" which is confusing
[[ $(echo $specific_php_version | wc -l) -eq 1 ]] \
|| ynh_die --message="Inconsistent php versions in dependencies ... found : $specific_php_version"
|| ynh_die "Inconsistent php versions in dependencies ... found : $specific_php_version"
dependencies+=", php${specific_php_version}, php${specific_php_version}-fpm, php${specific_php_version}-common"
@ -142,12 +142,12 @@ EOF
# Fake an install of those dependencies to see the errors
# The sed command here is, Print only from 'Reading state info' to the end.
[[ -n "$problematic_dependencies" ]] && _ynh_apt_install $problematic_dependencies --dry-run 2>&1 | sed --quiet '/Reading state info/,$p' | grep -v "fix-broken\|Reading state info" >&2
ynh_die --message="Unable to install dependencies"
ynh_die "Unable to install dependencies"
}
rm --recursive --force "$TMPDIR" # Remove the temp dir.
# check if the package is actually installed
_ynh_apt_package_is_installed "${app_ynh_deps}" || ynh_die --message="Unable to install dependencies"
_ynh_apt_package_is_installed "${app_ynh_deps}" || ynh_die "Unable to install dependencies"
# Specific tweak related to Postgresql
# -> trigger postgresql regenconf if we may have just installed postgresql
@ -291,7 +291,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_warn --message="dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem."
ynh_print_warn "dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem."
set -o xtrace # set -x
return 1
fi

View file

@ -41,9 +41,9 @@ ynh_backup() {
# don't backup big data items
if [[ "$is_data" == true ]] && ([[ ${do_not_backup_data:-0} -eq 1 ]] || [[ ${BACKUP_CORE_ONLY:-0} -eq 1 ]]); then
if [ $BACKUP_CORE_ONLY -eq 1 ]; then
ynh_print_info --message="$target will not be saved, because 'BACKUP_CORE_ONLY' is set."
ynh_print_info "$target will not be saved, because 'BACKUP_CORE_ONLY' is set."
else
ynh_print_info --message="$target will not be saved, because 'do_not_backup_data' is set."
ynh_print_info "$target will not be saved, because 'do_not_backup_data' is set."
fi
return 1
fi
@ -53,7 +53,7 @@ ynh_backup() {
# ==============================================================================
# Be sure the source path is not empty
if [ ! -e "$target" ]; then
ynh_print_warn --message="File or folder '${target}' to be backed up does not exist"
ynh_print_warn "File or folder '${target}' to be backed up does not exist"
return 1
fi
@ -67,7 +67,7 @@ ynh_backup() {
# Check if dest_path already exists in tmp archive
if [[ -e "${dest_path}" ]]; then
ynh_print_warn --message="Destination path '${dest_path}' already exist"
ynh_print_warn "Destination path '${dest_path}' already exist"
return 1
fi
@ -146,7 +146,7 @@ ynh_restore() {
if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ]; then
if [[ "$is_data" == true ]]
then
ynh_print_info --message="Skipping $target which doesn't exists in the archive, probably because restoring from a safety-backup-before-upgrade"
ynh_print_info "Skipping $target which doesn't exists in the archive, probably because restoring from a safety-backup-before-upgrade"
# Assume it's not a big deal, we may be restoring a safety-backup-before-upgrade which doesnt contain those
return 0
else
@ -275,13 +275,13 @@ ynh_backup_if_checksum_is_different() {
backup_file_checksum="/var/cache/yunohost/appconfbackup/$file.backup.$(date '+%Y%m%d.%H%M%S')"
mkdir --parents "$(dirname "$backup_file_checksum")"
cp --archive "$file" "$backup_file_checksum" # Backup the current file
ynh_print_warn --message="File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum"
ynh_print_warn "File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum"
echo "$backup_file_checksum" # Return the name of the backup file
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
local file_path_base64=$(echo "$file" | base64 -w0)
if test -e /var/cache/yunohost/appconfbackup/original_${file_path_base64}
then
ynh_print_warn --message="Diff with the original file:"
ynh_print_warn "Diff with the original file:"
diff --report-identical-files --unified --color=always /var/cache/yunohost/appconfbackup/original_${file_path_base64} $file >&2 || true
fi
fi

View file

@ -20,7 +20,7 @@ _ynh_app_config_get_one() {
# Get value from app settings or from another file
elif [[ "$type" == "file" ]]; then
if [[ "$bind" == "settings" ]]; then
ynh_die --message="File '${short_setting}' can't be stored in settings"
ynh_die "File '${short_setting}' can't be stored in settings"
fi
old[$short_setting]="$(ls "$(echo $bind | sed s@__INSTALL_DIR__@${install_dir:-}@ | sed s/__APP__/$app/)" 2>/dev/null || echo YNH_NULL)"
file_hash[$short_setting]="true"
@ -30,7 +30,7 @@ _ynh_app_config_get_one() {
if [[ "$bind" == "settings" ]]; then
old[$short_setting]="$(ynh_app_setting_get $app $short_setting)"
elif [[ "$bind" == *":"* ]]; then
ynh_die --message="For technical reasons, multiline text '${short_setting}' can't be stored automatically in a variable file, you have to create custom getter/setter"
ynh_die "For technical reasons, multiline text '${short_setting}' can't be stored automatically in a variable file, you have to create custom getter/setter"
else
old[$short_setting]="$(cat $(echo $bind | sed s@__INSTALL_DIR__@${install_dir:-}@ | sed s/__APP__/$app/) 2>/dev/null || echo YNH_NULL)"
fi
@ -71,38 +71,38 @@ _ynh_app_config_apply_one() {
# Save in a file
elif [[ "$type" == "file" ]]; then
if [[ "$bind" == "settings" ]]; then
ynh_die --message="File '${short_setting}' can't be stored in settings"
ynh_die "File '${short_setting}' can't be stored in settings"
fi
local bind_file="$(echo "$bind" | sed s@__INSTALL_DIR__@${install_dir:-}@ | sed s/__APP__/$app/)"
if [[ "${!short_setting}" == "" ]]; then
ynh_backup_if_checksum_is_different --file="$bind_file"
ynh_safe_rm "$bind_file"
ynh_delete_file_checksum --file="$bind_file"
ynh_print_info --message="File '$bind_file' removed"
ynh_print_info "File '$bind_file' removed"
else
ynh_backup_if_checksum_is_different --file="$bind_file"
if [[ "${!short_setting}" != "$bind_file" ]]; then
cp "${!short_setting}" "$bind_file"
fi
ynh_store_file_checksum --file="$bind_file" --update_only
ynh_print_info --message="File '$bind_file' overwritten with ${!short_setting}"
ynh_print_info "File '$bind_file' overwritten with ${!short_setting}"
fi
# Save value in app settings
elif [[ "$bind" == "settings" ]]; then
ynh_app_setting_set --key=$short_setting --value="${!short_setting}"
ynh_print_info --message="Configuration key '$short_setting' edited in app settings"
ynh_print_info "Configuration key '$short_setting' edited in app settings"
# Save multiline text in a file
elif [[ "$type" == "text" ]]; then
if [[ "$bind" == *":"* ]]; then
ynh_die --message="For technical reasons, multiline text '${short_setting}' can't be stored automatically in a variable file, you have to create custom getter/setter"
ynh_die "For technical reasons, multiline text '${short_setting}' can't be stored automatically in a variable file, you have to create custom getter/setter"
fi
local bind_file="$(echo "$bind" | sed s@__INSTALL_DIR__@${install_dir:-}@ | sed s/__APP__/$app/)"
ynh_backup_if_checksum_is_different --file="$bind_file"
echo "${!short_setting}" >"$bind_file"
ynh_store_file_checksum --file="$bind_file" --update_only
ynh_print_info --message="File '$bind_file' overwritten with the content provided in question '${short_setting}'"
ynh_print_info "File '$bind_file' overwritten with the content provided in question '${short_setting}'"
# Set value into a kind of key/value file
else
@ -121,7 +121,7 @@ _ynh_app_config_apply_one() {
# We stored the info in settings in order to be able to upgrade the app
ynh_app_setting_set --key=$short_setting --value="${!short_setting}"
ynh_print_info --message="Configuration key '$bind_key_' edited into $bind_file"
ynh_print_info "Configuration key '$bind_key_' edited into $bind_file"
fi
fi
@ -212,7 +212,7 @@ _ynh_app_config_show() {
_ynh_app_config_validate() {
# Change detection
ynh_script_progression --message="Checking what changed in the new configuration..." --weight=1
ynh_script_progression "Checking what changed in the new configuration..."
local nothing_changed=true
local changes_validated=true
for short_setting in "${!old[@]}"; do
@ -248,12 +248,12 @@ _ynh_app_config_validate() {
fi
done
if [[ "$nothing_changed" == "true" ]]; then
ynh_print_info --message="Nothing has changed"
ynh_print_info "Nothing has changed"
exit 0
fi
# Run validation if something is changed
ynh_script_progression --message="Validating the new configuration..." --weight=1
ynh_script_progression "Validating the new configuration..."
for short_setting in "${!old[@]}"; do
[[ "${changed[$short_setting]}" == "false" ]] && continue
@ -320,7 +320,7 @@ ynh_app_action_run() {
#ynh_return "result:"
#ynh_return "$(echo "${result}" | sed 's/^/ /g')"
else
ynh_die --message="No handler defined in app's script for action $1. If you are the maintainer of this app, you should define '$runner'"
ynh_die "No handler defined in app's script for action $1. If you are the maintainer of this app, you should define '$runner'"
fi
}
@ -339,14 +339,14 @@ ynh_app_config_run() {
;;
apply)
max_progression=4
ynh_script_progression --message="Reading config panel description and current configuration..."
ynh_script_progression "Reading config panel description and current configuration..."
ynh_app_config_get
ynh_app_config_validate
ynh_script_progression --message="Applying the new configuration..."
ynh_script_progression "Applying the new configuration..."
ynh_app_config_apply
ynh_script_progression --message="Configuration of $app completed" --last
ynh_script_progression "Configuration of $app completed"
;;
*)
ynh_app_action_run $1

View file

@ -65,7 +65,7 @@ ynh_config_add_fail2ban() {
# If failregex is provided, Build a config file on-the-fly using $logpath and $failregex
if [[ -n "${failregex:-}" ]]; then
test -n "$logpath" || ynh_die --message="ynh_config_add_fail2ban expects a logfile path as first argument and received nothing."
test -n "$logpath" || ynh_die "ynh_config_add_fail2ban expects a logfile path as first argument and received nothing."
echo "
[__APP__]
@ -109,8 +109,8 @@ ignoreregex =
local fail2ban_error="$(journalctl --no-hostname --unit=fail2ban | tail --lines=50 | grep "WARNING.*$app.*")"
if [[ -n "$fail2ban_error" ]]; then
ynh_print_warn --message="Fail2ban failed to load the jail for $app"
ynh_print_warn --message="${fail2ban_error#*WARNING}"
ynh_print_warn "Fail2ban failed to load the jail for $app"
ynh_print_warn "${fail2ban_error#*WARNING}"
fi
}

View file

@ -100,9 +100,9 @@ ynh_handle_getopts_args() {
getopts ":$getopts_parameters" parameter || true
if [ "$parameter" = "?" ]; then
ynh_die --message="Invalid argument: -${OPTARG:-}"
ynh_die "Invalid argument: -${OPTARG:-}"
elif [ "$parameter" = ":" ]; then
ynh_die --message="-$OPTARG parameter requires an argument."
ynh_die "-$OPTARG parameter requires an argument."
else
local shift_value=1
# Use the long option, corresponding to the short option read by getopts, as a variable
@ -128,7 +128,7 @@ ynh_handle_getopts_args() {
# At this point, if all_args[0] start with "-", then the argument is not well formed
if [ "${all_args[0]:0:1}" == "-" ]; then
ynh_die --message="Argument \"${all_args[0]}\" not valid! Did you use a single \"-\" instead of two?"
ynh_die "Argument \"${all_args[0]}\" not valid! Did you use a single \"-\" instead of two?"
fi
# Reduce the value of shift, because the option has been removed manually
shift_value=$((shift_value - 1))

View file

@ -3,7 +3,7 @@
ynh_go_try_bash_extension() {
if [ -x src/configure ]; then
src/configure && make -C src || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
ynh_print_info "Optional bash extension failed to build, but things will still work normally."
}
fi
}
@ -53,7 +53,7 @@ _ynh_load_go_in_path_and_other_tweaks() {
# Requires YunoHost version 3.2.2 or higher.
ynh_go_install () {
[[ -n "${go_version:-}" ]] || ynh_die --message="\$go_version should be defined prior to calling ynh_go_install"
[[ -n "${go_version:-}" ]] || ynh_die "\$go_version should be defined prior to calling ynh_go_install"
# Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
@ -68,11 +68,11 @@ ynh_go_install () {
mkdir -p $goenv_install_dir
pushd "$goenv_install_dir"
if ! [ -x "$goenv_install_dir/bin/goenv" ]; then
ynh_print_info --message="Downloading goenv..."
ynh_print_info "Downloading goenv..."
git init -q
git remote add origin https://github.com/syndbg/goenv.git
else
ynh_print_info --message="Updating goenv..."
ynh_print_info "Updating goenv..."
fi
git fetch -q --tags --prune origin
local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
@ -85,11 +85,11 @@ ynh_go_install () {
mkdir -p "$goenv_install_dir/plugins/xxenv-latest"
pushd "$goenv_install_dir/plugins/xxenv-latest"
if ! [ -x "$goenv_install_dir/plugins/xxenv-latest/bin/goenv-latest" ]; then
ynh_print_info --message="Downloading xxenv-latest..."
ynh_print_info "Downloading xxenv-latest..."
git init -q
git remote add origin https://github.com/momo-lab/xxenv-latest.git
else
ynh_print_info --message="Updating xxenv-latest..."
ynh_print_info "Updating xxenv-latest..."
fi
git fetch -q --tags --prune origin
local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
@ -110,7 +110,7 @@ ynh_go_install () {
# Install the requested version of Go
local final_go_version=$(goenv latest --print "$go_version")
ynh_print_info --message="Installation of Go-$final_go_version"
ynh_print_info "Installation of Go-$final_go_version"
goenv install --quiet --skip-existing "$final_go_version" 2>&1
# Store go_version into the config of this app
@ -181,7 +181,7 @@ _ynh_go_cleanup () {
do
if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Go-$installed_go_version"
ynh_print_info "Removing of Go-$installed_go_version"
$goenv_install_dir/bin/goenv uninstall --force "$installed_go_version"
fi
done
@ -190,7 +190,7 @@ _ynh_go_cleanup () {
if [[ ! $required_go_versions ]]
then
# Remove goenv environment configuration
ynh_print_info --message="Removing of goenv"
ynh_print_info "Removing of goenv"
ynh_secure_remove --file="$goenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/goenv.sh"
fi

View file

@ -1,55 +1,25 @@
#!/bin/bash
# Print a message to stderr and exit
# Print a message to stderr and terminate the current script
#
# usage: ynh_die --message=MSG [--ret_code=RETCODE]
# | arg: -m, --message= - Message to display
# | arg: -c, --ret_code= - Exit code to exit with
#
# Requires YunoHost version 2.4.0 or higher.
# usage: ynh_die "Some message"
ynh_die() {
# ============ Argument parsing =============
local -A args_array=([m]=message= [c]=ret_code=)
local message
local ret_code
ynh_handle_getopts_args "$@"
ret_code=${ret_code:-1}
# ===========================================
echo "$message" 1>&2
exit "$ret_code"
echo "$1" 1>&2
exit 1
}
# Display a message in the 'INFO' logging category
# Print an "INFO" message
#
# usage: ynh_print_info --message="Some message"
# | arg: -m, --message= - Message to display
#
# Requires YunoHost version 3.2.0 or higher.
# usage: ynh_print_info "Some message"
ynh_print_info() {
# ============ Argument parsing =============
local -A args_array=([m]=message=)
local message
ynh_handle_getopts_args "$@"
# ===========================================
echo "$message" >&$YNH_STDINFO
echo "$1" >&$YNH_STDINFO
}
# Print a warning on stderr
#
# usage: ynh_print_warn --message="Text to print"
# | arg: -m, --message= - The text to print
#
# Requires YunoHost version 3.2.0 or higher.
# usage: ynh_print_warn "Some message"
ynh_print_warn() {
# ============ Argument parsing =============
local -A args_array=([m]=message=)
local message
ynh_handle_getopts_args "$@"
# ===========================================
echo -e "${message}" >&2
echo "$1" >&2
}
# Execute a command and redirect stderr to stdout
@ -82,6 +52,16 @@ ynh_exec_and_print_stderr_only_if_error() {
fi
}
# Return data to the YunoHost core for later processing
# (to be used by special hooks like app config panel and core diagnosis)
#
# usage: ynh_return somedata
#
# Requires YunoHost version 3.6.0 or higher.
ynh_return() {
echo "$1" >>"$YNH_STDRETURN"
}
# Initial definitions for ynh_script_progression
increment_progression=0
previous_weight=0
@ -92,107 +72,47 @@ progress_scale=20
progress_string2="####################"
progress_string1="++++++++++++++++++++"
progress_string0="...................."
# Define base_time when the file is sourced
base_time=$(date +%s)
# Print a progress bar showing the progression of an app script
#
# usage: ynh_script_progression --message=message [--weight=weight] [--time]
# | arg: -m, --message= - The text to print
# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
# | arg: -t, --time - Print the execution time since the last call to this helper. Especially usefull to define weights. The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
# | arg: -l, --last - Use for the last call of the helper, to fill the progression bar.
# usage: ynh_script_progression "Some message"
#
# Requires YunoHost version 3.5.0 or higher.
ynh_script_progression() {
set +o xtrace # set +x
# ============ Argument parsing =============
local -A args_array=([m]=message= [w]=weight= [t]=time [l]=last)
local message
local weight
local time
local last
ynh_handle_getopts_args "$@"
weight=${weight:-1}
# ===========================================
# Re-disable xtrace, ynh_handle_getopts_args set it back
set +o xtrace # set +x
# Always activate time when running inside CI tests
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
time=${time:-1}
else
time=${time:-0}
fi
last=${last:-0}
# Get execution time since the last $base_time
local exec_time=$(($(date +%s) - $base_time))
base_time=$(date +%s)
# Compute $max_progression (if we didn't already)
if [ "$max_progression" = -1 ]; then
# Get the number of occurrences of 'ynh_script_progression' in the script. Except those are commented.
local helper_calls="$(grep --count "^[^#]*ynh_script_progression" $0)"
# Get the number of call with a weight value
local weight_calls=$(grep --perl-regexp --count "^[^#]*ynh_script_progression.*(--weight|-w )" $0)
# Get the weight of each occurrences of 'ynh_script_progression' in the script using --weight
local weight_valuesA="$(grep --perl-regexp "^[^#]*ynh_script_progression.*--weight" $0 | sed 's/.*--weight[= ]\([[:digit:]]*\).*/\1/g')"
# Get the weight of each occurrences of 'ynh_script_progression' in the script using -w
local weight_valuesB="$(grep --perl-regexp "^[^#]*ynh_script_progression.*-w " $0 | sed 's/.*-w[= ]\([[:digit:]]*\).*/\1/g')"
# Each value will be on a different line.
# Remove each 'end of line' and replace it by a '+' to sum the values.
local weight_values=$(($(echo "$weight_valuesA" "$weight_valuesB" | grep -v -E '^\s*$' | tr '\n' '+' | sed 's/+$/+0/g')))
# max_progression is a total number of calls to this helper.
# Less the number of calls with a weight value.
# Plus the total of weight values
max_progression=$(($helper_calls - $weight_calls + $weight_values))
local helper_calls=
max_progression="$(grep --count "^[^#]*ynh_script_progression" $0)"
fi
# Increment each execution of ynh_script_progression in this script by the weight of the previous call.
increment_progression=$(($increment_progression + $previous_weight))
# Store the weight of the current call in $previous_weight for next call
previous_weight=$weight
previous_weight=1
# Reduce $increment_progression to the size of the scale
if [ $last -eq 0 ]; then
local effective_progression=$(($increment_progression * $progress_scale / $max_progression))
local effective_progression=$(($increment_progression * $progress_scale / $max_progression))
# If last is specified, fill immediately the progression_bar
else
local effective_progression=$progress_scale
fi
# Build $progression_bar from progress_string(0,1,2) according to $effective_progression and the weight of the current task
# expected_progression is the progression expected after the current task
local expected_progression="$((($increment_progression + $weight) * $progress_scale / $max_progression - $effective_progression))"
if [ $last -eq 1 ]; then
expected_progression=0
# Hack for the "--last" message
if grep -qw 'completed' <<< "$1";
then
effective_progression=$progress_scale
expected_progression=0
fi
# left_progression is the progression not yet done
local left_progression="$(($progress_scale - $effective_progression - $expected_progression))"
# Build the progression bar with $effective_progression, work done, $expected_progression, current work and $left_progression, work to be done.
local progression_bar="${progress_string2:0:$effective_progression}${progress_string1:0:$expected_progression}${progress_string0:0:$left_progression}"
local print_exec_time=""
if [ $time -eq 1 ] && [ "$exec_time" -gt 10 ]; then
print_exec_time=" [$(bc <<< "scale=1; $exec_time / 60" ) minutes]"
fi
echo "[$progression_bar] > ${message}${print_exec_time}" >&$YNH_STDINFO
echo "[$progression_bar] > ${1}" >&$YNH_STDINFO
set -o xtrace # set -x
}
# Return data to the YunoHost core for later processing
# (to be used by special hooks like app config panel and core diagnosis)
#
# usage: ynh_return somedata
#
# Requires YunoHost version 3.6.0 or higher.
ynh_return() {
echo "$1" >>"$YNH_STDRETURN"
}

View file

@ -206,7 +206,7 @@ ynh_mongo_remove_db() {
if ynh_mongo_database_exists --database=$db_name; then # Check if the database exists
ynh_mongo_drop_db --database=$db_name # Remove the database
else
ynh_print_warn --message="Database $db_name not found"
ynh_print_warn "Database $db_name not found"
fi
# Remove mongo user if it exists
@ -221,17 +221,17 @@ ynh_mongo_remove_db() {
#
ynh_install_mongo() {
[[ -n "${mongo_version:-}" ]] || ynh_die --message="\$mongo_version should be defined prior to calling ynh_install_mongo"
[[ -n "${mongo_version:-}" ]] || ynh_die "\$mongo_version should be defined prior to calling ynh_install_mongo"
ynh_print_info --message="Installing MongoDB Community Edition ..."
ynh_print_info "Installing MongoDB Community Edition ..."
local mongo_debian_release=$YNH_DEBIAN_VERSION
if [[ $(cat /proc/cpuinfo) != *"avx"* && "$mongo_version" != "4.4" ]]; then
ynh_print_warn --message="Installing Mongo 4.4 as $mongo_version is not compatible with your cpu (see https://docs.mongodb.com/manual/administration/production-notes/#x86_64)."
ynh_print_warn "Installing Mongo 4.4 as $mongo_version is not compatible with your cpu (see https://docs.mongodb.com/manual/administration/production-notes/#x86_64)."
mongo_version="4.4"
fi
if [[ "$mongo_version" == "4.4" ]]; then
ynh_print_warn --message="Switched to buster install as Mongo 4.4 is not compatible with $mongo_debian_release."
ynh_print_warn "Switched to buster install as Mongo 4.4 is not compatible with $mongo_debian_release."
mongo_debian_release=buster
fi
@ -261,7 +261,7 @@ ynh_remove_mongo() {
# Only remove the mongodb service if it is not installed.
if ! _ynh_apt_package_is_installed "mongodb*"
then
ynh_print_info --message="Removing MongoDB service..."
ynh_print_info "Removing MongoDB service..."
mongodb_servicename=mongod
# Remove the mongodb service
yunohost service remove $mongodb_servicename

View file

@ -44,7 +44,7 @@ _ynh_load_nodejs_in_path_and_other_tweaks() {
ynh_nodejs_install() {
# Use n, https://github.com/tj/n to manage the nodejs versions
[[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_nodejs_install"
[[ -n "${nodejs_version:-}" ]] || ynh_die "\$nodejs_version should be defined prior to calling ynh_nodejs_install"
# Create $n_install_dir
mkdir --parents "$n_install_dir"
@ -111,7 +111,7 @@ ynh_nodejs_install() {
# Requires YunoHost version 2.7.12 or higher.
ynh_nodejs_remove() {
[[ -n "${nodejs_version:-}" ]] || ynh_die --message="\$nodejs_version should be defined prior to calling ynh_nodejs_remove"
[[ -n "${nodejs_version:-}" ]] || ynh_die "\$nodejs_version should be defined prior to calling ynh_nodejs_remove"
# Remove the line for this app
sed --in-place "/$YNH_APP_INSTANCE_NAME:$nodejs_version/d" "$n_install_dir/ynh_app_version"

View file

@ -139,7 +139,7 @@ pm.process_idle_timeout = 10s
if ! php-fpm${php_version} --test 2>/dev/null; then
php-fpm${php_version} --test || true
ynh_safe_rm "$fpm_config_dir/pool.d/$app.conf"
ynh_die --message="The new configuration broke php-fpm?"
ynh_die "The new configuration broke php-fpm?"
fi
ynh_systemd_action --service=$fpm_service --action=reload
}
@ -213,7 +213,7 @@ _ynh_get_scalable_phpfpm() {
elif [ "$usage" = "high" ]; then
php_pm=static
else
ynh_die --message="Does not recognize '$usage' as an usage value."
ynh_die "Does not recognize '$usage' as an usage value."
fi
# Get the total of RAM available, except swap.
@ -309,7 +309,7 @@ ynh_composer_install() {
install_args="${install_args:-}"
# ===========================================
[[ -n "${composer_version}" ]] || ynh_die --message="\$composer_version should be defined before calling ynh_composer_install. (In the past, this was called \$YNH_COMPOSER_VERSION)"
[[ -n "${composer_version}" ]] || ynh_die "\$composer_version should be defined before calling ynh_composer_install. (In the past, this was called \$YNH_COMPOSER_VERSION)"
[[ ! -e "$workdir/composer.phar" ]] || ynh_safe_rm $workdir/composer.phar
@ -321,9 +321,9 @@ ynh_composer_install() {
local out
# Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget)
out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$workdir/composer.phar $composer_url 2>&1) \
|| ynh_die --message="$out"
|| ynh_die "$out"
# install dependencies
ynh_composer_exec --workdir="$workdir" --commands="install --no-dev $install_args" \
|| ynh_die --message="Unable to install core dependencies with Composer."
|| ynh_die "Unable to install core dependencies with Composer."
}

View file

@ -23,7 +23,7 @@ ynh_redis_get_free_db() {
db=-1
done
test "$db" -eq -1 && ynh_die --message="No available Redis databases..."
test "$db" -eq -1 && ynh_die "No available Redis databases..."
echo "$db"
}

View file

@ -52,7 +52,7 @@ _ynh_load_ruby_in_path_and_other_tweaks() {
# Requires YunoHost version 3.2.2 or higher.
ynh_ruby_install () {
[[ -n "${ruby_version:-}" ]] || ynh_die --message="\$ruby_version should be defined prior to calling ynh_ruby_install"
[[ -n "${ruby_version:-}" ]] || ynh_die "\$ruby_version should be defined prior to calling ynh_ruby_install"
# Load rbenv path in PATH
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
@ -252,7 +252,7 @@ _ynh_ruby_cleanup () {
ynh_ruby_try_bash_extension() {
if [ -x src/configure ]; then
src/configure && make -C src 2>&1 || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
ynh_print_info "Optional bash extension failed to build, but things will still work normally."
}
fi
}

View file

@ -128,7 +128,7 @@ ynh_sanitize_dbid() {
ynh_normalize_url_path() {
local path_url=$1
test -n "$path_url" || ynh_die --message="ynh_normalize_url_path expect a URL path as first argument and received nothing."
test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a /
path_url="/$path_url" # Add / at begin of path variable
fi

View file

@ -131,12 +131,12 @@ ynh_systemd_action() {
if [ "$log_path" == "systemd" ]; then
# For systemd services, we in fact dont rely on the templog, which for some reason is not reliable, but instead re-read journalctl every iteration, starting at the timestamp where we triggered the action
if journalctl --unit=$service --since="$time_start" --quiet --no-pager --no-hostname | grep --extended-regexp --quiet "$wait_until"; then
ynh_print_info --message="The service $service has correctly executed the action ${action}."
ynh_print_info "The service $service has correctly executed the action ${action}."
break
fi
else
if grep --extended-regexp --quiet "$wait_until" "$templog"; then
ynh_print_info --message="The service $service has correctly executed the action ${action}."
ynh_print_info "The service $service has correctly executed the action ${action}."
break
fi
fi
@ -158,11 +158,11 @@ ynh_systemd_action() {
echo "" >&2
fi
if [ $i -eq $timeout ]; then
ynh_print_warn --message="The service $service 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:"
ynh_print_warn "The service $service didn't fully executed the action ${action} before the timeout."
ynh_print_warn "Please find here an extract of the end of the log of the service $service:"
journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service >&2
if [ -e "$log_path" ]; then
ynh_print_warn --message="\-\-\-"
ynh_print_warn "==="
tail --lines=$length "$log_path" >&2
fi
fi

View file

@ -88,7 +88,7 @@ ynh_config_add() {
elif [ -f "$template" ]; then
template_path=$template
else
ynh_die --message="The provided template $template doesn't exist"
ynh_die "The provided template $template doesn't exist"
fi
ynh_backup_if_checksum_is_different --file="$destination"
@ -173,7 +173,7 @@ ynh_replace_vars() {
# -v FOO tests if $FOO is defined
# -v $FOO tests if ${!FOO} is defined
# More info: https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash/17538964#comment96392525_17538964
[[ -v "${one_var:-}" ]] || ynh_die --message="Variable \$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file"
[[ -v "${one_var:-}" ]] || ynh_die "Variable \$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file"
# Escape delimiter in match/replace string
match_string="__${one_var^^}__"
@ -232,7 +232,7 @@ ynh_read_var_in_file() {
after="${after:-}"
# ===========================================
[[ -f $file ]] || ynh_die --message="File $file does not exists"
[[ -f $file ]] || ynh_die "File $file does not exists"
set +o xtrace # set +x
@ -310,7 +310,7 @@ ynh_write_var_in_file() {
after="${after:-}"
# ===========================================
[[ -f $file ]] || ynh_die --message="File $file does not exists"
[[ -f $file ]] || ynh_die "File $file does not exists"
set +o xtrace # set +x

View file

@ -135,7 +135,7 @@ ynh_system_user_create() {
else
local shell="--shell /usr/sbin/nologin"
fi
useradd $user_home_dir --system --user-group $username $shell || ynh_die --message="Unable to create $username system account"
useradd $user_home_dir --system --user-group $username $shell || ynh_die "Unable to create $username system account"
fi
local group
@ -163,7 +163,7 @@ ynh_system_user_delete() {
if ynh_system_user_exists --username="$username"; then
deluser $username
else
ynh_print_warn --message="The user $username was not found"
ynh_print_warn "The user $username was not found"
fi
# Check if the group exists on the system

View file

@ -166,8 +166,8 @@ ynh_setup_source() {
local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')"
local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')"
[[ -n "$src_url" ]] || ynh_die --message="No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die --message="No sha256 sum defined for source $source_id$arch_prefix ?"
[[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?"
if [[ -z "$src_format" ]]
then
@ -195,7 +195,7 @@ ynh_setup_source() {
if [[ "$src_extract" != "true" ]] && [[ "$src_extract" != "false" ]]
then
ynh_die --message="For source $source_id, expected either 'true' or 'false' for the extract parameter"
ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter"
fi
# (Unused?) mecanism where one can have the file in a special local cache to not have to download it...
@ -212,7 +212,7 @@ ynh_setup_source() {
cp $local_src $src_filename
fi
[ -n "$src_url" ] || ynh_die --message="Couldn't parse SOURCE_URL from $src_file_path ?"
[ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?"
# If the file was prefetched but somehow doesn't match the sum, rm and redownload it
if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status
@ -229,7 +229,7 @@ ynh_setup_source() {
local out
# Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget)
out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$src_filename $src_url 2>&1) \
|| ynh_die --message="$out"
|| ynh_die "$out"
fi
# Check the control sum
@ -238,7 +238,7 @@ ynh_setup_source() {
local actual_sum="$(${src_sumprg} ${src_filename} | cut --delimiter=' ' --fields=1)"
local actual_size="$(du -hs ${src_filename} | cut --fields=1)"
rm -f ${src_filename}
ynh_die --message="Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})."
ynh_die "Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})."
fi
fi
@ -302,7 +302,7 @@ ynh_setup_source() {
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]; then
tar --extract --file=$src_filename --directory="$dest_dir" $strip
else
ynh_die --message="Archive format unrecognized."
ynh_die "Archive format unrecognized."
fi
ynh_safe_rm "$src_filename"
fi
@ -315,7 +315,7 @@ ynh_setup_source() {
pushd "$dest_dir"
for p in $patches_folder/${source_id}-*.patch; do
echo $p
patch --strip=1 <$p || ynh_print_warn --message="Packagers /!\\ patch $p failed to apply"
patch --strip=1 <$p || ynh_print_warn "Packagers /!\\ patch $p failed to apply"
done
popd
fi
@ -432,15 +432,15 @@ ynh_safe_rm() {
set +o xtrace # set +x
if [ $# -ge 2 ]; then
ynh_print_warn --message="/!\ Packager ! You provided more than one argument to ynh_safe_rm but it will be ignored... Use this helper with one argument at time."
ynh_print_warn "/!\ Packager ! You provided more than one argument to ynh_safe_rm but it will be ignored... Use this helper with one argument at time."
fi
if [[ -z "$target" ]]; then
ynh_print_warn --message="ynh_safe_rm called with empty argument, ignoring."
ynh_print_warn "ynh_safe_rm called with empty argument, ignoring."
elif [[ ! -e $target ]]; then
ynh_print_info --message="'$target' wasn't deleted because it doesn't exist."
ynh_print_info "'$target' wasn't deleted because it doesn't exist."
elif ! _acceptable_path_to_delete "$target"; then
ynh_print_warn --message="Not deleting '$target' because it is not an acceptable path to delete."
ynh_print_warn "Not deleting '$target' because it is not an acceptable path to delete."
else
rm --recursive "$target"
fi
@ -486,7 +486,7 @@ ynh_app_upstream_version_changed() {
# Requires YunoHost version 11.2 or higher.
ynh_app_upgrading_from_version_before() {
local version=$1
[[ $version =~ '~ynh' ]] || ynh_die --message="Invalid argument for version, should include the ~ynhX prefix"
[[ $version =~ '~ynh' ]] || ynh_die "Invalid argument for version, should include the ~ynhX prefix"
dpkg --compare-versions $YNH_APP_CURRENT_VERSION lt $version
}
@ -498,7 +498,7 @@ ynh_app_upgrading_from_version_before() {
# Requires YunoHost version 11.2 or higher.
ynh_app_upgrading_from_version_before_or_equal_to() {
local version=$1
[[ $version =~ '~ynh' ]] || ynh_die --message="Invalid argument for version, should include the ~ynhX prefix"
[[ $version =~ '~ynh' ]] || ynh_die "Invalid argument for version, should include the ~ynhX prefix"
dpkg --compare-versions $YNH_APP_CURRENT_VERSION le $version
}
@ -600,7 +600,7 @@ ynh_get_ram() {
# ===========================================
if [ $free -eq $total ]; then
ynh_print_warn --message="You have to choose --free or --total when using ynh_get_ram"
ynh_print_warn "You have to choose --free or --total when using ynh_get_ram"
ram=0
elif [ $free -eq 1 ]; then
local free_ram=$(LC_ALL=C vmstat --stats --unit M | grep "free memory" | awk '{print $1}')