helpers2.1: in fact, let's use positional args for ynh_safe_rm because having --target everywhere is boring as hell

This commit is contained in:
Alexandre Aubin 2024-06-10 22:48:04 +02:00
parent 50eea8fc14
commit 480366d5a1
12 changed files with 27 additions and 32 deletions

View file

@ -481,10 +481,10 @@ EOF
# Requires YunoHost version 3.8.1 or higher.
ynh_remove_extra_repo() {
ynh_safe_rm --target="/etc/apt/sources.list.d/$app.list"
ynh_safe_rm --target="/etc/apt/preferences.d/$app"
ynh_safe_rm "/etc/apt/sources.list.d/$app.list"
ynh_safe_rm "/etc/apt/preferences.d/$app"
if [ -e /etc/apt/trusted.gpg.d/$app.gpg ]; then
ynh_safe_rm --target="/etc/apt/trusted.gpg.d/$app.gpg"
ynh_safe_rm "/etc/apt/trusted.gpg.d/$app.gpg"
fi
ynh_package_update
}

View file

@ -205,7 +205,7 @@ ynh_restore() {
mkdir --parents "$(dirname "$backup_file")"
mv "${target}" "$backup_file" # Move the current file or directory
else
ynh_safe_rm --target=${target}
ynh_safe_rm "${target}"
fi
fi

View file

@ -76,7 +76,7 @@ _ynh_app_config_apply_one() {
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 --target="$bind_file"
ynh_safe_rm "$bind_file"
ynh_delete_file_checksum --file="$bind_file"
ynh_print_info --message="File '$bind_file' removed"
else

View file

@ -120,7 +120,7 @@ ignoreregex =
#
# Requires YunoHost version 3.5.0 or higher.
ynh_remove_fail2ban_config() {
ynh_safe_rm --target="/etc/fail2ban/jail.d/$app.conf"
ynh_safe_rm --target="/etc/fail2ban/filter.d/$app.conf"
ynh_safe_rm "/etc/fail2ban/jail.d/$app.conf"
ynh_safe_rm "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --service=fail2ban --action=reload
}

View file

@ -80,7 +80,7 @@ ynh_exec_and_print_stderr_only_if_error() {
"$@" 2> "$logfile" || rc="$?"
if (( rc != 0 )); then
ynh_exec_warn cat "$logfile"
ynh_safe_rm --target="$logfile"
ynh_safe_rm "$logfile"
return "$rc"
fi
}

View file

@ -265,7 +265,7 @@ ynh_remove_mongo() {
mongodb_servicename=mongod
# Remove the mongodb service
yunohost service remove $mongodb_servicename
ynh_safe_rm --target="/var/lib/mongodb"
ynh_safe_rm --target="/var/log/mongodb"
ynh_safe_rm "/var/lib/mongodb"
ynh_safe_rm "/var/log/mongodb"
fi
}

View file

@ -39,7 +39,7 @@ ynh_add_nginx_config() {
#
# Requires YunoHost version 2.7.2 or higher.
ynh_remove_nginx_config() {
ynh_safe_rm --target="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_safe_rm "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service=nginx --action=reload
}
@ -58,7 +58,7 @@ ynh_change_url_nginx_config() {
local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path"
ynh_delete_file_checksum --file="$old_nginx_conf_path"
ynh_safe_rm --target="$old_nginx_conf_path"
ynh_safe_rm "$old_nginx_conf_path"
# Regen the nginx conf
ynh_add_nginx_config

View file

@ -172,8 +172,8 @@ ynh_remove_nodejs() {
# If no other app uses n, remove n
if [ ! -s "$n_install_dir/ynh_app_version" ]; then
ynh_safe_rm --target="$n_install_dir"
ynh_safe_rm --target="/usr/local/n"
ynh_safe_rm "$n_install_dir"
ynh_safe_rm "/usr/local/n"
sed --in-place "/N_PREFIX/d" /root/.bashrc
rm --force /etc/cron.daily/node_update
fi

View file

@ -127,7 +127,7 @@ pm.process_idle_timeout = 10s
# Validate that the new php conf doesn't break php-fpm entirely
if ! php-fpm${phpversion} --test 2>/dev/null; then
php-fpm${phpversion} --test || true
ynh_safe_rm --target="$finalphpconf"
ynh_safe_rm "$finalphpconf"
ynh_die --message="The new configuration broke php-fpm?"
fi
ynh_systemd_action --service=$fpm_service --action=reload
@ -142,7 +142,7 @@ ynh_remove_fpm_config() {
local fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir)
local fpm_service=$(ynh_app_setting_get --key=fpm_service)
ynh_safe_rm --target="$fpm_config_dir/pool.d/$app.conf"
ynh_safe_rm "$fpm_config_dir/pool.d/$app.conf"
ynh_systemd_action --service=$fpm_service --action=reload
}

View file

@ -115,7 +115,7 @@ ynh_install_ruby () {
else
ynh_print_info --message="Reinstalling rbenv..."
cd ..
ynh_safe_rm --target=$rbenv_install_dir
ynh_safe_rm $rbenv_install_dir
mkdir -p $rbenv_install_dir
cd $rbenv_install_dir
git init -q
@ -284,8 +284,8 @@ ynh_cleanup_ruby () {
then
# Remove rbenv environment configuration
ynh_print_info --message="Removing rbenv"
ynh_safe_rm --target="$rbenv_install_dir"
ynh_safe_rm --target="/etc/profile.d/rbenv.sh"
ynh_safe_rm "$rbenv_install_dir"
ynh_safe_rm "/etc/profile.d/rbenv.sh"
fi
}

View file

@ -46,7 +46,7 @@ ynh_remove_systemd_config() {
if [ -e "$finalsystemdconf" ]; then
ynh_systemd_action --service=$service --action=stop
systemctl disable $service --quiet
ynh_safe_rm --target="$finalsystemdconf"
ynh_safe_rm "$finalsystemdconf"
systemctl daemon-reload
fi
}
@ -181,6 +181,6 @@ ynh_clean_check_starting() {
kill -SIGTERM $pid_tail 2>&1
fi
if [ -n "${templog:-}" ]; then
ynh_safe_rm --target="$templog" 2>&1
ynh_safe_rm "$templog" 2>&1
fi
}

View file

@ -259,7 +259,7 @@ ynh_setup_source() {
fi
if [ "$full_replace" -eq 1 ]; then
ynh_safe_rm --target="$dest_dir"
ynh_safe_rm "$dest_dir"
fi
# Extract source into the app dir
@ -285,11 +285,11 @@ ynh_setup_source() {
local tmp_dir=$(mktemp --directory)
unzip -quo $src_filename -d "$tmp_dir"
cp --archive $tmp_dir/*/. "$dest_dir"
ynh_safe_rm --target="$tmp_dir"
ynh_safe_rm "$tmp_dir"
else
unzip -quo $src_filename -d "$dest_dir"
fi
ynh_safe_rm --target="$src_filename"
ynh_safe_rm "$src_filename"
else
local strip=""
if [ "$src_in_subdir" != "false" ]; then
@ -305,7 +305,7 @@ ynh_setup_source() {
else
ynh_die --message="Archive format unrecognized."
fi
ynh_safe_rm --target="$src_filename"
ynh_safe_rm "$src_filename"
fi
# Apply patches
@ -429,16 +429,11 @@ _acceptable_path_to_delete() {
# Remove a file or a directory securely
#
# usage: ynh_safe_rm --target=path_to_remove
# | arg: -t, --target= - File or directory to remove
# usage: ynh_safe_rm path_to_remove
#
# Requires YunoHost version 2.6.4 or higher.
ynh_safe_rm() {
# ============ Argument parsing =============
local -A args_array=([t]=target=)
local target
ynh_handle_getopts_args "$@"
# ===========================================
local target="$1"
set +o xtrace # set +x
if [ $# -ge 2 ]; then