From 57061b8e1db1171ddebf4f8a7ffdad25a1bb11f7 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sun, 19 Apr 2020 20:31:06 +0200 Subject: [PATCH] Unfold if-then when more than one line --- data/helpers.d/apt | 5 +++-- data/helpers.d/backup | 22 ++++++++++++++-------- data/helpers.d/fail2ban | 14 ++++++++------ data/helpers.d/getopts | 6 ++++-- data/helpers.d/logrotate | 15 ++++++++++----- data/helpers.d/mysql | 6 ++++-- data/helpers.d/nginx | 3 ++- data/helpers.d/php | 21 ++++++++++++++------- data/helpers.d/postgresql | 21 ++++++++++++++------- data/helpers.d/setting | 6 ++++-- data/helpers.d/systemd | 6 ++++-- data/helpers.d/user | 6 ++++-- data/helpers.d/utils | 35 ++++++++++++++++++++++------------- 13 files changed, 107 insertions(+), 59 deletions(-) diff --git a/data/helpers.d/apt b/data/helpers.d/apt index 4093e593f..a1eb6f470 100644 --- a/data/helpers.d/apt +++ b/data/helpers.d/apt @@ -78,7 +78,8 @@ ynh_package_version() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - if ynh_package_is_installed "$package"; then + if ynh_package_is_installed "$package" + then dpkg-query -W -f '${Version}' "$package" 2>/dev/null else echo '' @@ -251,7 +252,7 @@ ynh_install_app_dependencies () { # https://github.com/YunoHost/issues/issues/1407 # # If we require to install php dependency - if echo $dependencies | grep -q 'php'; + if echo $dependencies | grep -q 'php' then # And we have packages from sury installed (7.0.33-10+weirdshiftafter instead of 7.0.33-0 on debian) if dpkg --list | grep "php7.0" | grep -q -v "7.0.33-0+deb9" diff --git a/data/helpers.d/backup b/data/helpers.d/backup index bb676a0e0..096804380 100644 --- a/data/helpers.d/backup +++ b/data/helpers.d/backup @@ -64,7 +64,8 @@ ynh_backup() { # don't backup big data items if [ $is_big -eq 1 ] && ( [ ${do_not_backup_data:-0} -eq 1 ] || [ $BACKUP_CORE_ONLY -eq 1 ] ) then - if [ $BACKUP_CORE_ONLY -eq 1 ]; then + if [ $BACKUP_CORE_ONLY -eq 1 ] + then ynh_print_warn --message="$src_path will not be saved, because 'BACKUP_CORE_ONLY' is set." else ynh_print_warn --message="$src_path will not be saved, because 'do_not_backup_data' is set." @@ -100,12 +101,13 @@ ynh_backup() { # If there is no destination path, initialize it with the source path # relative to "/". # eg: src_path=/etc/yunohost -> dest_path=etc/yunohost - if [[ -z "$dest_path" ]]; then - + if [[ -z "$dest_path" ]] + then dest_path="${src_path#/}" else - if [[ "${dest_path:0:1}" == "/" ]]; then + if [[ "${dest_path:0:1}" == "/" ]] + then # If the destination path is an absolute path, transform it as a path # relative to the current working directory ($YNH_CWD) @@ -165,7 +167,8 @@ ynh_restore () { # For each destination path begining by $REL_DIR cat ${YNH_BACKUP_CSV} | tr -d $'\r' | grep -ohP "^\".*\",\"$REL_DIR.*\"$" | \ - while read line; do + while read line + do local ORIGIN_PATH=$(echo "$line" | grep -ohP "^\"\K.*(?=\",\".*\"$)") local ARCHIVE_PATH=$(echo "$line" | grep -ohP "^\".*\",\"$REL_DIR\K.*(?=\"$)") ynh_restore_file --origin_path="$ARCHIVE_PATH" --dest_path="$ORIGIN_PATH" @@ -234,7 +237,8 @@ ynh_restore_file () { local not_mandatory="${not_mandatory:-0}" # If archive_path doesn't exist, search for a corresponding path in CSV - if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ]; then + if [ ! -d "$archive_path" ] && [ ! -f "$archive_path" ] && [ ! -L "$archive_path" ] + then if [ "$not_mandatory" == "0" ] then archive_path="$YNH_BACKUP_DIR/$(_get_archive_path \"$origin_path\")" @@ -261,8 +265,10 @@ ynh_restore_file () { mkdir -p $(dirname "$dest_path") # Do a copy if it's just a mounting point - if mountpoint -q $YNH_BACKUP_DIR; then - if [[ -d "${archive_path}" ]]; then + if mountpoint -q $YNH_BACKUP_DIR + then + if [[ -d "${archive_path}" ]] + then archive_path="${archive_path}/." mkdir -p "$dest_path" fi diff --git a/data/helpers.d/fail2ban b/data/helpers.d/fail2ban index 2c17e1300..438b3b355 100644 --- a/data/helpers.d/fail2ban +++ b/data/helpers.d/fail2ban @@ -96,7 +96,8 @@ ynh_add_fail2ban_config () { fi # Replace all other variable given as arguments - for var_to_replace in ${others_var:-}; do + for var_to_replace in ${others_var:-} + do # ${var_to_replace^^} make the content of the variable on upper-cases # ${!var_to_replace} get the content of the variable named $var_to_replace ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalfail2banjailconf" @@ -104,11 +105,11 @@ ynh_add_fail2ban_config () { done else - # Usage 1, no template. Build a config file from scratch. - test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." - test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." + # Usage 1, no template. Build a config file from scratch. + test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." + test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." - tee $finalfail2banjailconf <$PSQL_ROOT_PWD_FILE - if [ -e /etc/postgresql/9.4/ ]; then + if [ -e /etc/postgresql/9.4/ ] + then local pg_hba=/etc/postgresql/9.4/main/pg_hba.conf local logfile=/var/log/postgresql/postgresql-9.4-main.log - elif [ -e /etc/postgresql/9.6/ ]; then + elif [ -e /etc/postgresql/9.6/ ] + then local pg_hba=/etc/postgresql/9.6/main/pg_hba.conf local logfile=/var/log/postgresql/postgresql-9.6-main.log else diff --git a/data/helpers.d/setting b/data/helpers.d/setting index 874ae44c1..eca529069 100644 --- a/data/helpers.d/setting +++ b/data/helpers.d/setting @@ -186,7 +186,8 @@ ynh_permission_create() { local allowed ynh_handle_getopts_args "$@" - if [[ -n ${url:-} ]]; then + if [[ -n ${url:-} ]] + then url="'$url'" else url="None" @@ -248,7 +249,8 @@ ynh_permission_url() { local url ynh_handle_getopts_args "$@" - if [[ -n ${url:-} ]]; then + if [[ -n ${url:-} ]] + then url="'$url'" else url="None" diff --git a/data/helpers.d/systemd b/data/helpers.d/systemd index 9ab3ff150..6257b9138 100644 --- a/data/helpers.d/systemd +++ b/data/helpers.d/systemd @@ -61,7 +61,8 @@ ynh_remove_systemd_config () { local service="${service:-$app}" local finalsystemdconf="/etc/systemd/system/$service.service" - if [ -e "$finalsystemdconf" ]; then + if [ -e "$finalsystemdconf" ] + then ynh_systemd_action --service_name=$service --action=stop systemctl disable $service ynh_secure_remove --file="$finalsystemdconf" @@ -103,7 +104,8 @@ ynh_systemd_action() { then local templog="$(mktemp)" # Following the starting of the app in its log - if [ "$log_path" == "systemd" ] ; then + if [ "$log_path" == "systemd" ] + then # Read the systemd journal journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" & # Get the PID of the journalctl command diff --git a/data/helpers.d/user b/data/helpers.d/user index 9d9bc9089..0b964c7c0 100644 --- a/data/helpers.d/user +++ b/data/helpers.d/user @@ -114,12 +114,14 @@ ynh_system_user_create () { if ! ynh_system_user_exists "$username" # Check if the user exists on the system then # If the user doesn't exist - if [ -n "$home_dir" ]; then # If a home dir is mentioned + if [ -n "$home_dir" ] + then # If a home dir is mentioned local user_home_dir="-d $home_dir" else local user_home_dir="--no-create-home" fi - if [ $use_shell -eq 1 ]; then # If we want a shell for the user + if [ $use_shell -eq 1 ] + then # If we want a shell for the user local shell="" # Use default shell else local shell="--shell /usr/sbin/nologin" diff --git a/data/helpers.d/utils b/data/helpers.d/utils index bdc8ee849..2ad05f93c 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -129,7 +129,7 @@ ynh_setup_source () { src_format=${src_format:-tar.gz} src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') src_extract=${src_extract:-true} - if [ "$src_filename" = "" ] ; then + if [ "$src_filename" = "" ]; then src_filename="${source_id}.${src_format}" fi local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}" @@ -155,7 +155,8 @@ ynh_setup_source () { then # Zip format # Using of a temp directory, because unzip doesn't manage --strip-components - if $src_in_subdir ; then + if $src_in_subdir + then local tmp_dir=$(mktemp -d) unzip -quo $src_filename -d "$tmp_dir" cp -a $tmp_dir/*/. "$dest_dir" @@ -167,14 +168,16 @@ ynh_setup_source () { local strip="" if [ "$src_in_subdir" != "false" ] then - if [ "$src_in_subdir" == "true" ]; then + if [ "$src_in_subdir" == "true" ] + then local sub_dirs=1 else local sub_dirs="$src_in_subdir" fi strip="--strip-components $sub_dirs" fi - if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]] ; then + if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]] + then tar -xf $src_filename -C "$dest_dir" $strip else ynh_die --message="Archive format unrecognized." @@ -321,7 +324,7 @@ ynh_secure_remove () { if [[ -z "$file" ]] then ynh_print_warn --message="ynh_secure_remove called with empty argument, ignoring." - else if [[ "$forbidden_path" =~ "$file" \ + elif [[ "$forbidden_path" =~ "$file" \ # Match all paths or subpaths in $forbidden_path || "$file" =~ ^/[[:alnum:]]+$ \ # Match all first level paths from / (Like /var, /root, etc...) @@ -329,12 +332,12 @@ ynh_secure_remove () { # Match if the path finishes by /. Because it seems there is an empty variable then ynh_print_warn --message="Not deleting '$file' because it is not an acceptable path to delete." - else if [ -e "$file" ] + elif [ -e "$file" ] then rm -R "$file" else ynh_print_info --message="'$file' wasn't deleted because it doesn't exist." - fi fi fi + fi } # Extract a key from a plain command output @@ -352,12 +355,16 @@ ynh_get_plain_key() { # an info to be redacted by the core local key_=$1 shift - while read line; do - if [[ "$founded" == "1" ]] ; then + while read line + do + if [[ "$founded" == "1" ]] + then [[ "$line" =~ ^${prefix}[^#] ]] && return echo $line - elif [[ "$line" =~ ^${prefix}${key_}$ ]]; then - if [[ -n "${1:-}" ]]; then + elif [[ "$line" =~ ^${prefix}${key_}$ ]] + then + if [[ -n "${1:-}" ]] + then prefix+="#" key_=$1 shift @@ -469,7 +476,8 @@ ynh_check_app_version_changed () { local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version" || echo 1.0) local update_upstream_version="$(ynh_app_upstream_version)" - if [ "$current_version" == "$update_version" ] ; then + if [ "$current_version" == "$update_version" ] + then # Complete versions are the same if [ "$force_upgrade" != "0" ] then @@ -481,7 +489,8 @@ ynh_check_app_version_changed () { else ynh_die "Up-to-date, nothing to do" 0 fi - elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then + elif [ "$current_upstream_version" == "$update_upstream_version" ] + then # Upstream versions are the same, only YunoHost package versions differ return_value="UPGRADE_PACKAGE" fi