diff --git a/debian/changelog b/debian/changelog index 43ecb1e7f..56c320259 100644 --- a/debian/changelog +++ b/debian/changelog @@ -37,6 +37,20 @@ yunohost (12.0.0) unstable; urgency=low -- Alexandre Aubin Thu, 04 May 2023 20:30:19 +0200 +yunohost (11.2.30) stable; urgency=low + + - helpers v2.1: check if patches dir exists before getting realpath ([#1938](http://github.com/YunoHost/yunohost/pull/1938)) + - helpers v2.1: ynh_add_swap and ynh_smart_mktemp (aff885e6b) + - helpers v2.1: fix ynh_restore_everything ([#1943](http://github.com/YunoHost/yunohost/pull/1943)) + - helpers v2.1: fix typo in docs: ynh_install_app_dependencies -> ynh_apt_install_dependencies ([#1939](http://github.com/YunoHost/yunohost/pull/1939)) + - helpers: fix syntax, disambiguate subshell syntax ([#1940](http://github.com/YunoHost/yunohost/pull/1940)) + - quality: Add maintenante/shfmt.sh for shell script formatting (68f35831e) + - quality: Apply shfmt everywhere, fix tabs/space/indent (8a5f2808a, e3ddb1dc4, ef1708276, 38b39ebae, b91e9dd8f) + + Thanks to all contributors <3 ! (Félix Piédallu, Josué Tille, OniriCorpe, selfhoster1312) + + -- Alexandre Aubin Sat, 31 Aug 2024 19:26:59 +0200 + yunohost (11.2.29) stable; urgency=low - apps: generalize replacing __INSTALL_DIR__ and __APP__ in config panel 'bind' statement to any setting (9b0553580) diff --git a/helpers/helpers b/helpers/helpers index 10cefdcad..9b43cde13 100644 --- a/helpers/helpers +++ b/helpers/helpers @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Entrypoint for the helpers scripts -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) # Helpers version can be specified via an environment variable or default to 1. YNH_HELPERS_VERSION=${YNH_HELPERS_VERSION:-1} @@ -21,6 +21,7 @@ case "$YNH_HELPERS_VERSION" in *) echo "Helpers are not available in version '$YNH_HELPERS_VERSION'." >&2 exit 1 + ;; esac eval "$XTRACE_ENABLE" diff --git a/helpers/helpers.v1.d/apps b/helpers/helpers.v1.d/apps index 81a5717eb..f55552134 100644 --- a/helpers/helpers.v1.d/apps +++ b/helpers/helpers.v1.d/apps @@ -7,52 +7,49 @@ # # Requires YunoHost version *.*.* or higher. ynh_install_apps() { - # Declare an array to define the options of this helper. - local legacy_args=a - local -A args_array=([a]=apps=) - local apps - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=a + local -A args_array=([a]=apps=) + local apps + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Split the list of apps in an array - local apps_list=($(echo $apps | tr " " "\n")) - local apps_dependencies="" - - # For each app - for one_app_and_its_args in "${apps_list[@]}" - 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" + # Split the list of apps in an array + local apps_list=($(echo $apps | tr " " "\n")) + local apps_dependencies="" - yunohost tools update apps - - # Installing or upgrading the app depending if it's installed or not - if ! yunohost app list --output-as json --quiet | jq -e --arg id $one_app '.apps[] | select(.id == $id)' >/dev/null - then - # Retrieve the arguments of the app (part after ?) - local one_argument="" - if [[ "$one_app_and_its_args" == *"?"* ]]; then - one_argument=$(cut -d "?" -f2- <<< "$one_app_and_its_args") - one_argument="--args $one_argument" - fi - - # Install the app with its arguments - yunohost app install $one_app $one_argument - else - # Upgrade the app - yunohost app upgrade $one_app - fi + # For each app + for one_app_and_its_args in "${apps_list[@]}"; 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" - if [ ! -z "$apps_dependencies" ] - then - apps_dependencies="$apps_dependencies, $one_app" - else - apps_dependencies="$one_app" - fi - done + yunohost tools update apps - ynh_app_setting_set --app=$app --key=apps_dependencies --value="$apps_dependencies" + # Installing or upgrading the app depending if it's installed or not + if ! yunohost app list --output-as json --quiet | jq -e --arg id $one_app '.apps[] | select(.id == $id)' > /dev/null; then + # Retrieve the arguments of the app (part after ?) + local one_argument="" + if [[ "$one_app_and_its_args" == *"?"* ]]; then + one_argument=$(cut -d "?" -f2- <<< "$one_app_and_its_args") + one_argument="--args $one_argument" + fi + + # Install the app with its arguments + yunohost app install $one_app $one_argument + else + # Upgrade the app + yunohost app upgrade $one_app + fi + + if [ ! -z "$apps_dependencies" ]; then + apps_dependencies="$apps_dependencies, $one_app" + else + apps_dependencies="$one_app" + fi + done + + ynh_app_setting_set --app=$app --key=apps_dependencies --value="$apps_dependencies" } # Remove other YunoHost apps @@ -63,53 +60,47 @@ ynh_install_apps() { # # Requires YunoHost version *.*.* or higher. ynh_remove_apps() { - # Retrieve the apps dependencies of the app - local apps_dependencies=$(ynh_app_setting_get --app=$app --key=apps_dependencies) - ynh_app_setting_delete --app=$app --key=apps_dependencies + # Retrieve the apps dependencies of the app + local apps_dependencies=$(ynh_app_setting_get --app=$app --key=apps_dependencies) + ynh_app_setting_delete --app=$app --key=apps_dependencies - if [ ! -z "$apps_dependencies" ] - then - # Split the list of apps dependencies in an array - local apps_dependencies_list=($(echo $apps_dependencies | tr ", " "\n")) - - # For each apps dependencies - for one_app in "${apps_dependencies_list[@]}" - do - # Retrieve the list of installed apps - local installed_apps_list=$(yunohost app list --output-as json --quiet | jq -r .apps[].id) - local required_by="" - local installed_app_required_by="" + if [ ! -z "$apps_dependencies" ]; then + # Split the list of apps dependencies in an array + local apps_dependencies_list=($(echo $apps_dependencies | tr ", " "\n")) - # For each other installed app - for one_installed_app in $installed_apps_list - do - # Retrieve the other apps dependencies - one_installed_apps_dependencies=$(ynh_app_setting_get --app=$one_installed_app --key=apps_dependencies) - if [ ! -z "$one_installed_apps_dependencies" ] - then - one_installed_apps_dependencies_list=($(echo $one_installed_apps_dependencies | tr ", " "\n")) + # For each apps dependencies + for one_app in "${apps_dependencies_list[@]}"; do + # Retrieve the list of installed apps + local installed_apps_list=$(yunohost app list --output-as json --quiet | jq -r .apps[].id) + local required_by="" + local installed_app_required_by="" - # For each dependency of the other apps - for one_installed_app_dependency in "${one_installed_apps_dependencies_list[@]}" - do - if [[ $one_installed_app_dependency == $one_app ]]; then - required_by="$required_by $one_installed_app" - fi - done - fi - done + # For each other installed app + for one_installed_app in $installed_apps_list; do + # Retrieve the other apps dependencies + one_installed_apps_dependencies=$(ynh_app_setting_get --app=$one_installed_app --key=apps_dependencies) + if [ ! -z "$one_installed_apps_dependencies" ]; then + one_installed_apps_dependencies_list=($(echo $one_installed_apps_dependencies | tr ", " "\n")) - # If $one_app is no more required - if [[ -z "$required_by" ]] - then - # Remove $one_app - ynh_print_info --message="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}" - fi - done - fi + # For each dependency of the other apps + for one_installed_app_dependency in "${one_installed_apps_dependencies_list[@]}"; do + if [[ $one_installed_app_dependency == $one_app ]]; then + required_by="$required_by $one_installed_app" + fi + done + fi + done + + # If $one_app is no more required + if [[ -z "$required_by" ]]; then + # Remove $one_app + ynh_print_info --message="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}" + fi + done + fi } # Spawn a Bash shell with the app environment loaded @@ -126,90 +117,83 @@ ynh_remove_apps() { # from the app's service configuration file (defaults to $app.service, overridable by the packager with `service` setting). # If the app relies on a specific PHP version, then `php` will be aliased that version. The PHP command will also be appended with the `phpflags` settings. ynh_spawn_app_shell() { - # Declare an array to define the options of this helper. - local legacy_args=a - local -A args_array=([a]=app=) - local app - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=a + local -A args_array=([a]=app=) + local app + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Force Bash to be used to run this helper - if [[ ! $0 =~ \/?bash$ ]] - then - ynh_print_err --message="Please use Bash as shell" - exit 1 - fi + # Force Bash to be used to run this helper + if [[ ! $0 =~ \/?bash$ ]]; then + ynh_print_err --message="Please use Bash as shell" + exit 1 + fi - # Make sure the app is installed - 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" - exit 1 - fi + # Make sure the app is installed + 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" + 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" - 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" + exit 1 + fi - # Make sure the app has an install_dir setting - local install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) - if [ -z "$install_dir" ] - then - ynh_print_err --message="$app has no install_dir setting (does it use packaging format >=2?)" - exit 1 - fi + # Make sure the app has an install_dir setting + local install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) + if [ -z "$install_dir" ]; then + ynh_print_err --message="$app has no install_dir setting (does it use packaging format >=2?)" + exit 1 + fi - # Load the app's service name, or default to $app - local service=$(ynh_app_setting_get --app=$app --key=service) - [ -z "$service" ] && service=$app; + # Load the app's service name, or default to $app + local service=$(ynh_app_setting_get --app=$app --key=service) + [ -z "$service" ] && service=$app - # Export HOME variable - export HOME=$install_dir; + # Export HOME variable + export HOME=$install_dir - # Load the Environment variables from the app's service - local env_var=$(systemctl show $service.service -p "Environment" --value) - [ -n "$env_var" ] && export $env_var; + # Load the Environment variables from the app's service + local env_var=$(systemctl show $service.service -p "Environment" --value) + [ -n "$env_var" ] && export $env_var - # Force `php` to its intended version - # We use `eval`+`export` since `alias` is not propagated to subshells, even with `export` - local phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - local phpflags=$(ynh_app_setting_get --app=$app --key=phpflags) - if [ -n "$phpversion" ] - then - eval "php() { php${phpversion} ${phpflags} \"\$@\"; }" - export -f php - fi + # Force `php` to its intended version + # We use `eval`+`export` since `alias` is not propagated to subshells, even with `export` + local phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) + local phpflags=$(ynh_app_setting_get --app=$app --key=phpflags) + if [ -n "$phpversion" ]; then + eval "php() { php${phpversion} ${phpflags} \"\$@\"; }" + export -f php + fi - # Source the EnvironmentFiles from the app's service - local env_files=($(systemctl show $service.service -p "EnvironmentFiles" --value)) - if [ ${#env_files[*]} -gt 0 ] - then - # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. - set -a - for file in ${env_files[*]} - do - [[ $file = /* ]] && source $file - done - set +a - fi + # Source the EnvironmentFiles from the app's service + local env_files=($(systemctl show $service.service -p "EnvironmentFiles" --value)) + if [ ${#env_files[*]} -gt 0 ]; then + # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. + set -a + for file in ${env_files[*]}; do + [[ $file = /* ]] && source $file + done + set +a + fi - # Activate the Python environment, if it exists - if [ -f $install_dir/venv/bin/activate ] - then - # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. - set -a - source $install_dir/venv/bin/activate - set +a - fi + # Activate the Python environment, if it exists + if [ -f $install_dir/venv/bin/activate ]; then + # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. + set -a + source $install_dir/venv/bin/activate + set +a + fi - # cd into the WorkingDirectory set in the service, or default to the install_dir - local env_dir=$(systemctl show $service.service -p "WorkingDirectory" --value) - [ -z $env_dir ] && env_dir=$install_dir; - cd $env_dir + # cd into the WorkingDirectory set in the service, or default to the install_dir + local env_dir=$(systemctl show $service.service -p "WorkingDirectory" --value) + [ -z $env_dir ] && env_dir=$install_dir + cd $env_dir - # Spawn the app shell - su -s /bin/bash $app + # Spawn the app shell + su -s /bin/bash $app } diff --git a/helpers/helpers.v1.d/apt b/helpers/helpers.v1.d/apt index cd648438a..dbe5c057e 100644 --- a/helpers/helpers.v1.d/apt +++ b/helpers/helpers.v1.d/apt @@ -14,7 +14,7 @@ ynh_wait_dpkg_free() { # With seq 1 17, timeout will be almost 30 minutes for try in $(seq 1 17); do # Check if /var/lib/dpkg/lock is used by another process - if lsof /var/lib/dpkg/lock >/dev/null; then + if lsof /var/lib/dpkg/lock > /dev/null; then echo "apt is already in use..." # Sleep an exponential time at each round sleep $((try * try)) @@ -32,7 +32,7 @@ ynh_wait_dpkg_free() { set -o xtrace # set -x return 1 fi - done 9<<<"$(ls -1 $dpkg_dir)" + done 9<<< "$(ls -1 $dpkg_dir)" set -o xtrace # set -x return 0 fi @@ -58,8 +58,8 @@ ynh_package_is_installed() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - dpkg-query --show --showformat='${Status}' "$package" 2>/dev/null \ - | grep --count "ok installed" &>/dev/null + dpkg-query --show --showformat='${Status}' "$package" 2> /dev/null \ + | grep --count "ok installed" &> /dev/null } # Get the version of an installed package @@ -82,7 +82,7 @@ ynh_package_version() { ynh_handle_getopts_args "$@" if ynh_package_is_installed "$package"; then - dpkg-query --show --showformat='${Version}' "$package" 2>/dev/null + dpkg-query --show --showformat='${Version}' "$package" 2> /dev/null else echo '' fi @@ -266,8 +266,7 @@ ynh_install_app_dependencies() { # The (?<=php) syntax corresponds to lookbehind ;) local specific_php_version=$(echo $dependencies | grep -oP '(?<=php)[0-9.]+(?=-|\>|)' | sort -u) - if [[ -n "$specific_php_version" ]] - then + if [[ -n "$specific_php_version" ]]; 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" @@ -281,8 +280,7 @@ ynh_install_app_dependencies() { local old_php_fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir) local old_php_finalphpconf="$old_php_fpm_config_dir/pool.d/$app.conf" - if [[ -f "$old_php_finalphpconf" ]] - then + if [[ -f "$old_php_finalphpconf" ]]; then ynh_backup_if_checksum_is_different --file="$old_php_finalphpconf" ynh_remove_fpm_config fi @@ -291,8 +289,7 @@ ynh_install_app_dependencies() { ynh_app_setting_set --app=$app --key=phpversion --value=$specific_php_version # Set the default php version back as the default version for php-cli. - if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION - then + if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION; then update-alternatives --set php /usr/bin/php$YNH_DEFAULT_PHP_VERSION fi elif grep --quiet 'php' <<< "$dependencies"; then @@ -306,20 +303,18 @@ ynh_install_app_dependencies() { # upgrade script where ynh_install_app_dependencies is called with this # expected effect) Otherwise, any subsequent call will add dependencies # to those already present in the equivs control file. - if [[ $YNH_INSTALL_APP_DEPENDENCIES_REPLACE == "true" ]] - then + if [[ $YNH_INSTALL_APP_DEPENDENCIES_REPLACE == "true" ]]; then YNH_INSTALL_APP_DEPENDENCIES_REPLACE="false" else local current_dependencies="" - if ynh_package_is_installed --package="${dep_app}-ynh-deps" - then + if ynh_package_is_installed --package="${dep_app}-ynh-deps"; then current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " current_dependencies=${current_dependencies// | /|} fi dependencies="$current_dependencies, $dependencies" fi - cat >/tmp/${dep_app}-ynh-deps.control < /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build Section: misc Priority: optional Package: ${dep_app}-ynh-deps @@ -337,8 +332,7 @@ EOF # Trigger postgresql regenconf if we may have just installed postgresql local psql_installed2="$(ynh_package_is_installed "postgresql-$PSQL_VERSION" && echo yes || echo no)" - if [[ "$psql_installed" != "$psql_installed2" ]] - then + if [[ "$psql_installed" != "$psql_installed2" ]]; then yunohost tools regen-conf postgresql fi @@ -372,7 +366,7 @@ ynh_add_app_dependencies() { # # Requires YunoHost version 2.6.4 or higher. ynh_remove_app_dependencies() { - local dep_app=${app//_/-} # Replace all '_' by '-' + local dep_app=${app//_/-} # Replace all '_' by '-' local current_dependencies="" if ynh_package_is_installed --package="${dep_app}-ynh-deps"; then @@ -382,16 +376,14 @@ ynh_remove_app_dependencies() { # Edge case where the app dep may be on hold, # cf https://forum.yunohost.org/t/migration-error-cause-of-ffsync/20675/4 - if apt-mark showhold | grep -q -w ${dep_app}-ynh-deps - then + if apt-mark showhold | grep -q -w ${dep_app}-ynh-deps; then apt-mark unhold ${dep_app}-ynh-deps fi # Remove the fake package and its dependencies if they not still used. # (except if dpkg doesn't know anything about the package, # which should be symptomatic of a failed install, and we don't want bash to report an error) - if dpkg-query --show ${dep_app}-ynh-deps &>/dev/null - then + if dpkg-query --show ${dep_app}-ynh-deps &> /dev/null; then ynh_package_autopurge ${dep_app}-ynh-deps fi } @@ -487,11 +479,13 @@ ynh_install_extra_repo() { if [[ "${repo_parts[0]}" == "deb" ]]; then index=1 fi - uri="${repo_parts[$index]}" ; index=$((index+1)) - suite="${repo_parts[$index]}" ; index=$((index+1)) + uri="${repo_parts[$index]}" + index=$((index + 1)) + suite="${repo_parts[$index]}" + index=$((index + 1)) # Get the components - if (( "${#repo_parts[@]}" > 0 )); then + if (("${#repo_parts[@]}" > 0)); then component="${repo_parts[*]:$index}" fi @@ -512,7 +506,7 @@ ynh_install_extra_repo() { if [ -n "$key" ] && [[ "$key" != "trusted=yes" ]]; then mkdir --parents "/etc/apt/trusted.gpg.d" # Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget) - wget --timeout 900 --quiet "$key" --output-document=- | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg >/dev/null + wget --timeout 900 --quiet "$key" --output-document=- | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null fi # Update the list of package with the new repo diff --git a/helpers/helpers.v1.d/backup b/helpers/helpers.v1.d/backup index a596ac9e0..b05629aa3 100644 --- a/helpers/helpers.v1.d/backup +++ b/helpers/helpers.v1.d/backup @@ -162,7 +162,7 @@ ynh_backup() { # ============================================================================== local src=$(echo "${src_path}" | sed --regexp-extended 's/"/\"\"/g') local dest=$(echo "${dest_path}" | sed --regexp-extended 's/"/\"\"/g') - echo "\"${src}\",\"${dest}\"" >>"${YNH_BACKUP_CSV}" + echo "\"${src}\",\"${dest}\"" >> "${YNH_BACKUP_CSV}" # ============================================================================== @@ -289,8 +289,7 @@ ynh_restore_file() { # Boring hack for nginx conf file mapped to php7.3 # Note that there's no need to patch the fpm config because most php apps # will call "ynh_add_fpm_config" during restore, effectively recreating the file from scratch - if [[ "${dest_path}" == "/etc/nginx/conf.d/"* ]] && grep 'php7.3.*sock' "${dest_path}" - then + if [[ "${dest_path}" == "/etc/nginx/conf.d/"* ]] && grep 'php7.3.*sock' "${dest_path}"; then sed -i 's/php7.3/php7.4/g' "${dest_path}" fi } @@ -376,8 +375,7 @@ ynh_backup_if_checksum_is_different() { 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 + if test -e /var/cache/yunohost/appconfbackup/original_${file_path_base64}; then 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 @@ -412,7 +410,7 @@ ynh_delete_file_checksum() { # ynh_backup_archive_exists() { yunohost backup list --output-as json --quiet \ - | jq -e --arg archive "$1" '.archives | index($archive)' >/dev/null + | jq -e --arg archive "$1" '.archives | index($archive)' > /dev/null } # Make a backup in case of failed upgrade @@ -455,7 +453,7 @@ ynh_backup_before_upgrade() { # If the backup succeeded, remove the previous backup if ynh_backup_archive_exists "$app_bck-pre-upgrade$old_backup_number"; then # Remove the previous backup only if it exists - yunohost backup delete $app_bck-pre-upgrade$old_backup_number >/dev/null + yunohost backup delete $app_bck-pre-upgrade$old_backup_number > /dev/null fi else ynh_die --message="Backup failed, the upgrade process was aborted." @@ -494,8 +492,7 @@ ynh_restore_upgradebackup() { yunohost app remove $app # Restore the backup yunohost backup restore $app_bck-pre-upgrade$backup_number --apps $app --force --debug - if [[ -d /etc/yunohost/apps/$app ]] - then + if [[ -d /etc/yunohost/apps/$app ]]; then ynh_die --message="The app was restored to the way it was before the failed upgrade." else ynh_die --message="Uhoh ... Yunohost failed to restore the app to the way it was before the failed upgrade :|" diff --git a/helpers/helpers.v1.d/config b/helpers/helpers.v1.d/config index e36897d82..b0e7863b9 100644 --- a/helpers/helpers.v1.d/config +++ b/helpers/helpers.v1.d/config @@ -6,11 +6,11 @@ _ynh_app_config_get_one() { local bind="$3" local getter="get__${short_setting}" # Get value from getter if exists - if type -t $getter 2>/dev/null | grep -q '^function$' 2>/dev/null; then + if type -t $getter 2> /dev/null | grep -q '^function$' 2> /dev/null; then old[$short_setting]="$($getter)" formats[${short_setting}]="yaml" - elif [[ "$bind" == *"("* ]] && type -t "get__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + elif [[ "$bind" == *"("* ]] && type -t "get__${bind%%(*}" 2> /dev/null | grep -q '^function$' 2> /dev/null; then old[$short_setting]="$("get__${bind%%(*}" $short_setting $type $bind)" formats[${short_setting}]="yaml" @@ -22,7 +22,7 @@ _ynh_app_config_get_one() { if [[ "$bind" == "settings" ]]; then ynh_die --message="File '${short_setting}' can't be stored in settings" fi - old[$short_setting]="$(ls "$bind" 2>/dev/null || echo YNH_NULL)" + old[$short_setting]="$(ls "$bind" 2> /dev/null || echo YNH_NULL)" file_hash[$short_setting]="true" # Get multiline text from settings or from a full file @@ -32,7 +32,7 @@ _ynh_app_config_get_one() { 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" else - old[$short_setting]="$(cat "$bind" 2>/dev/null || echo YNH_NULL)" + old[$short_setting]="$(cat "$bind" 2> /dev/null || echo YNH_NULL)" fi # Get value from a kind of key/value file @@ -59,10 +59,10 @@ _ynh_app_config_apply_one() { local type="${types[$short_setting]}" if [ "${changed[$short_setting]}" == "true" ]; then # Apply setter if exists - if type -t $setter 2>/dev/null | grep -q '^function$' 2>/dev/null; then + if type -t $setter 2> /dev/null | grep -q '^function$' 2> /dev/null; then $setter - elif [[ "$bind" == *"("* ]] && type -t "set__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + elif [[ "$bind" == *"("* ]] && type -t "set__${bind%%(*}" 2> /dev/null | grep -q '^function$' 2> /dev/null; then "set__${bind%%(*}" $short_setting $type $bind elif [[ "$bind" == "null" ]]; then @@ -100,7 +100,7 @@ _ynh_app_config_apply_one() { fi local bind_file="$bind" ynh_backup_if_checksum_is_different --file="$bind_file" - echo "${!short_setting}" >"$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}'" @@ -130,7 +130,7 @@ _ynh_app_config_apply_one() { _ynh_app_config_get() { for line in $YNH_APP_CONFIG_PANEL_OPTIONS_TYPES_AND_BINDS; do # Split line into short_setting, type and bind - IFS='|' read short_setting type bind <<<"$line" + IFS='|' read short_setting type bind <<< "$line" binds[${short_setting}]="$bind" types[${short_setting}]="$type" file_hash[${short_setting}]="" @@ -206,9 +206,9 @@ _ynh_app_config_validate() { for short_setting in "${!old[@]}"; do [[ "${changed[$short_setting]}" == "false" ]] && continue local result="" - if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null; then + if type -t validate__$short_setting | grep -q '^function$' 2> /dev/null; then result="$(validate__$short_setting)" - elif [[ "$bind" == *"("* ]] && type -t "validate__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + elif [[ "$bind" == *"("* ]] && type -t "validate__${bind%%(*}" 2> /dev/null | grep -q '^function$' 2> /dev/null; then "validate__${bind%%(*}" $short_setting fi if [ -n "$result" ]; then @@ -263,7 +263,7 @@ ynh_app_config_apply() { ynh_app_action_run() { local runner="run__$1" # Get value from getter if exists - if type -t "$runner" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + if type -t "$runner" 2> /dev/null | grep -q '^function$' 2> /dev/null; then $runner #ynh_return "result:" #ynh_return "$(echo "${result}" | sed 's/^/ /g')" @@ -281,22 +281,23 @@ ynh_app_config_run() { declare -Ag formats=() case $1 in - show) - ynh_app_config_get - ynh_app_config_show - ;; - apply) - max_progression=4 - ynh_script_progression --message="Reading config panel description and current configuration..." - ynh_app_config_get + show) + ynh_app_config_get + ynh_app_config_show + ;; + apply) + max_progression=4 + ynh_script_progression --message="Reading config panel description and current configuration..." + ynh_app_config_get - ynh_app_config_validate + ynh_app_config_validate - ynh_script_progression --message="Applying the new configuration..." - ynh_app_config_apply - ynh_script_progression --message="Configuration of $app completed" --last - ;; - *) - ynh_app_action_run $1 + ynh_script_progression --message="Applying the new configuration..." + ynh_app_config_apply + ynh_script_progression --message="Configuration of $app completed" --last + ;; + *) + ynh_app_action_run $1 + ;; esac } diff --git a/helpers/helpers.v1.d/fail2ban b/helpers/helpers.v1.d/fail2ban index 3b05c907a..548989e5f 100644 --- a/helpers/helpers.v1.d/fail2ban +++ b/helpers/helpers.v1.d/fail2ban @@ -82,7 +82,7 @@ port = __PORTS__ filter = __APP__ logpath = __LOGPATH__ maxretry = __MAX_RETRY__ -" >"$YNH_APP_BASEDIR/conf/f2b_jail.conf" +" > "$YNH_APP_BASEDIR/conf/f2b_jail.conf" echo " [INCLUDES] @@ -90,7 +90,7 @@ before = common.conf [Definition] failregex = __FAILREGEX__ ignoreregex = -" >"$YNH_APP_BASEDIR/conf/f2b_filter.conf" +" > "$YNH_APP_BASEDIR/conf/f2b_filter.conf" fi ynh_add_config --template="f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf" diff --git a/helpers/helpers.v1.d/getopts b/helpers/helpers.v1.d/getopts index f9ef5dc0b..63c0084cf 100644 --- a/helpers/helpers.v1.d/getopts +++ b/helpers/helpers.v1.d/getopts @@ -20,7 +20,7 @@ # | arg: $@ - Simply "$@" to tranfert all the positionnal arguments to the function # # This helper need an array, named "args_array" with all the arguments used by the helper -# that want to use ynh_handle_getopts_args +# that want to use ynh_handle_getopts_args # Be carreful, this array has to be an associative array, as the following example: # local -A args_array=( [a]=arg1 [b]=arg2= [c]=arg3 ) # Let's explain this array: @@ -180,7 +180,7 @@ ynh_handle_getopts_args() { # If not, enter in legacy mode and manage the arguments as positionnal ones.. # Dot not echo, to prevent to go through a helper output. But print only in the log. set -x - echo "! Helper used in legacy mode !" >/dev/null + echo "! Helper used in legacy mode !" > /dev/null set +x local i for i in $(seq 0 $((${#arguments[@]} - 1))); do diff --git a/helpers/helpers.v1.d/go b/helpers/helpers.v1.d/go index 86b2b83a8..ce74c48dc 100644 --- a/helpers/helpers.v1.d/go +++ b/helpers/helpers.v1.d/go @@ -1,11 +1,11 @@ #!/bin/bash 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." - } - fi + 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." + } + fi } goenv_install_dir="/opt/goenv" @@ -51,7 +51,7 @@ export GOENV_ROOT="$goenv_install_dir" # usage: ynh_use_go # # Requires YunoHost version 3.2.2 or higher. -ynh_use_go () { +ynh_use_go() { go_version=$(ynh_app_setting_get --app=$app --key=go_version) # Get the absolute path of this version of Go @@ -73,7 +73,7 @@ ynh_use_go () { # Sets the local application-specific Go version pushd $install_dir - $goenv_install_dir/bin/goenv local $go_version + $goenv_install_dir/bin/goenv local $go_version popd } @@ -93,10 +93,10 @@ ynh_use_go () { # | arg: -v, --go_version= - Version of go to install. # # Requires YunoHost version 3.2.2 or higher. -ynh_install_go () { +ynh_install_go() { # Declare an array to define the options of this helper. local legacy_args=v - local -A args_array=( [v]=go_version= ) + local -A args_array=([v]=go_version=) local go_version # Manage arguments with getopts ynh_handle_getopts_args "$@" @@ -113,34 +113,34 @@ ynh_install_go () { # Install or update goenv mkdir -p $goenv_install_dir pushd "$goenv_install_dir" - if ! [ -x "$goenv_install_dir/bin/goenv" ]; then - ynh_print_info --message="Downloading goenv..." - git init -q - git remote add origin https://github.com/syndbg/goenv.git - else - ynh_print_info --message="Updating goenv..." - fi - git fetch -q --tags --prune origin - local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") - git checkout -q "$git_latest_tag" - ynh_go_try_bash_extension - goenv=$goenv_install_dir/bin/goenv + if ! [ -x "$goenv_install_dir/bin/goenv" ]; then + ynh_print_info --message="Downloading goenv..." + git init -q + git remote add origin https://github.com/syndbg/goenv.git + else + ynh_print_info --message="Updating goenv..." + fi + git fetch -q --tags --prune origin + local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") + git checkout -q "$git_latest_tag" + ynh_go_try_bash_extension + goenv=$goenv_install_dir/bin/goenv popd # Install or update xxenv-latest goenv_latest_dir="$goenv_install_dir/plugins/xxenv-latest" mkdir -p "$goenv_latest_dir" pushd "$goenv_latest_dir" - if ! [ -x "$goenv_latest_dir/bin/goenv-latest" ]; then - ynh_print_info --message="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..." - fi - git fetch -q --tags --prune origin - local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") - git checkout -q "$git_latest_tag" + if ! [ -x "$goenv_latest_dir/bin/goenv-latest" ]; then + ynh_print_info --message="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..." + fi + git fetch -q --tags --prune origin + local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") + git checkout -q "$git_latest_tag" popd # Enable caching @@ -167,7 +167,7 @@ ynh_install_go () { ynh_cleanup_go # Set environment for Go users - echo "#goenv + echo "#goenv export GOENV_ROOT=$goenv_install_dir export PATH=\"$goenv_install_dir/bin:$PATH\" eval \"\$(goenv init -)\" @@ -182,7 +182,7 @@ eval \"\$(goenv init -)\" # This helper will also cleanup Go versions # # usage: ynh_remove_go -ynh_remove_go () { +ynh_remove_go() { local go_version=$(ynh_app_setting_get --app="$app" --key="go_version") # Load goenv path in PATH @@ -205,34 +205,29 @@ ynh_remove_go () { # If no app uses Go, goenv will be also removed. # # usage: ynh_cleanup_go -ynh_cleanup_go () { +ynh_cleanup_go() { # List required Go versions local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id) local required_go_versions="" - for installed_app in $installed_apps - do + for installed_app in $installed_apps; do local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") - if [[ $installed_app_go_version ]] - then + if [[ $installed_app_go_version ]]; then required_go_versions="${installed_app_go_version}\n${required_go_versions}" fi done # Remove no more needed Go versions local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/') - for installed_go_version in $installed_go_versions - do - if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1` - then + for installed_go_version in $installed_go_versions; 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" $goenv_install_dir/bin/goenv uninstall --force "$installed_go_version" fi done # If none Go version is required - if [[ ! $required_go_versions ]] - then + if [[ ! $required_go_versions ]]; then # Remove goenv environment configuration ynh_print_info --message="Removing of goenv" ynh_secure_remove --file="$goenv_install_dir" diff --git a/helpers/helpers.v1.d/logging b/helpers/helpers.v1.d/logging index accb8f9b0..f7873928c 100644 --- a/helpers/helpers.v1.d/logging +++ b/helpers/helpers.v1.d/logging @@ -93,8 +93,7 @@ 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 + 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 @@ -114,8 +113,7 @@ 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 + 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 @@ -135,8 +133,7 @@ ynh_exec_warn_less() { # 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 + if [[ "$#" -eq 1 ]] && [[ "$1" == *" "* ]]; then eval $@ 2>&1 else # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 @@ -156,8 +153,7 @@ 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 + if [[ "$#" -eq 1 ]] && [[ "$1" == *" "* ]]; then eval $@ > /dev/null else # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 @@ -177,8 +173,7 @@ 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 + 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 @@ -199,7 +194,7 @@ ynh_exec_and_print_stderr_only_if_error() { rc=0 # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 "$@" 2> "$logfile" || rc="$?" - if (( rc != 0 )); then + if ((rc != 0)); then ynh_exec_warn cat "$logfile" ynh_secure_remove "$logfile" return "$rc" @@ -216,7 +211,7 @@ ynh_exec_and_print_stderr_only_if_error() { # # Requires YunoHost version 3.2.0 or higher. ynh_print_OFF() { - exec {BASH_XTRACEFD}>/dev/null + exec {BASH_XTRACEFD}> /dev/null } # Restore the logging after ynh_print_OFF @@ -229,7 +224,7 @@ ynh_print_OFF() { 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 + echo ynh_print_ON > /dev/null } # Initial definitions for ynh_script_progression @@ -271,9 +266,9 @@ ynh_script_progression() { # Always activate time when running inside CI tests if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then - time=${time:-1} + time=${time:-1} else - time=${time:-0} + time=${time:-0} fi last=${last:-0} @@ -298,8 +293,8 @@ ynh_script_progression() { 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 + # Less the number of calls with a weight value. + # Plus the total of weight values max_progression=$(($helper_calls - $weight_calls + $weight_values)) fi @@ -329,7 +324,7 @@ ynh_script_progression() { local print_exec_time="" if [ $time -eq 1 ] && [ "$exec_time" -gt 10 ]; then - print_exec_time=" [$(bc <<< "scale=1; $exec_time / 60" ) minutes]" + print_exec_time=" [$(bc <<< "scale=1; $exec_time / 60") minutes]" fi ynh_print_info "[$progression_bar] > ${message}${print_exec_time}" @@ -343,5 +338,5 @@ ynh_script_progression() { # # Requires YunoHost version 3.6.0 or higher. ynh_return() { - echo "$1" >>"$YNH_STDRETURN" + echo "$1" >> "$YNH_STDRETURN" } diff --git a/helpers/helpers.v1.d/logrotate b/helpers/helpers.v1.d/logrotate index efc1137c1..1be98d220 100644 --- a/helpers/helpers.v1.d/logrotate +++ b/helpers/helpers.v1.d/logrotate @@ -16,11 +16,9 @@ ynh_use_logrotate() { # Stupid patch to ignore legacy --non-append and --nonappend # which was never properly understood and improperly used and kind of bullshit - local all_args=( ${@} ) - for I in $(seq 0 $(($# - 1))) - do - if [[ "${all_args[$I]}" == "--non-append" ]] || [[ "${all_args[$I]}" == "--nonappend" ]] - then + local all_args=(${@}) + for I in $(seq 0 $(($# - 1))); do + if [[ "${all_args[$I]}" == "--non-append" ]] || [[ "${all_args[$I]}" == "--nonappend" ]]; then unset all_args[$I] fi done @@ -43,8 +41,7 @@ ynh_use_logrotate() { fi set +o noglob - for stuff in $logfile - do + for stuff in $logfile; do mkdir --parents $(dirname "$stuff") done @@ -54,7 +51,7 @@ ynh_use_logrotate() { fi local tempconf="$(mktemp)" - cat << EOF >$tempconf + cat << EOF > $tempconf $logfile { # Rotate if the logfile exceeds 100Mo size 100M @@ -76,8 +73,7 @@ $logfile { } EOF - if [[ "$FIRST_CALL_TO_LOGROTATE" == "true" ]] - then + if [[ "$FIRST_CALL_TO_LOGROTATE" == "true" ]]; then cat $tempconf > /etc/logrotate.d/$app else cat $tempconf >> /etc/logrotate.d/$app diff --git a/helpers/helpers.v1.d/mongodb b/helpers/helpers.v1.d/mongodb index 8736aad31..1e8dc944b 100644 --- a/helpers/helpers.v1.d/mongodb +++ b/helpers/helpers.v1.d/mongodb @@ -6,100 +6,92 @@ # example: ynh_mongo_exec --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # # usage: ynh_mongo_exec [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" [--eval] -# | arg: -u, --user= - The user name to connect as -# | arg: -p, --password= - The user password -# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to -# | arg: -d, --database= - The database to connect to -# | arg: -h, --host= - The host to connect to -# | arg: -P, --port= - The port to connect to -# | arg: -c, --command= - The command to evaluate -# | arg: -e, --eval - Evaluate instead of execute the command. +# | arg: -u, --user= - The user name to connect as +# | arg: -p, --password= - The user password +# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to +# | arg: -d, --database= - The database to connect to +# | arg: -h, --host= - The host to connect to +# | arg: -P, --port= - The port to connect to +# | arg: -c, --command= - The command to evaluate +# | arg: -e, --eval - Evaluate instead of execute the command. # # ynh_mongo_exec() { - # Declare an array to define the options of this helper. - local legacy_args=upadhPce - local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval ) - local user - local password - local authenticationdatabase - local database - local host - local port - local command - local eval - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - user="${user:-}" - password="${password:-}" - authenticationdatabase="${authenticationdatabase:-}" - database="${database:-}" - host="${host:-}" - port="${port:-}" - eval=${eval:-0} + # Declare an array to define the options of this helper. + local legacy_args=upadhPce + local -A args_array=([u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval) + local user + local password + local authenticationdatabase + local database + local host + local port + local command + local eval + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + user="${user:-}" + password="${password:-}" + authenticationdatabase="${authenticationdatabase:-}" + database="${database:-}" + host="${host:-}" + port="${port:-}" + eval=${eval:-0} - # If user is provided - if [ -n "$user" ] - then - user="--username=$user" + # If user is provided + if [ -n "$user" ]; then + user="--username=$user" - # If password is provided - if [ -n "$password" ] - then - password="--password=$password" - fi + # If password is provided + if [ -n "$password" ]; then + password="--password=$password" + fi - # If authenticationdatabase is provided - if [ -n "$authenticationdatabase" ] - then - authenticationdatabase="--authenticationDatabase=$authenticationdatabase" - else - authenticationdatabase="--authenticationDatabase=admin" - fi - else - password="" - authenticationdatabase="" - fi + # If authenticationdatabase is provided + if [ -n "$authenticationdatabase" ]; then + authenticationdatabase="--authenticationDatabase=$authenticationdatabase" + else + authenticationdatabase="--authenticationDatabase=admin" + fi + else + password="" + authenticationdatabase="" + fi - # If host is provided - if [ -n "$host" ] - then - host="--host=$host" - fi + # If host is provided + if [ -n "$host" ]; then + host="--host=$host" + fi - # If port is provided - if [ -n "$port" ] - then - port="--port=$port" - fi + # If port is provided + if [ -n "$port" ]; then + port="--port=$port" + fi - # If eval is not provided - if [ $eval -eq 0 ] - then - # If database is provided - if [ -n "$database" ] - then - database="use $database" - else - database="" - fi + # If eval is not provided + if [ $eval -eq 0 ]; then + # If database is provided + if [ -n "$database" ]; then + database="use $database" + else + database="" + fi - mongosh --quiet --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port < ./dump.bson # # usage: ynh_mongo_dump_db --database=database -# | arg: -d, --database= - The database name to dump +# | arg: -d, --database= - The database name to dump # | ret: the mongodump output # # ynh_mongo_dump_db() { - # Declare an array to define the options of this helper. - local legacy_args=d - local -A args_array=( [d]=database= ) - local database - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=d + local -A args_array=([d]=database=) + local database + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - mongodump --quiet --db="$database" --archive + mongodump --quiet --db="$database" --archive } # Create a user @@ -149,49 +141,48 @@ ynh_mongo_dump_db() { # [internal] # # usage: ynh_mongo_create_user --db_user=user --db_pwd=pwd --db_name=name -# | arg: -u, --db_user= - The user name to create -# | arg: -p, --db_pwd= - The password to identify user by -# | arg: -n, --db_name= - Name of the database to grant privilegies +# | arg: -u, --db_user= - The user name to create +# | arg: -p, --db_pwd= - The password to identify user by +# | arg: -n, --db_name= - Name of the database to grant privilegies # # ynh_mongo_create_user() { - # Declare an array to define the options of this helper. - local legacy_args=unp - local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= ) - local db_user - local db_name - local db_pwd - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=unp + local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=) + local db_user + local db_name + local db_pwd + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Create the user and set the user as admin of the db - ynh_mongo_exec --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' + # Create the user and set the user as admin of the db + ynh_mongo_exec --database="$db_name" --command='db.createUser( { user: "'${db_user}'", pwd: "'${db_pwd}'", roles: [ { role: "readWrite", db: "'${db_name}'" } ] } );' - # Add clustermonitoring rights - ynh_mongo_exec --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' + # Add clustermonitoring rights + ynh_mongo_exec --database="$db_name" --command='db.grantRolesToUser("'${db_user}'",[{ role: "clusterMonitor", db: "admin" }]);' } # Check if a mongo database exists # # usage: ynh_mongo_database_exists --database=database -# | arg: -d, --database= - The database for which to check existence +# | arg: -d, --database= - The database for which to check existence # | exit: Return 1 if the database doesn't exist, 0 otherwise # # ynh_mongo_database_exists() { - # Declare an array to define the options of this helper. - local legacy_args=d - local -A args_array=([d]=database=) - local database - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=d + local -A args_array=([d]=database=) + local database + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")' --eval) -lt 0 ] - then - return 1 - else - return 0 - fi + if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")' --eval) -lt 0 ]; then + return 1 + else + return 0 + fi } # Restore a database @@ -199,18 +190,18 @@ ynh_mongo_database_exists() { # example: ynh_mongo_restore_db --database=wekan < ./dump.bson # # usage: ynh_mongo_restore_db --database=database -# | arg: -d, --database= - The database name to restore +# | arg: -d, --database= - The database name to restore # # ynh_mongo_restore_db() { - # Declare an array to define the options of this helper. - local legacy_args=d - local -A args_array=( [d]=database= ) - local database - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=d + local -A args_array=([d]=database=) + local database + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - mongorestore --quiet --db="$database" --archive + mongorestore --quiet --db="$database" --archive } # Drop a user @@ -218,120 +209,120 @@ ynh_mongo_restore_db() { # [internal] # # usage: ynh_mongo_drop_user --db_user=user --db_name=name -# | arg: -u, --db_user= - The user to drop -# | arg: -n, --db_name= - Name of the database +# | arg: -u, --db_user= - The user to drop +# | arg: -n, --db_name= - Name of the database # # ynh_mongo_drop_user() { - # Declare an array to define the options of this helper. - local legacy_args=un - local -A args_array=( [u]=db_user= [n]=db_name= ) - local db_user - local db_name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=un + local -A args_array=([u]=db_user= [n]=db_name=) + local db_user + local db_name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - ynh_mongo_exec --database="$db_name" --command='db.dropUser("'$db_user'", {w: "majority", wtimeout: 5000})' + ynh_mongo_exec --database="$db_name" --command='db.dropUser("'$db_user'", {w: "majority", wtimeout: 5000})' } # Create a database, an user and its password. Then store the password in the app's config # # usage: ynh_mongo_setup_db --db_user=user --db_name=name [--db_pwd=pwd] -# | arg: -u, --db_user= - Owner of the database -# | arg: -n, --db_name= - Name of the database -# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated +# | arg: -u, --db_user= - Owner of the database +# | arg: -n, --db_name= - Name of the database +# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated # # After executing this helper, the password of the created database will be available in $db_pwd # It will also be stored as "mongopwd" into the app settings. # # ynh_mongo_setup_db() { - # Declare an array to define the options of this helper. - local legacy_args=unp - local -A args_array=( [u]=db_user= [n]=db_name= [p]=db_pwd= ) - local db_user - local db_name - db_pwd="" - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=unp + local -A args_array=([u]=db_user= [n]=db_name= [p]=db_pwd=) + local db_user + local db_name + db_pwd="" + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - local new_db_pwd=$(ynh_string_random) # Generate a random password - # If $db_pwd is not provided, use new_db_pwd instead for db_pwd - db_pwd="${db_pwd:-$new_db_pwd}" + local new_db_pwd=$(ynh_string_random) # Generate a random password + # If $db_pwd is not provided, use new_db_pwd instead for db_pwd + db_pwd="${db_pwd:-$new_db_pwd}" - # Create the user and grant access to the database - ynh_mongo_create_user --db_user="$db_user" --db_pwd="$db_pwd" --db_name="$db_name" + # Create the user and grant access to the database + ynh_mongo_create_user --db_user="$db_user" --db_pwd="$db_pwd" --db_name="$db_name" - # Store the password in the app's config - ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd + # Store the password in the app's config + ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd } # Remove a database if it exists, and the associated user # # usage: ynh_mongo_remove_db --db_user=user --db_name=name -# | arg: -u, --db_user= - Owner of the database -# | arg: -n, --db_name= - Name of the database +# | arg: -u, --db_user= - Owner of the database +# | arg: -n, --db_name= - Name of the database # # ynh_mongo_remove_db() { - # Declare an array to define the options of this helper. - local legacy_args=un - local -A args_array=( [u]=db_user= [n]=db_name= ) - local db_user - local db_name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=un + local -A args_array=([u]=db_user= [n]=db_name=) + local db_user + local db_name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - 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" - fi + 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" + fi - # Remove mongo user if it exists - ynh_mongo_drop_user --db_user=$db_user --db_name=$db_name + # Remove mongo user if it exists + ynh_mongo_drop_user --db_user=$db_user --db_name=$db_name } # Install MongoDB and integrate MongoDB service in YunoHost # # usage: ynh_install_mongo [--mongo_version=mongo_version] -# | arg: -m, --mongo_version= - Version of MongoDB to install +# | arg: -m, --mongo_version= - Version of MongoDB to install # # ynh_install_mongo() { - # Declare an array to define the options of this helper. - local legacy_args=m - local -A args_array=([m]=mongo_version=) - local mongo_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - mongo_version="${mongo_version:-$YNH_MONGO_VERSION}" + # Declare an array to define the options of this helper. + local legacy_args=m + local -A args_array=([m]=mongo_version=) + local mongo_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + mongo_version="${mongo_version:-$YNH_MONGO_VERSION}" - ynh_print_info --message="Installing MongoDB Community Edition ..." - local mongo_debian_release=$(ynh_get_debian_release) + ynh_print_info --message="Installing MongoDB Community Edition ..." + local mongo_debian_release=$(ynh_get_debian_release) if [[ "$(grep '^flags' /proc/cpuinfo | uniq)" != *"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)." - 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." - mongo_debian_release=buster - fi + 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)." + 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." + mongo_debian_release=buster + fi - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian $mongo_debian_release/mongodb-org/$mongo_version main" --package="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh" --key="https://www.mongodb.org/static/pgp/server-$mongo_version.asc" - mongodb_servicename=mongod + ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian $mongo_debian_release/mongodb-org/$mongo_version main" --package="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh" --key="https://www.mongodb.org/static/pgp/server-$mongo_version.asc" + mongodb_servicename=mongod - # Make sure MongoDB is started and enabled - systemctl enable $mongodb_servicename --quiet - systemctl daemon-reload --quiet - ynh_systemd_action --service_name=$mongodb_servicename --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log" + # Make sure MongoDB is started and enabled + systemctl enable $mongodb_servicename --quiet + systemctl daemon-reload --quiet + ynh_systemd_action --service_name=$mongodb_servicename --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log" - # Integrate MongoDB service in YunoHost - yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log" + # Integrate MongoDB service in YunoHost + yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log" - # Store mongo_version into the config of this app - ynh_app_setting_set --app=$app --key=mongo_version --value=$mongo_version + # Store mongo_version into the config of this app + ynh_app_setting_set --app=$app --key=mongo_version --value=$mongo_version } # Remove MongoDB @@ -342,14 +333,13 @@ ynh_install_mongo() { # # ynh_remove_mongo() { - # Only remove the mongodb service if it is not installed. - if ! ynh_package_is_installed --package="mongodb*" - then - ynh_print_info --message="Removing MongoDB service..." - mongodb_servicename=mongod - # Remove the mongodb service - yunohost service remove $mongodb_servicename - ynh_secure_remove --file="/var/lib/mongodb" - ynh_secure_remove --file="/var/log/mongodb" - fi + # Only remove the mongodb service if it is not installed. + if ! ynh_package_is_installed --package="mongodb*"; then + ynh_print_info --message="Removing MongoDB service..." + mongodb_servicename=mongod + # Remove the mongodb service + yunohost service remove $mongodb_servicename + ynh_secure_remove --file="/var/lib/mongodb" + ynh_secure_remove --file="/var/log/mongodb" + fi } diff --git a/helpers/helpers.v1.d/mysql b/helpers/helpers.v1.d/mysql index af7dec42e..cf56173f7 100644 --- a/helpers/helpers.v1.d/mysql +++ b/helpers/helpers.v1.d/mysql @@ -47,7 +47,7 @@ ynh_mysql_execute_as_root() { database="--database=$database" fi - mysql -B "$database" <<<"$sql" + mysql -B "$database" <<< "$sql" } # Execute a command from a file as root user @@ -71,7 +71,7 @@ ynh_mysql_execute_file_as_root() { database="--database=$database" fi - mysql -B "$database" <"$file" + mysql -B "$database" < "$file" } # Create a database and grant optionnaly privilegies to a user diff --git a/helpers/helpers.v1.d/network b/helpers/helpers.v1.d/network index bed9dd402..a2c5e4c91 100644 --- a/helpers/helpers.v1.d/network +++ b/helpers/helpers.v1.d/network @@ -79,7 +79,7 @@ ynh_validate_ip() { [ "$family" == "4" ] || [ "$family" == "6" ] || return 1 - python3 /dev/stdin </dev/null + | jq -e --arg perm "$app.$permission" '.permissions[$perm]' > /dev/null } # Redefine the url associated to a permission @@ -342,7 +342,7 @@ ynh_permission_has_user() { # Check both allowed and corresponding_users sections in the json for section in "allowed" "corresponding_users"; do if yunohost user permission info "$app.$permission" --output-as json --quiet \ - | jq -e --arg user $user --arg section $section '.[$section] | index($user)' >/dev/null; then + | jq -e --arg user $user --arg section $section '.[$section] | index($user)' > /dev/null; then return 0 fi done diff --git a/helpers/helpers.v1.d/php b/helpers/helpers.v1.d/php index 6be509411..22628da85 100644 --- a/helpers/helpers.v1.d/php +++ b/helpers/helpers.v1.d/php @@ -11,19 +11,19 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION} # # Case 1 (recommended) : your provided a snippet conf/extra_php-fpm.conf # -# The actual PHP configuration will be automatically generated, +# The actual PHP configuration will be automatically generated, # and your extra_php-fpm.conf will be appended (typically contains PHP upload limits) # # The resulting configuration will be deployed to the appropriate place, /etc/php/$phpversion/fpm/pool.d/$app.conf # -# Performance-related options in the PHP conf, such as : +# Performance-related options in the PHP conf, such as : # pm.max_children, pm.start_servers, pm.min_spare_servers pm.max_spare_servers # are computed from two parameters called "usage" and "footprint" which can be set to low/medium/high. (cf details below) # -# If you wish to tweak those, please initialize the settings `fpm_usage` and `fpm_footprint` +# If you wish to tweak those, please initialize the settings `fpm_usage` and `fpm_footprint` # *prior* to calling this helper. Otherwise, "low" will be used as a default for both values. # -# Otherwise, if you want the user to have control over these, we encourage to create a config panel +# Otherwise, if you want the user to have control over these, we encourage to create a config panel # (which should ultimately be standardized by the core ...) # # Case 2 (deprecate) : you provided an entire conf/php-fpm.conf @@ -33,7 +33,7 @@ YNH_PHP_VERSION=${YNH_PHP_VERSION:-$YNH_DEFAULT_PHP_VERSION} # The resulting configuration will be deployed to the appropriate place, /etc/php/$phpversion/fpm/pool.d/$app.conf # # ---------------------- -# +# # fpm_footprint: Memory footprint of the service (low/medium/high). # low - Less than 20 MB of RAM by pool. # medium - Between 20 MB and 40 MB of RAM by pool. @@ -89,16 +89,14 @@ ynh_add_fpm_config() { # If no usage provided, default to the value existing in setting ... or to low local fpm_usage_in_setting=$(ynh_app_setting_get --app=$app --key=fpm_usage) - if [ -z "$usage" ] - then + if [ -z "$usage" ]; then usage=${fpm_usage_in_setting:-low} ynh_app_setting_set --app=$app --key=fpm_usage --value=$usage fi # If no footprint provided, default to the value existing in setting ... or to low local fpm_footprint_in_setting=$(ynh_app_setting_get --app=$app --key=fpm_footprint) - if [ -z "$footprint" ] - then + if [ -z "$footprint" ]; then footprint=${fpm_footprint_in_setting:-low} ynh_app_setting_set --app=$app --key=fpm_footprint --value=$footprint fi @@ -120,8 +118,7 @@ ynh_add_fpm_config() { local old_php_fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir) local old_php_finalphpconf="$old_php_fpm_config_dir/pool.d/$app.conf" - if [[ -f "$old_php_finalphpconf" ]] - then + if [[ -f "$old_php_finalphpconf" ]]; then ynh_backup_if_checksum_is_different --file="$old_php_finalphpconf" ynh_remove_fpm_config fi @@ -166,24 +163,24 @@ pm = __PHP_PM__ pm.max_children = __PHP_MAX_CHILDREN__ pm.max_requests = 500 request_terminate_timeout = 1d -" >"$phpfpm_path" +" > "$phpfpm_path" if [ "$php_pm" = "dynamic" ]; then echo " pm.start_servers = __PHP_START_SERVERS__ pm.min_spare_servers = __PHP_MIN_SPARE_SERVERS__ pm.max_spare_servers = __PHP_MAX_SPARE_SERVERS__ -" >>"$phpfpm_path" +" >> "$phpfpm_path" elif [ "$php_pm" = "ondemand" ]; then echo " pm.process_idle_timeout = 10s -" >>"$phpfpm_path" +" >> "$phpfpm_path" fi # Concatene the extra config. if [ -e $YNH_APP_BASEDIR/conf/extra_php-fpm.conf ]; then - cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >>"$phpfpm_path" + cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >> "$phpfpm_path" fi fi @@ -196,6 +193,7 @@ pm.process_idle_timeout = 10s ynh_secure_remove --file="$finalphpconf" ynh_die --message="The new configuration broke php-fpm?" fi + ynh_systemd_action --service_name=$fpm_service --action=reload } diff --git a/helpers/helpers.v1.d/postgresql b/helpers/helpers.v1.d/postgresql index 56fa41a18..4daf8005e 100644 --- a/helpers/helpers.v1.d/postgresql +++ b/helpers/helpers.v1.d/postgresql @@ -51,7 +51,7 @@ ynh_psql_execute_as_root() { fi ynh_psql_connect_as --user="postgres" --password="$(cat $PSQL_ROOT_PWD_FILE)" \ - $database <<<"$sql" + $database <<< "$sql" } # Execute a command from a file as root user @@ -76,7 +76,7 @@ ynh_psql_execute_file_as_root() { fi ynh_psql_connect_as --user="postgres" --password="$(cat $PSQL_ROOT_PWD_FILE)" \ - $database <"$file" + $database < "$file" } # Create a database and grant optionnaly privilegies to a user @@ -199,10 +199,9 @@ ynh_psql_database_exists() { # if psql is not there, we cannot check the db # though it could exists. - if ! command -v psql - then - ynh_print_err -m "PostgreSQL is not installed, impossible to check for db existence." - return 1 + if ! command -v psql; then + ynh_print_err -m "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 else diff --git a/helpers/helpers.v1.d/redis b/helpers/helpers.v1.d/redis index 545bb8705..fe83500c6 100644 --- a/helpers/helpers.v1.d/redis +++ b/helpers/helpers.v1.d/redis @@ -5,27 +5,25 @@ # usage: ynh_redis_get_free_db # | returns: the database number to use ynh_redis_get_free_db() { - local result max db - result=$(redis-cli INFO keyspace) + local result max db + result=$(redis-cli INFO keyspace) - # get the num - max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") - db=0 - # default Debian setting is 15 databases - for i in $(seq 0 "$max") - do - if ! echo "$result" | grep -q "db$i" - then - db=$i - break 1 - fi - db=-1 - done + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max"); do + if ! echo "$result" | grep -q "db$i"; then + db=$i + break 1 + fi + db=-1 + done - test "$db" -eq -1 && ynh_die --message="No available Redis databases..." + test "$db" -eq -1 && ynh_die --message="No available Redis databases..." - echo "$db" + echo "$db" } # Create a master password and set up global settings @@ -34,6 +32,6 @@ ynh_redis_get_free_db() { # usage: ynh_redis_remove_db database # | arg: database - the database to erase ynh_redis_remove_db() { - local db=$1 - redis-cli -n "$db" flushdb + local db=$1 + redis-cli -n "$db" flushdb } diff --git a/helpers/helpers.v1.d/ruby b/helpers/helpers.v1.d/ruby index 24e4b218b..fb2a09efb 100644 --- a/helpers/helpers.v1.d/ruby +++ b/helpers/helpers.v1.d/ruby @@ -8,8 +8,8 @@ export RBENV_ROOT="$rbenv_install_dir" export rbenv_root="$rbenv_install_dir" if dpkg --compare-versions ${YNH_APP_PACKAGING_FORMAT:-0} lt 2; then - build_ruby_dependencies="libjemalloc-dev curl build-essential libreadline-dev zlib1g-dev libsqlite3-dev libssl-dev libxml2-dev libxslt-dev autoconf automake bison libtool" - build_pkg_dependencies="${build_pkg_dependencies:-} $build_ruby_dependencies" + build_ruby_dependencies="libjemalloc-dev curl build-essential libreadline-dev zlib1g-dev libsqlite3-dev libssl-dev libxml2-dev libxslt-dev autoconf automake bison libtool" + build_pkg_dependencies="${build_pkg_dependencies:-} $build_ruby_dependencies" fi # Load the version of Ruby for an app, and set variables. @@ -50,7 +50,7 @@ fi # usage: ynh_use_ruby # # Requires YunoHost version 3.2.2 or higher. -ynh_use_ruby () { +ynh_use_ruby() { ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) # Get the absolute path of this version of Ruby @@ -75,7 +75,7 @@ ynh_use_ruby () { # Sets the local application-specific Ruby version pushd ${install_dir:-$final_path} - $rbenv_install_dir/bin/rbenv local $ruby_version + $rbenv_install_dir/bin/rbenv local $ruby_version popd } @@ -95,10 +95,10 @@ ynh_use_ruby () { # | arg: -v, --ruby_version= - Version of ruby to install. # # Requires YunoHost version 3.2.2 or higher. -ynh_install_ruby () { +ynh_install_ruby() { # Declare an array to define the options of this helper. local legacy_args=v - local -A args_array=( [v]=ruby_version= ) + local -A args_array=([v]=ruby_version=) local ruby_version # Manage arguments with getopts ynh_handle_getopts_args "$@" @@ -117,31 +117,31 @@ ynh_install_ruby () { rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)" if [ -n "$rbenv" ]; then pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then - ynh_print_info --message="Updating rbenv..." - git pull -q --tags origin master - ynh_ruby_try_bash_extension - else - ynh_print_info --message="Reinstalling rbenv..." - cd .. - ynh_secure_remove --file=$rbenv_install_dir - mkdir -p $rbenv_install_dir - cd $rbenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_ruby_try_bash_extension - rbenv=$rbenv_install_dir/bin/rbenv - fi - popd - else - ynh_print_info --message="Installing rbenv..." - pushd $rbenv_install_dir + if git remote -v 2> /dev/null | grep "https://github.com/rbenv/rbenv.git"; then + ynh_print_info --message="Updating rbenv..." + git pull -q --tags origin master + ynh_ruby_try_bash_extension + else + ynh_print_info --message="Reinstalling rbenv..." + cd .. + ynh_secure_remove --file=$rbenv_install_dir + mkdir -p $rbenv_install_dir + cd $rbenv_install_dir git init -q git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 git checkout -q -b master origin/master ynh_ruby_try_bash_extension rbenv=$rbenv_install_dir/bin/rbenv + fi + popd + else + ynh_print_info --message="Installing rbenv..." + pushd $rbenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_ruby_try_bash_extension + rbenv=$rbenv_install_dir/bin/rbenv popd fi @@ -150,10 +150,10 @@ ynh_install_ruby () { ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)" if [ -n "$ruby_build" ]; then pushd "${ruby_build%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then - ynh_print_info --message="Updating ruby-build..." - git pull -q origin master - fi + if git remote -v 2> /dev/null | grep "https://github.com/rbenv/ruby-build.git"; then + ynh_print_info --message="Updating ruby-build..." + git pull -q origin master + fi popd else ynh_print_info --message="Installing ruby-build..." @@ -163,10 +163,10 @@ ynh_install_ruby () { rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" if [ -n "$rbenv_alias" ]; then pushd "${rbenv_alias%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then - ynh_print_info --message="Updating rbenv-aliases..." - git pull -q origin master - fi + if git remote -v 2> /dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then + ynh_print_info --message="Updating rbenv-aliases..." + git pull -q origin master + fi popd else ynh_print_info --message="Installing rbenv-aliases..." @@ -176,10 +176,10 @@ ynh_install_ruby () { rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" if [ -n "$rbenv_latest" ]; then pushd "${rbenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then - ynh_print_info --message="Updating xxenv-latest..." - git pull -q origin master - fi + if git remote -v 2> /dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then + ynh_print_info --message="Updating xxenv-latest..." + git pull -q origin master + fi popd else ynh_print_info --message="Installing xxenv-latest..." @@ -210,8 +210,7 @@ ynh_install_ruby () { ynh_app_setting_set --app=$app --key=ruby_version --value=$final_ruby_version # Remove app virtualenv - if rbenv alias --list | grep --quiet "$app " - then + if rbenv alias --list | grep --quiet "$app "; then rbenv alias $app --remove fi @@ -222,7 +221,7 @@ ynh_install_ruby () { ynh_cleanup_ruby # Set environment for Ruby users - echo "#rbenv + echo "#rbenv export RBENV_ROOT=$rbenv_install_dir export PATH=\"$rbenv_install_dir/bin:$PATH\" eval \"\$(rbenv init -)\" @@ -237,7 +236,7 @@ eval \"\$(rbenv init -)\" # This helper will also cleanup Ruby versions # # usage: ynh_remove_ruby -ynh_remove_ruby () { +ynh_remove_ruby() { local ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) # Load rbenv path in PATH @@ -262,34 +261,29 @@ ynh_remove_ruby () { # If no app uses Ruby, rbenv will be also removed. # # usage: ynh_cleanup_ruby -ynh_cleanup_ruby () { +ynh_cleanup_ruby() { # List required Ruby versions local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local required_ruby_versions="" - for installed_app in $installed_apps - do + for installed_app in $installed_apps; do local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") - if [[ -n "$installed_app_ruby_version" ]] - then + if [[ -n "$installed_app_ruby_version" ]]; then required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" fi done - + # Remove no more needed Ruby versions local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') - for installed_ruby_version in $installed_ruby_versions - do - if ! echo ${required_ruby_versions} | grep -q "${installed_ruby_version}" - then + for installed_ruby_version in $installed_ruby_versions; do + if ! echo ${required_ruby_versions} | grep -q "${installed_ruby_version}"; then ynh_print_info --message="Removing Ruby-$installed_ruby_version" $rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version fi done # If none Ruby version is required - if [[ -z "$required_ruby_versions" ]] - then + if [[ -z "$required_ruby_versions" ]]; then # Remove rbenv environment configuration ynh_print_info --message="Removing rbenv" ynh_secure_remove --file="$rbenv_install_dir" @@ -298,9 +292,9 @@ ynh_cleanup_ruby () { } ynh_ruby_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." - } - fi + 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." + } + fi } diff --git a/helpers/helpers.v1.d/setting b/helpers/helpers.v1.d/setting index 33751791b..d60407602 100644 --- a/helpers/helpers.v1.d/setting +++ b/helpers/helpers.v1.d/setting @@ -108,7 +108,7 @@ ynh_app_setting_delete() { # ynh_app_setting() { set +o xtrace # set +x - ACTION="$1" APP="$2" KEY="$3" VALUE="${4:-}" python3 - </dev/null - then + if test -e $YNH_APP_BASEDIR/manifest.toml && cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq -e '.resources.sources' > /dev/null; then source_id="${source_id:-main}" local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]") - if jq -re ".url" <<< "$sources_json" - then + if jq -re ".url" <<< "$sources_json"; then local arch_prefix="" else local arch_prefix=".$YNH_ARCH" @@ -100,22 +98,16 @@ ynh_setup_source() { [[ -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 - if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]] - then + if [[ -z "$src_format" ]]; then + if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]]; then src_format="zip" - elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]] - then + elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]]; then src_format="tar.gz" - elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]] - then + elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]]; then src_format="tar.xz" - elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]] - then + elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]; then src_format="tar.bz2" - elif [[ -z "$src_extract" ]] - then + elif [[ -z "$src_extract" ]]; then src_extract="false" fi fi @@ -142,12 +134,10 @@ ynh_setup_source() { src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') src_extract=${src_extract:-true} - if [[ "$src_extract" != "true" ]] && [[ "$src_extract" != "false" ]] - then + if [[ "$src_extract" != "true" ]] && [[ "$src_extract" != "false" ]]; then 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... local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${source_id}" @@ -165,14 +155,12 @@ ynh_setup_source() { [ -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 - then + if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status; then rm -f "$src_filename" fi # Only redownload the file if it wasnt prefetched - if [ ! -e "$src_filename" ] - then + if [ ! -e "$src_filename" ]; then # NB. we have to declare the var as local first, # otherwise 'local foo=$(false) || echo 'pwet'" does'nt work # because local always return 0 ... @@ -183,8 +171,7 @@ ynh_setup_source() { fi # Check the control sum - if ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status - then + if ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status; then 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} @@ -222,8 +209,7 @@ ynh_setup_source() { fi if [[ "$src_extract" == "false" ]]; then - if [[ -z "$src_rename" ]] - then + if [[ -z "$src_rename" ]]; then mv $src_filename $dest_dir else mv $src_filename $dest_dir/$src_rename @@ -263,11 +249,11 @@ ynh_setup_source() { # Apply patches if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/) - if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2>/dev/null | wc --lines) > "0")); then + if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2> /dev/null | wc --lines) > "0")); then 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 --message="Packagers /!\\ patch $p failed to apply" done popd fi diff --git a/helpers/helpers.v1.d/string b/helpers/helpers.v1.d/string index b674d9a4a..b4f6d06bf 100644 --- a/helpers/helpers.v1.d/string +++ b/helpers/helpers.v1.d/string @@ -21,7 +21,7 @@ ynh_string_random() { length=${length:-24} filter=${filter:-'A-Za-z0-9'} - dd if=/dev/urandom bs=1 count=1000 2>/dev/null \ + dd if=/dev/urandom bs=1 count=1000 2> /dev/null \ | tr --complement --delete "$filter" \ | sed --quiet 's/\(.\{'"$length"'\}\).*/\1/p' } diff --git a/helpers/helpers.v1.d/systemd b/helpers/helpers.v1.d/systemd index 765c575ef..d4917045c 100644 --- a/helpers/helpers.v1.d/systemd +++ b/helpers/helpers.v1.d/systemd @@ -94,12 +94,12 @@ ynh_systemd_action() { # Following the starting of the app in its log if [ "$log_path" == "systemd" ]; then # Read the systemd journal - journalctl --unit=$service_name --follow --since=-0 --quiet >"$templog" & + journalctl --unit=$service_name --follow --since=-0 --quiet > "$templog" & # Get the PID of the journalctl command local pid_tail=$! else # Read the specified log file - tail --follow=name --retry --lines=0 "$log_path" >"$templog" 2>&1 & + tail --follow=name --retry --lines=0 "$log_path" > "$templog" 2>&1 & # Get the PID of the tail command local pid_tail=$! fi @@ -149,8 +149,7 @@ ynh_systemd_action() { # Also check the timeout using actual timestamp, because sometimes for some reason, # journalctl may take a huge time to run, and we end up waiting literally an entire hour # instead of 5 min ... - if [[ "$(( $(date +%s) - $starttime))" -gt "$timeout" ]] - then + if [[ "$(($(date +%s) - $starttime))" -gt "$timeout" ]]; then i=$timeout break fi diff --git a/helpers/helpers.v1.d/systemuser b/helpers/helpers.v1.d/systemuser index 4fac34bb4..65d00a477 100644 --- a/helpers/helpers.v1.d/systemuser +++ b/helpers/helpers.v1.d/systemuser @@ -17,7 +17,7 @@ ynh_system_user_exists() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - getent passwd "$username" &>/dev/null + getent passwd "$username" &> /dev/null } # Check if a group exists on the system @@ -37,7 +37,7 @@ ynh_system_group_exists() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - getent group "$group" &>/dev/null + getent group "$group" &> /dev/null } # Create a system user diff --git a/helpers/helpers.v1.d/templating b/helpers/helpers.v1.d/templating index 76f319137..474b403c1 100644 --- a/helpers/helpers.v1.d/templating +++ b/helpers/helpers.v1.d/templating @@ -39,11 +39,11 @@ # This option is meant for advanced use-cases where the "simple" templating # mode ain't enough because you need conditional blocks or loops. # -# For a full documentation of jinja's syntax you can refer to: +# For a full documentation of jinja's syntax you can refer to: # https://jinja.palletsprojects.com/en/3.1.x/templates/ # # Note that in YunoHost context, all variables are from shell variables and therefore are strings -# +# # ##### Keeping track of manual changes by the admin # # The helper will verify the checksum and backup the destination file @@ -83,10 +83,9 @@ ynh_add_config() { chmod 640 $destination _ynh_apply_default_permissions $destination - if [[ "$jinja" == 1 ]] - then + if [[ "$jinja" == 1 ]]; then # This is ran in a subshell such that the "export" does not "contaminate" the main process - ( + ( export $(compgen -v) j2 "$template_path" -f env -o $destination ) @@ -267,7 +266,7 @@ ynh_read_var_in_file() { var_part+='\s*' # Extract the part after assignation sign - local expression_with_comment="$((tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" + local expression_with_comment="$( (tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" if [[ "$expression_with_comment" == "YNH_NULL" ]]; then set -o xtrace # set -x echo YNH_NULL @@ -346,7 +345,7 @@ ynh_write_var_in_file() { var_part+='\s*' # Extract the part after assignation sign - local expression_with_comment="$((tail +$after_line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" + local expression_with_comment="$( (tail +$after_line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" if [[ "$expression_with_comment" == "YNH_NULL" ]]; then set -o xtrace # set -x return 1 @@ -403,5 +402,5 @@ ynh_render_template() { # Taken from https://stackoverflow.com/a/35009576 python3 -c 'import os, sys, jinja2; sys.stdout.write( jinja2.Template(sys.stdin.read() - ).render(os.environ));' <$template_path >$output_path + ).render(os.environ));' < $template_path > $output_path } diff --git a/helpers/helpers.v1.d/utils b/helpers/helpers.v1.d/utils index 0e1c18663..0a390e808 100644 --- a/helpers/helpers.v1.d/utils +++ b/helpers/helpers.v1.d/utils @@ -22,8 +22,7 @@ YNH_APP_BASEDIR=${YNH_APP_BASEDIR:-$(realpath ..)} ynh_exit_properly() { local exit_code=$? - if [[ "${YNH_APP_ACTION:-}" =~ ^install$|^upgrade$|^restore$ ]] - then + if [[ "${YNH_APP_ACTION:-}" =~ ^install$|^upgrade$|^restore$ ]]; then rm -rf "/var/cache/yunohost/download/" fi @@ -39,7 +38,7 @@ ynh_exit_properly() { # Small tempo to avoid the next message being mixed up with other DEBUG messages sleep 0.5 - if type -t ynh_clean_setup >/dev/null; then # Check if the function exist in the app script. + if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script. ynh_clean_setup # Call the function to do specific cleaning for the app. fi @@ -67,8 +66,7 @@ ynh_abort_if_errors() { } # When running an app script with packaging format >= 2, auto-enable ynh_abort_if_errors except for remove script -if [[ "${YNH_CONTEXT:-}" != "regenconf" ]] && dpkg --compare-versions ${YNH_APP_PACKAGING_FORMAT:-0} ge 2 && [[ ${YNH_APP_ACTION} != "remove" ]] -then +if [[ "${YNH_CONTEXT:-}" != "regenconf" ]] && dpkg --compare-versions ${YNH_APP_PACKAGING_FORMAT:-0} ge 2 && [[ ${YNH_APP_ACTION} != "remove" ]]; then ynh_abort_if_errors fi @@ -149,8 +147,7 @@ _acceptable_path_to_delete() { local forbidden_paths=$(ls -d / /* /{var,home,usr}/* /etc/{default,sudoers.d,yunohost,cron*} /etc/yunohost/{apps,domains,hooks.d} /opt/yunohost 2> /dev/null) # Legacy : A couple apps still have data in /home/$app ... - if [[ -n "${app:-}" ]] - then + if [[ -n "${app:-}" ]]; then forbidden_paths=$(echo "$forbidden_paths" | grep -v "/home/$app") fi @@ -215,19 +212,16 @@ ynh_read_manifest() { if [ ! -e "${manifest:-}" ]; then # If the manifest isn't found, try the common place for backup and restore script. - if [ -e "$YNH_APP_BASEDIR/manifest.json" ] - then + if [ -e "$YNH_APP_BASEDIR/manifest.json" ]; then manifest="$YNH_APP_BASEDIR/manifest.json" - elif [ -e "$YNH_APP_BASEDIR/manifest.toml" ] - then + elif [ -e "$YNH_APP_BASEDIR/manifest.toml" ]; then manifest="$YNH_APP_BASEDIR/manifest.toml" else ynh_die --message "No manifest found !?" fi fi - if echo "$manifest" | grep -q '\.json$' - then + if echo "$manifest" | grep -q '\.json$'; then jq ".$manifest_key" "$manifest" --raw-output else cat "$manifest" | python3 -c 'import json, toml, sys; print(json.dumps(toml.load(sys.stdin)))' | jq ".$manifest_key" --raw-output @@ -383,8 +377,7 @@ _ynh_apply_default_permissions() { # Crons should be owned by root # Also we don't want systemd conf, nginx conf or others stuff to be owned by the app, # otherwise they could self-edit their own systemd conf and escalate privilege - if grep -qE '^(/etc/cron|/etc/php|/etc/nginx/conf.d|/etc/fail2ban|/etc/systemd/system)' <<< "$target" - then + if grep -qE '^(/etc/cron|/etc/php|/etc/nginx/conf.d|/etc/fail2ban|/etc/systemd/system)' <<< "$target"; then chmod 400 $target chown root:root $target fi @@ -415,7 +408,7 @@ ynh_user_exists() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - yunohost user list --output-as json --quiet | jq -e ".users.\"${username}\"" >/dev/null + yunohost user list --output-as json --quiet | jq -e ".users.\"${username}\"" > /dev/null } # Retrieve a YunoHost user information diff --git a/helpers/helpers.v2.1.d/apt b/helpers/helpers.v2.1.d/apt index 6b2ecad1c..7f44cb67d 100644 --- a/helpers/helpers.v2.1.d/apt +++ b/helpers/helpers.v2.1.d/apt @@ -4,9 +4,9 @@ YNH_APT_INSTALL_DEPENDENCIES_REPLACE="true" # Define and install dependencies with a equivs control file # -# example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" +# example : ynh_apt_install_dependencies dep1 dep2 "dep3|dep4|dep5" # -# usage: ynh_install_app_dependencies dep [dep [...]] +# usage: ynh_apt_install_dependencies dep [dep [...]] # | arg: dep - the package name to install in dependence. # | arg: "dep1|dep2|…" - You can specify alternatives. It will require to install (dep1 or dep2, etc). # @@ -39,8 +39,7 @@ ynh_apt_install_dependencies() { # The (?<=php) syntax corresponds to lookbehind ;) local specific_php_version=$(grep -oP '(?<=php)[0-9.]+(?=-|\>|)' <<< "$dependencies" | sort -u) - if [[ -n "$specific_php_version" ]] - then + if [[ -n "$specific_php_version" ]]; 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 "Inconsistent php versions in dependencies ... found : $specific_php_version" @@ -51,8 +50,7 @@ ynh_apt_install_dependencies() { # If the PHP version changed, remove the old fpm conf if [ -n "$old_php_version" ] && [ "$old_php_version" != "$specific_php_version" ]; then - if [[ -f "/etc/php/$php_version/fpm/pool.d/$app.conf" ]] - then + if [[ -f "/etc/php/$php_version/fpm/pool.d/$app.conf" ]]; then ynh_backup_if_checksum_is_different "/etc/php/$php_version/fpm/pool.d/$app.conf" ynh_config_remove_phpfpm fi @@ -61,8 +59,7 @@ ynh_apt_install_dependencies() { ynh_app_setting_set --key=php_version --value=$specific_php_version # Set the default php version back as the default version for php-cli. - if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION - then + if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION; then update-alternatives --set php /usr/bin/php$YNH_DEFAULT_PHP_VERSION fi elif grep --quiet 'php' <<< "$dependencies"; then @@ -72,18 +69,16 @@ ynh_apt_install_dependencies() { # Specific tweak related to Postgresql (cf end of the helper) local psql_installed="$(_ynh_apt_package_is_installed "postgresql-$PSQL_VERSION" && echo yes || echo no)" - # The first time we run ynh_install_app_dependencies, we will replace the + # The first time we run ynh_apt_install_dependencies, we will replace the # entire control file (This is in particular meant to cover the case of - # upgrade script where ynh_install_app_dependencies is called with this + # upgrade script where ynh_apt_install_dependencies is called with this # expected effect) Otherwise, any subsequent call will add dependencies # to those already present in the equivs control file. - if [[ $YNH_APT_INSTALL_DEPENDENCIES_REPLACE == "true" ]] - then + if [[ $YNH_APT_INSTALL_DEPENDENCIES_REPLACE == "true" ]]; then YNH_APT_INSTALL_DEPENDENCIES_REPLACE="false" else local current_dependencies="" - if _ynh_apt_package_is_installed "${app_ynh_deps}" - then + if _ynh_apt_package_is_installed "${app_ynh_deps}"; then current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${app_ynh_deps}) " current_dependencies=${current_dependencies// | /|} fi @@ -100,7 +95,7 @@ ynh_apt_install_dependencies() { # For some reason, dpkg-deb insists for folder perm to be 755 and sometimes it's 777 o_O? chmod -R 755 ${TMPDIR}/${app_ynh_deps} - cat >${TMPDIR}/${app_ynh_deps}/DEBIAN/control < ${TMPDIR}/${app_ynh_deps}/DEBIAN/control << EOF Section: misc Priority: optional Package: ${app_ynh_deps} @@ -145,8 +140,7 @@ EOF # Specific tweak related to Postgresql # -> trigger postgresql regenconf if we may have just installed postgresql local psql_installed2="$(_ynh_apt_package_is_installed "postgresql-$PSQL_VERSION" && echo yes || echo no)" - if [[ "$psql_installed" != "$psql_installed2" ]] - then + if [[ "$psql_installed" != "$psql_installed2" ]]; then yunohost tools regen-conf postgresql fi @@ -168,16 +162,14 @@ ynh_apt_remove_dependencies() { # Edge case where the app dep may be on hold, # cf https://forum.yunohost.org/t/migration-error-cause-of-ffsync/20675/4 - if apt-mark showhold | grep -q -w ${app_ynh_deps} - then + if apt-mark showhold | grep -q -w ${app_ynh_deps}; then apt-mark unhold ${app_ynh_deps} fi # Remove the fake package and its dependencies if they not still used. # (except if dpkg doesn't know anything about the package, # which should be symptomatic of a failed install, and we don't want bash to report an error) - if dpkg-query --show ${app_ynh_deps} &>/dev/null - then + if dpkg-query --show ${app_ynh_deps} &> /dev/null; then _ynh_apt autoremove --purge ${app_ynh_deps} fi } @@ -206,11 +198,13 @@ ynh_apt_install_dependencies_from_extra_repository() { if [[ "${repo_parts[0]}" == "deb" ]]; then index=1 fi - uri="${repo_parts[$index]}" ; index=$((index+1)) - suite="${repo_parts[$index]}" ; index=$((index+1)) + uri="${repo_parts[$index]}" + index=$((index + 1)) + suite="${repo_parts[$index]}" + index=$((index + 1)) # Get the components - if (( "${#repo_parts[@]}" > 0 )); then + if (("${#repo_parts[@]}" > 0)); then component="${repo_parts[*]:$index}" fi @@ -280,7 +274,7 @@ _ynh_wait_dpkg_free() { # With seq 1 17, timeout will be almost 30 minutes for try in $(seq 1 17); do # Check if /var/lib/dpkg/lock is used by another process - if lsof /var/lib/dpkg/lock >/dev/null; then + if lsof /var/lib/dpkg/lock > /dev/null; then echo "apt is already in use..." # Sleep an exponential time at each round sleep $((try * try)) @@ -298,7 +292,7 @@ _ynh_wait_dpkg_free() { set -o xtrace # set -x return 1 fi - done 9<<<"$(ls -1 $dpkg_dir)" + done 9<<< "$(ls -1 $dpkg_dir)" set -o xtrace # set -x return 0 fi @@ -310,14 +304,14 @@ _ynh_wait_dpkg_free() { # Check either a package is installed or not _ynh_apt_package_is_installed() { local package=$1 - dpkg-query --show --showformat='${db:Status-Status}' "$package" 2>/dev/null \ - | grep --quiet "^installed$" &>/dev/null + dpkg-query --show --showformat='${db:Status-Status}' "$package" 2> /dev/null \ + | grep --quiet "^installed$" &> /dev/null } # Return the installed version of an apt package, if installed _ynh_apt_package_version() { if _ynh_apt_package_is_installed "$package"; then - dpkg-query --show --showformat='${Version}' "$package" 2>/dev/null + dpkg-query --show --showformat='${Version}' "$package" 2> /dev/null else echo '' fi diff --git a/helpers/helpers.v2.1.d/backup b/helpers/helpers.v2.1.d/backup index a40c4f1f2..a8b805bda 100644 --- a/helpers/helpers.v2.1.d/backup +++ b/helpers/helpers.v2.1.d/backup @@ -27,13 +27,11 @@ ynh_backup() { local is_data=false # If the path starts with /var/log/$app or $data_dir - if ([[ -n "${app:-}" ]] && [[ "$target" == "/var/log/$app*" ]]) || ([[ -n "${data_dir:-}" ]] && [[ "$target" == "$data_dir*" ]]) - then + if ([[ -n "${app:-}" ]] && [[ "$target" == "/var/log/$app*" ]]) || ([[ -n "${data_dir:-}" ]] && [[ "$target" == "$data_dir*" ]]); then is_data=true fi - if [[ -n "${app:-}" ]] - then + if [[ -n "${app:-}" ]]; then local do_not_backup_data=$(ynh_app_setting_get --key=do_not_backup_data) fi @@ -83,7 +81,7 @@ ynh_backup() { # ============================================================================== local src=$(echo "${src_path}" | sed --regexp-extended 's/"/\"\"/g') local dest=$(echo "${dest_path}" | sed --regexp-extended 's/"/\"\"/g') - echo "\"${src}\",\"${dest}\"" >>"${YNH_BACKUP_CSV}" + echo "\"${src}\",\"${dest}\"" >> "${YNH_BACKUP_CSV}" # ============================================================================== @@ -135,15 +133,13 @@ ynh_restore() { # If the path starts with /var/log/$app or $data_dir local is_data=false - if ([[ -n "${app:-}" ]] && [[ "$target" == "/var/log/$app*" ]]) || ([[ -n "${data_dir:-}" ]] && [[ "$target" == "$data_dir*" ]]) - then + if ([[ -n "${app:-}" ]] && [[ "$target" == "/var/log/$app*" ]]) || ([[ -n "${data_dir:-}" ]] && [[ "$target" == "$data_dir*" ]]); then is_data=true fi # 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 [[ "$is_data" == true ]] - then + if [[ "$is_data" == true ]]; then 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 @@ -194,7 +190,7 @@ ynh_restore_everything() { # For each destination path begining by $REL_DIR cat ${YNH_BACKUP_CSV} | tr --delete $'\r' | grep --only-matching --no-filename --perl-regexp "^\".*\",\"$REL_DIR.*\"$" \ | while read line; do - local ARCHIVE_PATH=$(echo "$line" | grep --only-matching --no-filename --perl-regexp "^\".*\",\"$REL_DIR\K.*(?=\"$)") + local ARCHIVE_PATH=$(echo "$line" | grep --only-matching --no-filename --perl-regexp "^\"\K.*(?=\",\"$REL_DIR.*\"$)") ynh_restore "$ARCHIVE_PATH" done } @@ -256,8 +252,7 @@ ynh_backup_if_checksum_is_different() { echo "$backup_file_checksum" # Return the name of the backup file if ynh_in_ci_tests; then local file_path_base64=$(echo "$file" | base64 -w0) - if test -e /var/cache/yunohost/appconfbackup/original_${file_path_base64} - then + if test -e /var/cache/yunohost/appconfbackup/original_${file_path_base64}; then 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 diff --git a/helpers/helpers.v2.1.d/composer b/helpers/helpers.v2.1.d/composer index b9608f693..51e62cf8c 100644 --- a/helpers/helpers.v2.1.d/composer +++ b/helpers/helpers.v2.1.d/composer @@ -38,8 +38,8 @@ ynh_composer_exec() { local workdir="${composer_workdir:-$install_dir}" COMPOSER_HOME="$workdir/.composer" \ - COMPOSER_MEMORY_LIMIT=-1 \ - sudo -E -u "${composer_user:-$app}" \ - php${php_version} "$workdir/composer.phar" $@ \ + COMPOSER_MEMORY_LIMIT=-1 \ + sudo -E -u "${composer_user:-$app}" \ + php${php_version} "$workdir/composer.phar" $@ \ -d "$workdir" --no-interaction --no-ansi 2>&1 } diff --git a/helpers/helpers.v2.1.d/config b/helpers/helpers.v2.1.d/config index b853d44d8..f15398156 100644 --- a/helpers/helpers.v2.1.d/config +++ b/helpers/helpers.v2.1.d/config @@ -6,11 +6,11 @@ _ynh_app_config_get_one() { local bind="$3" local getter="get__${short_setting}" # Get value from getter if exists - if type -t $getter 2>/dev/null | grep -q '^function$' 2>/dev/null; then + if type -t $getter 2> /dev/null | grep -q '^function$' 2> /dev/null; then old[$short_setting]="$($getter)" formats[${short_setting}]="yaml" - elif [[ "$bind" == *"("* ]] && type -t "get__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + elif [[ "$bind" == *"("* ]] && type -t "get__${bind%%(*}" 2> /dev/null | grep -q '^function$' 2> /dev/null; then old[$short_setting]="$("get__${bind%%(*}" $short_setting $type $bind)" formats[${short_setting}]="yaml" @@ -22,7 +22,7 @@ _ynh_app_config_get_one() { if [[ "$bind" == "settings" ]]; then ynh_die "File '${short_setting}' can't be stored in settings" fi - old[$short_setting]="$(ls "$bind" 2>/dev/null || echo YNH_NULL)" + old[$short_setting]="$(ls "$bind" 2> /dev/null || echo YNH_NULL)" file_hash[$short_setting]="true" # Get multiline text from settings or from a full file @@ -32,7 +32,7 @@ _ynh_app_config_get_one() { elif [[ "$bind" == *":"* ]]; then 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 "$bind" 2>/dev/null || echo YNH_NULL)" + old[$short_setting]="$(cat "$bind" 2> /dev/null || echo YNH_NULL)" fi # Get value from a kind of key/value file @@ -59,10 +59,10 @@ _ynh_app_config_apply_one() { local type="${types[$short_setting]}" if [ "${changed[$short_setting]}" == "true" ]; then # Apply setter if exists - if type -t $setter 2>/dev/null | grep -q '^function$' 2>/dev/null; then + if type -t $setter 2> /dev/null | grep -q '^function$' 2> /dev/null; then $setter - elif [[ "$bind" == *"("* ]] && type -t "set__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + elif [[ "$bind" == *"("* ]] && type -t "set__${bind%%(*}" 2> /dev/null | grep -q '^function$' 2> /dev/null; then "set__${bind%%(*}" $short_setting $type $bind elif [[ "$bind" == "null" ]]; then @@ -84,8 +84,7 @@ _ynh_app_config_apply_one() { if [[ "${!short_setting}" != "$bind_file" ]]; then cp "${!short_setting}" "$bind_file" fi - if _ynh_file_checksum_exists "$bind_file" - then + if _ynh_file_checksum_exists "$bind_file"; then ynh_store_file_checksum "$bind_file" fi ynh_print_info "File '$bind_file' overwritten with ${!short_setting}" @@ -103,9 +102,8 @@ _ynh_app_config_apply_one() { fi local bind_file="$bind" ynh_backup_if_checksum_is_different "$bind_file" - echo "${!short_setting}" >"$bind_file" - if _ynh_file_checksum_exists "$bind_file" - then + echo "${!short_setting}" > "$bind_file" + if _ynh_file_checksum_exists "$bind_file"; then ynh_store_file_checksum "$bind_file" fi ynh_print_info "File '$bind_file' overwritten with the content provided in question '${short_setting}'" @@ -123,8 +121,7 @@ _ynh_app_config_apply_one() { ynh_backup_if_checksum_is_different "$bind_file" ynh_write_var_in_file --file="${bind_file}" --key="${bind_key_}" --value="${!short_setting}" --after="${bind_after}" - if _ynh_file_checksum_exists "$bind_file" - then + if _ynh_file_checksum_exists "$bind_file"; then ynh_store_file_checksum "$bind_file" fi @@ -139,7 +136,7 @@ _ynh_app_config_apply_one() { _ynh_app_config_get() { for line in $YNH_APP_CONFIG_PANEL_OPTIONS_TYPES_AND_BINDS; do # Split line into short_setting, type and bind - IFS='|' read short_setting type bind <<<"$line" + IFS='|' read short_setting type bind <<< "$line" binds[${short_setting}]="$bind" types[${short_setting}]="$type" file_hash[${short_setting}]="" @@ -215,9 +212,9 @@ _ynh_app_config_validate() { for short_setting in "${!old[@]}"; do [[ "${changed[$short_setting]}" == "false" ]] && continue local result="" - if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null; then + if type -t validate__$short_setting | grep -q '^function$' 2> /dev/null; then result="$(validate__$short_setting)" - elif [[ "$bind" == *"("* ]] && type -t "validate__${bind%%(*}" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + elif [[ "$bind" == *"("* ]] && type -t "validate__${bind%%(*}" 2> /dev/null | grep -q '^function$' 2> /dev/null; then "validate__${bind%%(*}" $short_setting fi if [ -n "$result" ]; then @@ -272,7 +269,7 @@ ynh_app_config_apply() { ynh_app_action_run() { local runner="run__$1" # Get value from getter if exists - if type -t "$runner" 2>/dev/null | grep -q '^function$' 2>/dev/null; then + if type -t "$runner" 2> /dev/null | grep -q '^function$' 2> /dev/null; then $runner #ynh_return "result:" #ynh_return "$(echo "${result}" | sed 's/^/ /g')" @@ -290,22 +287,23 @@ ynh_app_config_run() { declare -Ag formats=() case $1 in - show) - ynh_app_config_get - ynh_app_config_show - ;; - apply) - max_progression=4 - ynh_script_progression "Reading config panel description and current configuration..." - ynh_app_config_get + show) + ynh_app_config_get + ynh_app_config_show + ;; + apply) + max_progression=4 + ynh_script_progression "Reading config panel description and current configuration..." + ynh_app_config_get - ynh_app_config_validate + ynh_app_config_validate - ynh_script_progression "Applying the new configuration..." - ynh_app_config_apply - ynh_script_progression "Configuration of $app completed" - ;; - *) - ynh_app_action_run $1 + ynh_script_progression "Applying the new configuration..." + ynh_app_config_apply + ynh_script_progression "Configuration of $app completed" + ;; + *) + ynh_app_action_run $1 + ;; esac } diff --git a/helpers/helpers.v2.1.d/fail2ban b/helpers/helpers.v2.1.d/fail2ban index 6ca379074..8967bf5c8 100644 --- a/helpers/helpers.v2.1.d/fail2ban +++ b/helpers/helpers.v2.1.d/fail2ban @@ -68,7 +68,7 @@ port = http,https filter = __APP__ logpath = __LOGPATH__ maxretry = 5 -" >"$YNH_APP_BASEDIR/conf/f2b_jail.conf" +" > "$YNH_APP_BASEDIR/conf/f2b_jail.conf" echo " [INCLUDES] @@ -76,7 +76,7 @@ before = common.conf [Definition] failregex = __FAILREGEX__ ignoreregex = -" >"$YNH_APP_BASEDIR/conf/f2b_filter.conf" +" > "$YNH_APP_BASEDIR/conf/f2b_filter.conf" fi ynh_config_add --template="f2b_jail.conf" --destination="/etc/fail2ban/jail.d/$app.conf" diff --git a/helpers/helpers.v2.1.d/getopts b/helpers/helpers.v2.1.d/getopts index ca517eebd..aa452d9fd 100644 --- a/helpers/helpers.v2.1.d/getopts +++ b/helpers/helpers.v2.1.d/getopts @@ -20,7 +20,7 @@ # | arg: $@ - Simply "$@" to tranfert all the positionnal arguments to the function # # This helper need an array, named "args_array" with all the arguments used by the helper -# that want to use ynh_handle_getopts_args +# that want to use ynh_handle_getopts_args # Be carreful, this array has to be an associative array, as the following example: # local -A args_array=( [a]=arg1 [b]=arg2= [c]=arg3 ) # Let's explain this array: @@ -50,8 +50,7 @@ ynh_handle_getopts_args() { eval "$xtrace_enable" return # Validate that the first char is - because it should be something like --option=value or -o ... - elif [[ "${1:0:1}" != "-" ]] - then + elif [[ "${1:0:1}" != "-" ]]; then ynh_die "It looks like you called the helper using positional arguments instead of keyword arguments ?" fi @@ -182,6 +181,6 @@ ynh_handle_getopts_args() { # Call parse_arg and pass the modified list of args as an array of arguments. parse_arg "${arguments[@]}" - + eval "$xtrace_enable" } diff --git a/helpers/helpers.v2.1.d/go b/helpers/helpers.v2.1.d/go index bb272d50c..7e9a6391b 100644 --- a/helpers/helpers.v2.1.d/go +++ b/helpers/helpers.v2.1.d/go @@ -23,7 +23,7 @@ _ynh_load_go_in_path_and_other_tweaks() { # Sets the local application-specific go version pushd ${install_dir} - $GOENV_INSTALL_DIR/bin/goenv local $go_version + $GOENV_INSTALL_DIR/bin/goenv local $go_version popd } @@ -39,7 +39,7 @@ _ynh_load_go_in_path_and_other_tweaks() { # - `$go_dir` (the directory containing the specific go version) # # This helper also creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv -ynh_go_install () { +ynh_go_install() { [[ -n "${go_version:-}" ]] || ynh_die "\$go_version should be defined prior to calling ynh_go_install" @@ -55,33 +55,33 @@ ynh_go_install () { # Install or update goenv mkdir -p $GOENV_INSTALL_DIR pushd "$GOENV_INSTALL_DIR" - if ! [ -x "$GOENV_INSTALL_DIR/bin/goenv" ]; then - ynh_print_info "Downloading goenv..." - git init -q - git remote add origin https://github.com/syndbg/goenv.git - else - 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)") - git checkout -q "$git_latest_tag" - _ynh_go_try_bash_extension - goenv=$GOENV_INSTALL_DIR/bin/goenv + if ! [ -x "$GOENV_INSTALL_DIR/bin/goenv" ]; then + ynh_print_info "Downloading goenv..." + git init -q + git remote add origin https://github.com/syndbg/goenv.git + else + 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)") + git checkout -q "$git_latest_tag" + _ynh_go_try_bash_extension + goenv=$GOENV_INSTALL_DIR/bin/goenv popd # Install or update xxenv-latest 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 "Downloading xxenv-latest..." - git init -q - git remote add origin https://github.com/momo-lab/xxenv-latest.git - else - 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)") - git checkout -q "$git_latest_tag" + if ! [ -x "$GOENV_INSTALL_DIR/plugins/xxenv-latest/bin/goenv-latest" ]; then + 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 "Updating xxenv-latest..." + fi + git fetch -q --tags --prune origin + local git_latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") + git checkout -q "$git_latest_tag" popd # Enable caching @@ -109,7 +109,7 @@ ynh_go_install () { _ynh_go_cleanup # Set environment for Go users - echo "#goenv + echo "#goenv export GOENV_ROOT=$GOENV_INSTALL_DIR export PATH=\"$GOENV_INSTALL_DIR/bin:$PATH\" eval \"\$(goenv init -)\" @@ -126,7 +126,7 @@ eval \"\$(goenv init -)\" # This helper will also cleanup Go versions # # usage: ynh_go_remove -ynh_go_remove () { +ynh_go_remove() { local go_version=$(ynh_app_setting_get --key="go_version") # Load goenv path in PATH @@ -151,34 +151,29 @@ ynh_go_remove () { # If no app uses Go, goenv will be also removed. # # usage: _ynh_go_cleanup -_ynh_go_cleanup () { +_ynh_go_cleanup() { # List required Go versions local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id) local required_go_versions="" - for installed_app in $installed_apps - do + for installed_app in $installed_apps; do local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") - if [[ $installed_app_go_version ]] - then + if [[ $installed_app_go_version ]]; then required_go_versions="${installed_app_go_version}\n${required_go_versions}" fi done # Remove no more needed Go versions local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/') - for installed_go_version in $installed_go_versions - do - if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1` - then + for installed_go_version in $installed_go_versions; do + if ! $(echo ${required_go_versions} | grep "${installed_go_version}" 1> /dev/null 2>&1); then ynh_print_info "Removing of Go-$installed_go_version" $GOENV_INSTALL_DIR/bin/goenv uninstall --force "$installed_go_version" fi done # If none Go version is required - if [[ ! $required_go_versions ]] - then + if [[ ! $required_go_versions ]]; then # Remove goenv environment configuration ynh_print_info "Removing of goenv" ynh_safe_rm "$GOENV_INSTALL_DIR" @@ -187,9 +182,9 @@ _ynh_go_cleanup () { } _ynh_go_try_bash_extension() { - if [ -x src/configure ]; then - src/configure && make -C src || { - ynh_print_info "Optional bash extension failed to build, but things will still work normally." - } - fi + if [ -x src/configure ]; then + src/configure && make -C src || { + ynh_print_info "Optional bash extension failed to build, but things will still work normally." + } + fi } diff --git a/helpers/helpers.v2.1.d/logging b/helpers/helpers.v2.1.d/logging index a2471cd2d..8786daaed 100644 --- a/helpers/helpers.v2.1.d/logging +++ b/helpers/helpers.v2.1.d/logging @@ -5,11 +5,9 @@ # usage: ynh_die "Some message" ynh_die() { set +o xtrace # set +x - if [[ -n "${1:-}" ]] - then - if [[ -n "${YNH_STDRETURN:-}" ]] - then - python3 -c 'import yaml, sys; print(yaml.dump({"error": sys.stdin.read()}))' <<< "${1:-}" >>"$YNH_STDRETURN" + if [[ -n "${1:-}" ]]; then + if [[ -n "${YNH_STDRETURN:-}" ]]; then + python3 -c 'import yaml, sys; print(yaml.dump({"error": sys.stdin.read()}))' <<< "${1:-}" >> "$YNH_STDRETURN" fi echo "${1:-}" 1>&2 fi @@ -51,7 +49,7 @@ ynh_exec_and_print_stderr_only_if_error() { rc=0 # Note that "$@" is used and not $@, c.f. https://unix.stackexchange.com/a/129077 "$@" 2> "$logfile" || rc="$?" - if (( rc != 0 )); then + if ((rc != 0)); then cat "$logfile" >&2 ynh_safe_rm "$logfile" return "$rc" @@ -63,7 +61,7 @@ ynh_exec_and_print_stderr_only_if_error() { # # usage: ynh_return somedata ynh_return() { - echo "$1" >>"$YNH_STDRETURN" + echo "$1" >> "$YNH_STDRETURN" } # Initial definitions for ynh_script_progression @@ -105,10 +103,9 @@ ynh_script_progression() { local expected_progression="$((($increment_progression + 1) * $progress_scale / $max_progression - $effective_progression))" # Hack for the "--last" message - if grep -qw 'completed' <<< "$1"; - then - effective_progression=$progress_scale - expected_progression=0 + 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))" diff --git a/helpers/helpers.v2.1.d/logrotate b/helpers/helpers.v2.1.d/logrotate index e431841c5..4d471b43c 100644 --- a/helpers/helpers.v2.1.d/logrotate +++ b/helpers/helpers.v2.1.d/logrotate @@ -22,8 +22,7 @@ ynh_config_add_logrotate() { fi set +o noglob - for stuff in $logfile - do + for stuff in $logfile; do # Make sure the permissions of the parent dir are correct (otherwise the config file could be ignored and the corresponding logs never rotated) local dir=$(dirname "$stuff") mkdir --parents $dir @@ -32,7 +31,7 @@ ynh_config_add_logrotate() { done local tempconf="$(mktemp)" - cat << EOF >$tempconf + cat << EOF > $tempconf $logfile { # Rotate if the logfile exceeds 100Mo size 100M @@ -53,8 +52,7 @@ $logfile { } EOF - if [[ "$FIRST_CALL_TO_LOGROTATE" == "true" ]] - then + if [[ "$FIRST_CALL_TO_LOGROTATE" == "true" ]]; then cat $tempconf > /etc/logrotate.d/$app else cat $tempconf >> /etc/logrotate.d/$app diff --git a/helpers/helpers.v2.1.d/mongodb b/helpers/helpers.v2.1.d/mongodb index 3fb851277..95e04ec0e 100644 --- a/helpers/helpers.v2.1.d/mongodb +++ b/helpers/helpers.v2.1.d/mongodb @@ -12,16 +12,15 @@ # ynh_mongo_exec() { # ============ Argument parsing ============= - local -A args_array=( [d]=database= [c]=command= ) + local -A args_array=([d]=database= [c]=command=) local database local command ynh_handle_getopts_args "$@" database="${database:-}" # =========================================== - if [ -n "$database" ] - then - mongosh --quiet </dev/null + | jq -e --arg perm "$app.$permission" '.permissions[$perm]' > /dev/null } # Redefine the url associated to a permission @@ -301,7 +301,7 @@ ynh_permission_has_user() { # Check both allowed and corresponding_users sections in the json for section in "allowed" "corresponding_users"; do if yunohost user permission info "$app.$permission" --output-as json --quiet \ - | jq -e --arg user $user --arg section $section '.[$section] | index($user)' >/dev/null; then + | jq -e --arg user $user --arg section $section '.[$section] | index($user)' > /dev/null; then return 0 fi done diff --git a/helpers/helpers.v2.1.d/php b/helpers/helpers.v2.1.d/php index b7165e010..a28188621 100644 --- a/helpers/helpers.v2.1.d/php +++ b/helpers/helpers.v2.1.d/php @@ -59,9 +59,9 @@ ynh_config_add_phpfpm() { # Apps willing to tweak these should use ynh_setting_set_default_value (in install and upgrade?) # local php_upload_max_filesize=${php_upload_max_filesize:-50M} - local php_process_management=${php_process_management:-ondemand} # alternatively 'dynamic' or 'static' + local php_process_management=${php_process_management:-ondemand} # alternatively 'dynamic' or 'static' local php_max_children=${php_max_children:-$(_default_php_max_children)} - local php_memory_limit=${php_memory_limit:-128M} # default value is from global php.ini + local php_memory_limit=${php_memory_limit:-128M} # default value is from global php.ini local phpfpm_template=$(mktemp) cat << EOF > $phpfpm_template @@ -102,7 +102,7 @@ EOF # Concatene the extra config if [ -e $YNH_APP_BASEDIR/conf/extra_php-fpm.conf ]; then - cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >>"$phpfpm_template" + cat $YNH_APP_BASEDIR/conf/extra_php-fpm.conf >> "$phpfpm_template" fi # Make sure the fpm pool dir exists @@ -111,7 +111,7 @@ EOF ynh_config_add --template="$phpfpm_template" --destination="/etc/php/$php_version/fpm/pool.d/$app.conf" # Validate that the new php conf doesn't break php-fpm entirely - if ! php-fpm${php_version} --test 2>/dev/null; then + if ! php-fpm${php_version} --test 2> /dev/null; then php-fpm${php_version} --test || true ynh_safe_rm "/etc/php/$php_version/fpm/pool.d/$app.conf" ynh_die "The new configuration broke php-fpm?" diff --git a/helpers/helpers.v2.1.d/redis b/helpers/helpers.v2.1.d/redis index 310db411b..0425b5fd4 100644 --- a/helpers/helpers.v2.1.d/redis +++ b/helpers/helpers.v2.1.d/redis @@ -5,27 +5,25 @@ # usage: ynh_redis_get_free_db # | returns: the database number to use ynh_redis_get_free_db() { - local result max db - result=$(redis-cli INFO keyspace) + local result max db + result=$(redis-cli INFO keyspace) - # get the num - max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") - db=0 - # default Debian setting is 15 databases - for i in $(seq 0 "$max") - do - if ! echo "$result" | grep -q "db$i" - then - db=$i - break 1 - fi - db=-1 - done + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max"); do + if ! echo "$result" | grep -q "db$i"; then + db=$i + break 1 + fi + db=-1 + done - test "$db" -eq -1 && ynh_die "No available Redis databases..." + test "$db" -eq -1 && ynh_die "No available Redis databases..." - echo "$db" + echo "$db" } # Create a master password and set up global settings @@ -34,6 +32,6 @@ ynh_redis_get_free_db() { # usage: ynh_redis_remove_db database # | arg: database - the database to erase ynh_redis_remove_db() { - local db=$1 - redis-cli -n "$db" flushdb + local db=$1 + redis-cli -n "$db" flushdb } diff --git a/helpers/helpers.v2.1.d/ruby b/helpers/helpers.v2.1.d/ruby index 22b28d9ad..45559a2f3 100644 --- a/helpers/helpers.v2.1.d/ruby +++ b/helpers/helpers.v2.1.d/ruby @@ -25,7 +25,7 @@ _ynh_load_ruby_in_path_and_other_tweaks() { # Sets the local application-specific Ruby version pushd ${install_dir} - $RBENV_INSTALL_DIR/bin/rbenv local $ruby_version + $RBENV_INSTALL_DIR/bin/rbenv local $ruby_version popd } @@ -41,7 +41,7 @@ _ynh_load_ruby_in_path_and_other_tweaks() { # - `$ruby_dir`, the directory containing the specific version of ruby, which may be used in the systemd config too (e.g. `ExecStart=__RUBY_DIR__/ruby foo bar`) # # This helper also creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv -ynh_ruby_install () { +ynh_ruby_install() { [[ -n "${ruby_version:-}" ]] || ynh_die "\$ruby_version should be defined prior to calling ynh_ruby_install" @@ -59,31 +59,31 @@ ynh_ruby_install () { rbenv="$(command -v rbenv $RBENV_INSTALL_DIR/bin/rbenv | grep "$RBENV_INSTALL_DIR/bin/rbenv" | head -1)" if [ -n "$rbenv" ]; then pushd "${rbenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then - echo "Updating rbenv..." - git pull -q --tags origin master - _ynh_ruby_try_bash_extension - else - echo "Reinstalling rbenv..." - cd .. - ynh_safe_rm $RBENV_INSTALL_DIR - mkdir -p $RBENV_INSTALL_DIR - cd $RBENV_INSTALL_DIR - git init -q - git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - _ynh_ruby_try_bash_extension - rbenv=$RBENV_INSTALL_DIR/bin/rbenv - fi - popd - else - echo "Installing rbenv..." - pushd $RBENV_INSTALL_DIR + if git remote -v 2> /dev/null | grep "https://github.com/rbenv/rbenv.git"; then + echo "Updating rbenv..." + git pull -q --tags origin master + _ynh_ruby_try_bash_extension + else + echo "Reinstalling rbenv..." + cd .. + ynh_safe_rm $RBENV_INSTALL_DIR + mkdir -p $RBENV_INSTALL_DIR + cd $RBENV_INSTALL_DIR git init -q git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 git checkout -q -b master origin/master _ynh_ruby_try_bash_extension rbenv=$RBENV_INSTALL_DIR/bin/rbenv + fi + popd + else + echo "Installing rbenv..." + pushd $RBENV_INSTALL_DIR + git init -q + git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + _ynh_ruby_try_bash_extension + rbenv=$RBENV_INSTALL_DIR/bin/rbenv popd fi @@ -92,10 +92,10 @@ ynh_ruby_install () { ruby_build="$(command -v "$RBENV_INSTALL_DIR"/plugins/*/bin/rbenv-install rbenv-install | head -1)" if [ -n "$ruby_build" ]; then pushd "${ruby_build%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then - echo "Updating ruby-build..." - git pull -q origin master - fi + if git remote -v 2> /dev/null | grep "https://github.com/rbenv/ruby-build.git"; then + echo "Updating ruby-build..." + git pull -q origin master + fi popd else echo "Installing ruby-build..." @@ -105,10 +105,10 @@ ynh_ruby_install () { rbenv_alias="$(command -v "$RBENV_INSTALL_DIR"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)" if [ -n "$rbenv_alias" ]; then pushd "${rbenv_alias%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then - echo "Updating rbenv-aliases..." - git pull -q origin master - fi + if git remote -v 2> /dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then + echo "Updating rbenv-aliases..." + git pull -q origin master + fi popd else echo "Installing rbenv-aliases..." @@ -118,10 +118,10 @@ ynh_ruby_install () { rbenv_latest="$(command -v "$RBENV_INSTALL_DIR"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)" if [ -n "$rbenv_latest" ]; then pushd "${rbenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then - echo "Updating xxenv-latest..." - git pull -q origin master - fi + if git remote -v 2> /dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then + echo "Updating xxenv-latest..." + git pull -q origin master + fi popd else echo "Installing xxenv-latest..." @@ -153,8 +153,7 @@ ynh_ruby_install () { ruby_version=$final_ruby_version # Remove app virtualenv - if rbenv alias --list | grep --quiet "$app " - then + if rbenv alias --list | grep --quiet "$app "; then rbenv alias $app --remove fi @@ -165,7 +164,7 @@ ynh_ruby_install () { _ynh_ruby_cleanup # Set environment for Ruby users - echo "#rbenv + echo "#rbenv export RBENV_ROOT=$RBENV_INSTALL_DIR export PATH=\"$RBENV_INSTALL_DIR/bin:$PATH\" eval \"\$(rbenv init -)\" @@ -182,7 +181,7 @@ eval \"\$(rbenv init -)\" # This helper will also cleanup unused Ruby versions # # usage: ynh_ruby_remove -ynh_ruby_remove () { +ynh_ruby_remove() { [[ -n "${ruby_version:-}" ]] || ynh_die "\$ruby_version should be defined prior to calling ynh_ruby_remove" @@ -208,34 +207,29 @@ ynh_ruby_remove () { # This helper will check what Ruby version are no more required, # and uninstall them # If no app uses Ruby, rbenv will be also removed. -_ynh_ruby_cleanup () { +_ynh_ruby_cleanup() { # List required Ruby versions local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local required_ruby_versions="" - for installed_app in $installed_apps - do + for installed_app in $installed_apps; do local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version") - if [[ -n "$installed_app_ruby_version" ]] - then + if [[ -n "$installed_app_ruby_version" ]]; then required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}" fi done # Remove no more needed Ruby versions local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/') - for installed_ruby_version in $installed_ruby_versions - do - if ! echo ${required_ruby_versions} | grep -q "${installed_ruby_version}" - then + for installed_ruby_version in $installed_ruby_versions; do + if ! echo ${required_ruby_versions} | grep -q "${installed_ruby_version}"; then echo "Removing Ruby-$installed_ruby_version" $RBENV_INSTALL_DIR/bin/rbenv uninstall --force $installed_ruby_version fi done # If none Ruby version is required - if [[ -z "$required_ruby_versions" ]] - then + if [[ -z "$required_ruby_versions" ]]; then # Remove rbenv environment configuration echo "Removing rbenv" ynh_safe_rm "$RBENV_INSTALL_DIR" @@ -244,9 +238,9 @@ _ynh_ruby_cleanup () { } _ynh_ruby_try_bash_extension() { - if [ -x src/configure ]; then - src/configure && make -C src 2>&1 || { - ynh_print_info "Optional bash extension failed to build, but things will still work normally." - } - fi + if [ -x src/configure ]; then + src/configure && make -C src 2>&1 || { + ynh_print_info "Optional bash extension failed to build, but things will still work normally." + } + fi } diff --git a/helpers/helpers.v2.1.d/setting b/helpers/helpers.v2.1.d/setting index 01480331c..a3b944627 100644 --- a/helpers/helpers.v2.1.d/setting +++ b/helpers/helpers.v2.1.d/setting @@ -98,7 +98,7 @@ ynh_app_setting() { # Trick to only re-enable debugging if it was set before local xtrace_enable=$(set +o | grep xtrace) set +o xtrace # set +x - ACTION="$1" APP="$2" KEY="$3" VALUE="${4:-}" python3 - </dev/null \ + dd if=/dev/urandom bs=1 count=1000 2> /dev/null \ | tr --complement --delete "$filter" \ | sed --quiet 's/\(.\{'"$length"'\}\).*/\1/p' } diff --git a/helpers/helpers.v2.1.d/systemd b/helpers/helpers.v2.1.d/systemd index b8ff84fd1..64079e6ef 100644 --- a/helpers/helpers.v2.1.d/systemd +++ b/helpers/helpers.v2.1.d/systemd @@ -68,8 +68,7 @@ ynh_systemctl() { # =========================================== # On CI, use length=100 because it's sometime hell to debug otherwise for super-long output - if ynh_in_ci_tests && [ $length -le 20 ] - then + if ynh_in_ci_tests && [ $length -le 20 ]; then length=100 fi @@ -84,12 +83,12 @@ ynh_systemctl() { # Following the starting of the app in its log if [ "$log_path" == "systemd" ]; then # Read the systemd journal - journalctl --unit=$service --follow --since=-0 --quiet >"$templog" & + journalctl --unit=$service --follow --since=-0 --quiet > "$templog" & # Get the PID of the journalctl command local pid_tail=$! else # Read the specified log file - tail --follow=name --retry --lines=0 "$log_path" >"$templog" 2>&1 & + tail --follow=name --retry --lines=0 "$log_path" > "$templog" 2>&1 & # Get the PID of the tail command local pid_tail=$! fi @@ -139,8 +138,7 @@ ynh_systemctl() { # Also check the timeout using actual timestamp, because sometimes for some reason, # journalctl may take a huge time to run, and we end up waiting literally an entire hour # instead of 5 min ... - if [[ "$(( $(date +%s) - $starttime))" -gt "$timeout" ]] - then + if [[ "$(($(date +%s) - $starttime))" -gt "$timeout" ]]; then i=$timeout break fi @@ -160,8 +158,7 @@ ynh_systemctl() { fi # If we tried to reload/start/restart the service but systemctl consider it to be still inactive/broken, then handle it as a failure - if ([ "$action" == "reload" ] || [ "$action" == "start" ] || [ "$action" == "restart" ]) && ! systemctl --quiet is-active $service - then + if ([ "$action" == "reload" ] || [ "$action" == "start" ] || [ "$action" == "restart" ]) && ! systemctl --quiet is-active $service; then _ynh_clean_check_starting return 1 fi diff --git a/helpers/helpers.v2.1.d/systemuser b/helpers/helpers.v2.1.d/systemuser index 720a6ec28..d8b27a9bf 100644 --- a/helpers/helpers.v2.1.d/systemuser +++ b/helpers/helpers.v2.1.d/systemuser @@ -12,7 +12,7 @@ ynh_system_user_exists() { ynh_handle_getopts_args "$@" # =========================================== - getent passwd "$username" &>/dev/null + getent passwd "$username" &> /dev/null } # Check if a group exists on the system @@ -27,7 +27,7 @@ ynh_system_group_exists() { ynh_handle_getopts_args "$@" # =========================================== - getent group "$group" &>/dev/null + getent group "$group" &> /dev/null } # Create a system user diff --git a/helpers/helpers.v2.1.d/templating b/helpers/helpers.v2.1.d/templating index dc7a090a2..3da3a1e2b 100644 --- a/helpers/helpers.v2.1.d/templating +++ b/helpers/helpers.v2.1.d/templating @@ -29,7 +29,7 @@ # This option is meant for advanced use-cases where the "simple" templating # mode ain't enough because you need conditional blocks or loops. # -# For a full documentation of jinja's syntax you can refer to: +# For a full documentation of jinja's syntax you can refer to: # https://jinja.palletsprojects.com/en/3.1.x/templates/ # # Note that in YunoHost context, all variables are from shell variables and therefore are strings @@ -70,10 +70,9 @@ ynh_config_add() { chmod 640 $destination _ynh_apply_default_permissions $destination - if [[ "$jinja" == 1 ]] - then + if [[ "$jinja" == 1 ]]; then # This is ran in a subshell such that the "export" does not "contaminate" the main process - ( + ( export $(compgen -v) j2 "$template_path" -f env -o $destination ) @@ -216,7 +215,7 @@ ynh_read_var_in_file() { var_part+='\s*' # Extract the part after assignation sign - local expression_with_comment="$((tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" + local expression_with_comment="$( (tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" if [[ "$expression_with_comment" == "YNH_NULL" ]]; then set -o xtrace # set -x echo YNH_NULL @@ -292,7 +291,7 @@ ynh_write_var_in_file() { var_part+='\s*' # Extract the part after assignation sign - local expression_with_comment="$((tail +$after_line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" + local expression_with_comment="$( (tail +$after_line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL) | head -n1)" if [[ "$expression_with_comment" == "YNH_NULL" ]]; then set -o xtrace # set -x return 1 diff --git a/helpers/helpers.v2.1.d/utils b/helpers/helpers.v2.1.d/utils index aca976c54..bda5391cd 100644 --- a/helpers/helpers.v2.1.d/utils +++ b/helpers/helpers.v2.1.d/utils @@ -9,8 +9,7 @@ YNH_APP_BASEDIR=${YNH_APP_BASEDIR:-$(realpath ..)} ynh_exit_properly() { local exit_code=$? - if [[ "${YNH_APP_ACTION:-}" =~ ^install$|^upgrade$|^restore$ ]] - then + if [[ "${YNH_APP_ACTION:-}" =~ ^install$|^upgrade$|^restore$ ]]; then rm -rf "/var/cache/yunohost/download/" fi @@ -47,8 +46,7 @@ ynh_abort_if_errors() { } # When running an app script, auto-enable ynh_abort_if_errors except for remove script -if [[ "${YNH_CONTEXT:-}" != "regenconf" ]] && [[ "${YNH_APP_ACTION}" != "remove" ]] -then +if [[ "${YNH_CONTEXT:-}" != "regenconf" ]] && [[ "${YNH_APP_ACTION}" != "remove" ]]; then ynh_abort_if_errors fi @@ -124,8 +122,7 @@ _acceptable_path_to_delete() { local forbidden_paths=$(ls -d / /* /{var,home,usr}/* /etc/{default,sudoers.d,yunohost,cron*} /etc/yunohost/{apps,domains,hooks.d} /opt/yunohost 2> /dev/null) # Legacy : A couple apps still have data in /home/$app ... - if [[ -n "${app:-}" ]] - then + if [[ -n "${app:-}" ]]; then forbidden_paths=$(echo "$forbidden_paths" | grep -v "/home/$app") fi @@ -223,31 +220,27 @@ _ynh_apply_default_permissions() { is_in_dir() { # Returns false if parent is empty [ -n "$2" ] || return 1 - local child=$(realpath "$1" 2>/dev/null) - local parent=$(realpath "$2" 2>/dev/null) + local child=$(realpath "$1" 2> /dev/null) + local parent=$(realpath "$2" 2> /dev/null) [[ "${child}" =~ ^$parent ]] } # App files can have files of their own if ynh_system_user_exists --username="$app"; then # If this is a file in $install_dir or $data_dir : it should be owned and read+writable by $app only - if [ -f "$target" ] && (is_in_dir "$target" "${install_dir:-}" || is_in_dir "$target" "${data_dir:-}" || is_in_dir "$target" "/etc/$app") - then + if [ -f "$target" ] && (is_in_dir "$target" "${install_dir:-}" || is_in_dir "$target" "${data_dir:-}" || is_in_dir "$target" "/etc/$app"); then chmod 600 "$target" chown "$app:$app" "$target" return fi # If this is the install dir (so far this is the only way this helper is called with a directory) - if [ "$target" == "${install_dir:-}" ] - then + if [ "$target" == "${install_dir:-}" ]; then # Read the group from the install_dir manifest resource local group="$(ynh_read_manifest 'resources.install_dir.group' | sed 's/null//g' | sed "s/__APP__/$app/g" | cut -f1 -d:)" - if [[ -z "$group" ]] - then + if [[ -z "$group" ]]; then # We set the group to www-data for webapps that do serve static assets, which therefore need to be readable by nginx ... # The fact that the app needs this is infered by the existence of an nginx.conf and the presence of "alias" or "root" directive - if grep -q '^\s*alias\s\|^\s*root\s' "$YNH_APP_BASEDIR/conf/nginx.conf" 2>/dev/null; - then + if grep -q '^\s*alias\s\|^\s*root\s' "$YNH_APP_BASEDIR/conf/nginx.conf" 2> /dev/null; then group="www-data" # Or default to "$app" else @@ -292,7 +285,7 @@ ynh_validate_ip() { [ "$family" == "4" ] || [ "$family" == "6" ] || return 1 # http://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python#319298 - python3 /dev/stdin </dev/null || ynh_die "There is no \"$app\" system user" + # Make sure the app has its own user + id -u "$app" &> /dev/null || ynh_die "There is no \"$app\" system user" - # Make sure the app has an install_dir setting - local install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) - [ -n "$install_dir" ] || ynh_die "$app has no install_dir setting (does it use packaging format >=2?)" + # Make sure the app has an install_dir setting + local install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) + [ -n "$install_dir" ] || ynh_die "$app has no install_dir setting (does it use packaging format >=2?)" - # Load the app's service name, or default to $app - local service=$(ynh_app_setting_get --app=$app --key=service) - [ -z "$service" ] && service=$app; + # Load the app's service name, or default to $app + local service=$(ynh_app_setting_get --app=$app --key=service) + [ -z "$service" ] && service=$app - # Export HOME variable - export HOME=$install_dir; + # Export HOME variable + export HOME=$install_dir - # Load the Environment variables from the app's service - local env_var=$(systemctl show $service.service -p "Environment" --value) - [ -n "$env_var" ] && export $env_var; + # Load the Environment variables from the app's service + local env_var=$(systemctl show $service.service -p "Environment" --value) + [ -n "$env_var" ] && export $env_var - # Force `php` to its intended version - # We use `eval`+`export` since `alias` is not propagated to subshells, even with `export` - local phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - local phpflags=$(ynh_app_setting_get --app=$app --key=phpflags) - if [ -n "$phpversion" ] - then - eval "php() { php${phpversion} ${phpflags} \"\$@\"; }" - export -f php - fi + # Force `php` to its intended version + # We use `eval`+`export` since `alias` is not propagated to subshells, even with `export` + local phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) + local phpflags=$(ynh_app_setting_get --app=$app --key=phpflags) + if [ -n "$phpversion" ]; then + eval "php() { php${phpversion} ${phpflags} \"\$@\"; }" + export -f php + fi - # Source the EnvironmentFiles from the app's service - local env_files=($(systemctl show $service.service -p "EnvironmentFiles" --value)) - if [ ${#env_files[*]} -gt 0 ] - then - # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. - set -a - for file in ${env_files[*]} - do - [[ $file = /* ]] && source $file - done - set +a - fi + # Source the EnvironmentFiles from the app's service + local env_files=($(systemctl show $service.service -p "EnvironmentFiles" --value)) + if [ ${#env_files[*]} -gt 0 ]; then + # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. + set -a + for file in ${env_files[*]}; do + [[ $file = /* ]] && source $file + done + set +a + fi - # Activate the Python environment, if it exists - if [ -f $install_dir/venv/bin/activate ] - then - # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. - set -a - source $install_dir/venv/bin/activate - set +a - fi + # Activate the Python environment, if it exists + if [ -f $install_dir/venv/bin/activate ]; then + # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. + set -a + source $install_dir/venv/bin/activate + set +a + fi - # cd into the WorkingDirectory set in the service, or default to the install_dir - local env_dir=$(systemctl show $service.service -p "WorkingDirectory" --value) - [ -z $env_dir ] && env_dir=$install_dir; - cd $env_dir + # cd into the WorkingDirectory set in the service, or default to the install_dir + local env_dir=$(systemctl show $service.service -p "WorkingDirectory" --value) + [ -z $env_dir ] && env_dir=$install_dir + cd $env_dir - # Spawn the app shell - su -s /bin/bash $app + # Spawn the app shell + su -s /bin/bash $app +} + +# Add swap +# +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap() { + if systemd-detect-virt --container --quiet; then + ynh_print_warn --message="You are inside a container/VM. swap will not be added, but that can cause troubles for the app $app. Please make sure you have enough RAM available." + return + fi + + # Declare an array to define the options of this helper. + declare -Ar args_array=([s]=size=) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local swap_max_size=$(($size * 1024)) + + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(($free_space / 2)) + + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ]; then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" + return + fi + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ]; then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(($swap_max_size / 2)) ]; then + local swap_size=$(($swap_max_size / 2)) + elif [ $usable_space -ge $(($swap_max_size / 3)) ]; then + local swap_size=$(($swap_max_size / 3)) + elif [ $usable_space -ge $(($swap_max_size / 4)) ]; then + local swap_size=$(($swap_max_size / 4)) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ]; then + # Create file + truncate -s 0 /swap_$app + + # set the No_COW attribute on the swapfile with chattr + chattr +C /swap_$app + + # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case + if ! fallocate -l ${swap_size}K /swap_$app; then + dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} + fi + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi +} + +ynh_del_swap() { + # If there a swap at this place + if [ -e /swap_$app ]; then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_a_sd_card() { + if [ "$(systemd-detect-virt)" != "none" ]; then + # Assume virtualization does not take place on SD card + return 1 + fi + + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ]; then + return 0 + else + return 1 + fi +} + +# Check available space before creating a temp directory. +# +# usage: ynh_smart_mktemp --min_size="Min size" +# +# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb +ynh_smart_mktemp() { + # Declare an array to define the options of this helper. + declare -Ar args_array=([s]=min_size=) + local min_size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + min_size="${min_size:-300}" + # Transform the minimum size from megabytes to kilobytes + min_size=$(($min_size * 1024)) + + # Check if there's enough free space in a directory + is_there_enough_space() { + local free_space=$(df --output=avail "$1" | sed 1d) + test $free_space -ge $min_size + } + + if is_there_enough_space /tmp; then + local tmpdir=/tmp + elif is_there_enough_space /var; then + local tmpdir=/var + elif is_there_enough_space /; then + local tmpdir=/ + elif is_there_enough_space /home; then + local tmpdir=/home + else + ynh_die "Insufficient free space to continue..." + fi + + echo "$(mktemp --directory --tmpdir="$tmpdir")" } diff --git a/hooks/backup/50-conf_manually_modified_files b/hooks/backup/50-conf_manually_modified_files index bdea14113..299b52b75 100644 --- a/hooks/backup/50-conf_manually_modified_files +++ b/hooks/backup/50-conf_manually_modified_files @@ -6,7 +6,7 @@ YNH_CWD="${YNH_BACKUP_DIR%/}/conf/manually_modified_files" mkdir -p "$YNH_CWD" cd "$YNH_CWD" -yunohost tools shell -c "from yunohost.regenconf import manually_modified_files; print('\n'.join(manually_modified_files()))" >./manually_modified_files_list +yunohost tools shell -c "from yunohost.regenconf import manually_modified_files; print('\n'.join(manually_modified_files()))" > ./manually_modified_files_list ynh_backup --src_path="./manually_modified_files_list" diff --git a/hooks/conf_regen/01-yunohost b/hooks/conf_regen/01-yunohost index dbf5bb5a5..7fb2812cd 100755 --- a/hooks/conf_regen/01-yunohost +++ b/hooks/conf_regen/01-yunohost @@ -166,7 +166,7 @@ do_init_regen() { # set default current_host [[ -f /etc/yunohost/current_host ]] \ - || echo "yunohost.org" >/etc/yunohost/current_host + || echo "yunohost.org" > /etc/yunohost/current_host # copy default services and firewall [[ -f /etc/yunohost/firewall.yml ]] \ @@ -199,8 +199,7 @@ do_init_regen() { # Change dpkg vendor # see https://wiki.debian.org/Derivatives/Guidelines#Vendor - if readlink -f /etc/dpkg/origins/default | grep -q debian; - then + if readlink -f /etc/dpkg/origins/default | grep -q debian; then rm -f /etc/dpkg/origins/default ln -s /etc/dpkg/origins/yunohost /etc/dpkg/origins/default fi @@ -218,19 +217,19 @@ do_pre_regen() { # add cron job for diagnosis to be ran at 7h and 19h + a random delay between # 0 and 20min, meant to avoid every instances running their diagnosis at # exactly the same time, which may overload the diagnosis server. - cat >$pending_dir/etc/cron.d/yunohost-diagnosis < $pending_dir/etc/cron.d/yunohost-diagnosis << EOF SHELL=/bin/bash 0 7,19 * * * root : YunoHost Automatic Diagnosis; sleep \$((RANDOM\\%1200)); yunohost diagnosis run --email > /dev/null 2>/dev/null || echo "Running the automatic diagnosis failed miserably" EOF # Cron job that upgrade the app list everyday - cat >$pending_dir/etc/cron.daily/yunohost-fetch-apps-catalog < $pending_dir/etc/cron.daily/yunohost-fetch-apps-catalog << EOF #!/bin/bash sleep \$((RANDOM%3600)); yunohost tools update apps > /dev/null EOF # Cron job that renew lets encrypt certificates if there's any that needs renewal - cat >$pending_dir/etc/cron.daily/yunohost-certificate-renew < $pending_dir/etc/cron.daily/yunohost-certificate-renew << EOF #!/bin/bash yunohost domain cert renew --email EOF @@ -238,8 +237,8 @@ EOF # If we subscribed to a dyndns domain, add the corresponding cron # - delay between 0 and 60 secs to spread the check over a 1 min window # - do not run the command if some process already has the lock, to avoid queuing hundreds of commands... - if ls -l /etc/yunohost/dyndns/K*.key 2>/dev/null; then - cat >$pending_dir/etc/cron.d/yunohost-dyndns < /dev/null; then + cat > $pending_dir/etc/cron.d/yunohost-dyndns << EOF SHELL=/bin/bash # Every 10 minutes, # - (sleep random 60 is here to spread requests over a 1-min window) @@ -254,10 +253,9 @@ EOF fi # Skip ntp if inside a container (inspired from the conf of systemd-timesyncd) - if systemctl | grep -q 'ntp.service' - then + if systemctl | grep -q 'ntp.service'; then mkdir -p ${pending_dir}/etc/systemd/system/ntp.service.d/ - cat >${pending_dir}/etc/systemd/system/ntp.service.d/ynh-override.conf < ${pending_dir}/etc/systemd/system/ntp.service.d/ynh-override.conf << EOF [Unit] ConditionCapability=CAP_SYS_TIME ConditionVirtualization=!container @@ -266,7 +264,7 @@ EOF # Make nftable conflict with yunohost-firewall mkdir -p ${pending_dir}/etc/systemd/system/nftables.service.d/ - cat >${pending_dir}/etc/systemd/system/nftables.service.d/ynh-override.conf < ${pending_dir}/etc/systemd/system/nftables.service.d/ynh-override.conf << EOF [Unit] # yunohost-firewall and nftables conflict with each other Conflicts=yunohost-firewall.service @@ -276,7 +274,7 @@ EOF # Don't suspend computer on LidSwitch mkdir -p ${pending_dir}/etc/systemd/logind.conf.d/ - cat >${pending_dir}/etc/systemd/logind.conf.d/ynh-override.conf < ${pending_dir}/etc/systemd/logind.conf.d/ynh-override.conf << EOF [Login] HandleLidSwitch=ignore HandleLidSwitchDocked=ignore @@ -320,8 +318,7 @@ do_post_regen() { find /etc/systemd/system/*.service -type f | xargs -r chown root:root find /etc/systemd/system/*.service -type f | xargs -r chmod 0644 - if ls -l /etc/php/*/fpm/pool.d/*.conf 2>/dev/null - then + if ls -l /etc/php/*/fpm/pool.d/*.conf 2>/dev/null; then chown root:root /etc/php/*/fpm/pool.d/*.conf chmod 644 /etc/php/*/fpm/pool.d/*.conf fi @@ -336,16 +333,15 @@ do_post_regen() { done # Misc configuration / state files - chown root:root $(ls /etc/yunohost/{*.yml,*.yaml,*.json,mysql,psql} 2>/dev/null | grep -vw mdns.yml) - chmod 600 $(ls /etc/yunohost/{*.yml,*.yaml,*.json,mysql,psql} 2>/dev/null) + chown root:root $(ls /etc/yunohost/{*.yml,*.yaml,*.json,mysql,psql} 2> /dev/null | grep -vw mdns.yml) + chmod 600 $(ls /etc/yunohost/{*.yml,*.yaml,*.json,mysql,psql} 2> /dev/null) # Create ssh.app and sftp.app groups if they don't exist yet grep -q '^ssh.app:' /etc/group || groupadd ssh.app grep -q '^sftp.app:' /etc/group || groupadd sftp.app # Propagates changes in systemd service config overrides - if systemctl | grep -q 'ntp.service' - then + if systemctl | grep -q 'ntp.service'; then [[ ! "$regen_conf_files" =~ "ntp.service.d/ynh-override.conf" ]] || { systemctl daemon-reload systemctl restart ntp @@ -353,7 +349,7 @@ do_post_regen() { fi [[ ! "$regen_conf_files" =~ "nftables.service.d/ynh-override.conf" ]] || systemctl daemon-reload - [[ ! "$regen_conf_files" =~ "login.conf.d/ynh-override.conf" ]] || { + [[ ! "$regen_conf_files" =~ "login.conf.d/ynh-override.conf" ]] || { systemctl daemon-reload systemctl restart systemd-logind } @@ -377,14 +373,12 @@ do_post_regen() { # Change dpkg vendor # see https://wiki.debian.org/Derivatives/Guidelines#Vendor - if readlink -f /etc/dpkg/origins/default | grep -q debian; - then + if readlink -f /etc/dpkg/origins/default | grep -q debian; then rm -f /etc/dpkg/origins/default ln -s /etc/dpkg/origins/yunohost /etc/dpkg/origins/default fi - if test -e /etc/yunohost/installed && test -e /etc/profile.d/check_yunohost_is_installed.sh - then + if test -e /etc/yunohost/installed && test -e /etc/profile.d/check_yunohost_is_installed.sh; then rm /etc/profile.d/check_yunohost_is_installed.sh fi } diff --git a/hooks/conf_regen/02-ssl b/hooks/conf_regen/02-ssl index 10ef7d83c..cc60bbb83 100755 --- a/hooks/conf_regen/02-ssl +++ b/hooks/conf_regen/02-ssl @@ -23,7 +23,7 @@ regen_local_ca() { # (Update the serial so that it's specific to this very instance) # N.B. : the weird RANDFILE thing comes from: # https://stackoverflow.com/questions/94445/using-openssl-what-does-unable-to-write-random-state-mean - RANDFILE=.rnd openssl rand -hex 19 >serial + RANDFILE=.rnd openssl rand -hex 19 > serial rm -f index.txt touch index.txt cp ${template_dir}/openssl.cnf openssl.ca.cnf @@ -51,7 +51,7 @@ regen_local_ca() { do_init_regen() { LOGFILE=/tmp/yunohost-ssl-init - echo "" >$LOGFILE + echo "" > $LOGFILE chown root:root $LOGFILE chmod 640 $LOGFILE @@ -61,24 +61,24 @@ do_init_regen() { # create default certificates if [[ ! -f "$ynh_ca" ]]; then - regen_local_ca yunohost.org >>$LOGFILE + regen_local_ca yunohost.org >> $LOGFILE fi if [[ ! -f "$ynh_crt" ]]; then - echo -e "\n# Creating initial key and certificate \n" >>$LOGFILE + echo -e "\n# Creating initial key and certificate \n" >> $LOGFILE openssl req -new \ -config "${ssl_dir}/openssl.cnf" \ -out "${ssl_dir}/certs/yunohost_csr.pem" \ -keyout "${ssl_dir}/certs/yunohost_key.pem" \ - -nodes -batch &>>$LOGFILE + -nodes -batch &>> $LOGFILE openssl ca \ -config "${ssl_dir}/openssl.cnf" \ -days 730 \ -in "${ssl_dir}/certs/yunohost_csr.pem" \ -out "${ssl_dir}/certs/yunohost_crt.pem" \ - -batch &>>$LOGFILE + -batch &>> $LOGFILE chmod 640 "${ssl_dir}/certs/yunohost_key.pem" chmod 640 "${ssl_dir}/certs/yunohost_crt.pem" @@ -104,10 +104,9 @@ do_post_regen() { current_local_ca_domain=$(openssl x509 -in $ynh_ca -text | tr ',' '\n' | grep Issuer | awk '{print $4}') main_domain=$(cat /etc/yunohost/current_host) - + # Automigrate legacy folder - if [ -e /usr/share/yunohost/yunohost-config/ssl/yunoCA ] - then + if [ -e /usr/share/yunohost/yunohost-config/ssl/yunoCA ]; then mv /usr/share/yunohost/yunohost-config/ssl/yunoCA/* ${ssl_dir} rm -rf /usr/share/yunohost/yunohost-config # Overwrite openssl.cnf because it may still contain references to the old yunoCA dir @@ -120,7 +119,7 @@ do_post_regen() { chown root:root ${ssl_dir} chmod 750 ${ssl_dir} chmod -R o-rwx ${ssl_dir} - chmod o+x ${ssl_dir}/certs + chmod o+x ${ssl_dir}/certs chmod o+r ${ssl_dir}/certs/yunohost_crt.pem if [[ "$current_local_ca_domain" != "$main_domain" ]]; then diff --git a/hooks/conf_regen/06-slapd b/hooks/conf_regen/06-slapd index b44d9d649..e7be7ba10 100755 --- a/hooks/conf_regen/06-slapd +++ b/hooks/conf_regen/06-slapd @@ -16,7 +16,7 @@ do_init_regen() { rm -rf /var/backups/*.ldapdb rm -rf /var/backups/slapd-* - debconf-set-selections </dev/null | awk '{print $2}') + curr_backend=$(grep '^database' /etc/ldap/slapd.conf 2> /dev/null | awk '{print $2}') if [ -e /etc/ldap/slapd.conf ] && [ -n "$curr_backend" ] \ && [ $curr_backend != 'mdb' ]; then backup_dir="/var/backups/dc=yunohost,dc=org-${curr_backend}-$(date +%s)" mkdir -p "$backup_dir" slapcat -b dc=yunohost,dc=org -l "${backup_dir}/dc=yunohost-dc=org.ldif" - echo "$backup_dir" >"$tmp_backup_dir_file" + echo "$backup_dir" > "$tmp_backup_dir_file" fi # create needed directories @@ -151,7 +151,7 @@ objectClass: top" _regenerate_slapd_conf # If there's a backup, re-import its data - backup_dir=$(cat "$tmp_backup_dir_file" 2>/dev/null || true) + backup_dir=$(cat "$tmp_backup_dir_file" 2> /dev/null || true) if [[ -n "$backup_dir" && -f "${backup_dir}/dc=yunohost-dc=org.ldif" ]]; then # regenerate LDAP config directory and import database as root echo "Import the database using slapadd" diff --git a/hooks/conf_regen/10-apt b/hooks/conf_regen/10-apt index 84955ae64..caa76537a 100755 --- a/hooks/conf_regen/10-apt +++ b/hooks/conf_regen/10-apt @@ -2,7 +2,7 @@ set -e -readonly YNH_DEFAULT_PHP_VERSION=7.4 +readonly YNH_DEFAULT_PHP_VERSION=8.2 do_pre_regen() { pending_dir=$1 @@ -17,14 +17,14 @@ do_pre_regen() { echo " Package: php-common Pin: origin \"packages.sury.org\" -Pin-Priority: 500" >>"${pending_dir}/etc/apt/preferences.d/extra_php_version" +Pin-Priority: 500" >> "${pending_dir}/etc/apt/preferences.d/extra_php_version" packages_to_refuse_from_sury="php php-* openssl libssl1.1 libssl-dev" for package in $packages_to_refuse_from_sury; do echo " Package: $package Pin: origin \"packages.sury.org\" -Pin-Priority: -1" >>"${pending_dir}/etc/apt/preferences.d/extra_php_version" +Pin-Priority: -1" >> "${pending_dir}/etc/apt/preferences.d/extra_php_version" done # Add yarn @@ -68,8 +68,7 @@ Pin-Priority: -1 Package: bind9 Pin: release * Pin-Priority: -1 -" >>"${pending_dir}/etc/apt/preferences.d/ban_packages" - +" >> "${pending_dir}/etc/apt/preferences.d/ban_packages" } @@ -77,14 +76,13 @@ do_post_regen() { regen_conf_files=$1 # Purge expired keys (such as sury 95BD4743) - EXPIRED_KEYS="$(LC_ALL='en_US.UTF-8' apt-key list 2>/dev/null | grep -A1 'expired:' | grep -v 'expired\|^-' | sed 's/\s//g')" - for KEY in $EXPIRED_KEYS; do apt-key del $KEY 2>/dev/null; done + EXPIRED_KEYS="$(LC_ALL='en_US.UTF-8' apt-key list 2> /dev/null | grep -A1 'expired:' | grep -v 'expired\|^-' | sed 's/\s//g')" + for KEY in $EXPIRED_KEYS; do apt-key del $KEY 2> /dev/null; done # Add sury key # We do this only at the post regen and if the key doesn't already exists, because we don't want the regenconf to fuck everything up if the regenconf runs while the network is down - if [[ ! -s /etc/apt/trusted.gpg.d/extra_php_version.gpg ]] - then - wget --timeout 900 --quiet "https://packages.sury.org/php/apt.gpg" --output-document=- | gpg --dearmor >"/etc/apt/trusted.gpg.d/extra_php_version.gpg" + if [[ ! -s /etc/apt/trusted.gpg.d/extra_php_version.gpg ]]; then + wget --timeout 900 --quiet "https://packages.sury.org/php/apt.gpg" --output-document=- | gpg --dearmor > "/etc/apt/trusted.gpg.d/extra_php_version.gpg" fi # Similar to Sury @@ -94,8 +92,7 @@ do_post_regen() { fi # Make sure php7.4 is the default version when using php in cli - if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION - then + if test -e /usr/bin/php$YNH_DEFAULT_PHP_VERSION; then update-alternatives --set php /usr/bin/php$YNH_DEFAULT_PHP_VERSION fi } diff --git a/hooks/conf_regen/15-nginx b/hooks/conf_regen/15-nginx index e4683ff92..88cb6dd59 100755 --- a/hooks/conf_regen/15-nginx +++ b/hooks/conf_regen/15-nginx @@ -38,7 +38,7 @@ do_init_regen() { rm -f "${nginx_dir}/sites-enabled/default" # Restart nginx if conf looks good, otherwise display error and exit unhappy - nginx -t 2>/dev/null || { + nginx -t 2> /dev/null || { nginx -t exit 1 } @@ -86,16 +86,14 @@ do_pre_regen() { export domain_cert_ca=$(echo $cert_status \ | jq ".certificates.\"$domain\".CA_type" \ | tr -d '"') - if echo "$mail_domain_list" | grep -q "^$domain$" - then + if echo "$mail_domain_list" | grep -q "^$domain$"; then export mail_enabled="True" else export mail_enabled="False" fi ynh_render_template "server.tpl.conf" "${nginx_conf_dir}/${domain}.conf" - if [ $mail_enabled == "True" ] - then + if [ $mail_enabled == "True" ]; then ynh_render_template "autoconfig.tpl.xml" "${mail_autoconfig_dir}/config-v1.1.xml" fi @@ -116,7 +114,7 @@ do_pre_regen() { done # remove old mail-autoconfig files - autoconfig_files=$(ls -1 /var/www/.well-known/*/autoconfig/mail/config-v1.1.xml 2>/dev/null || true) + autoconfig_files=$(ls -1 /var/www/.well-known/*/autoconfig/mail/config-v1.1.xml 2> /dev/null || true) for file in $autoconfig_files; do domain=$(basename $(readlink -f $(dirname $file)/../..)) [[ $YNH_DOMAINS =~ $domain ]] \ @@ -131,8 +129,7 @@ do_pre_regen() { do_post_regen() { regen_conf_files=$1 - if ls -l /etc/nginx/conf.d/*.d/*.conf - then + if ls -l /etc/nginx/conf.d/*.d/*.conf; then chown root:root /etc/nginx/conf.d/*.d/*.conf chmod 644 /etc/nginx/conf.d/*.d/*.conf fi @@ -145,7 +142,7 @@ do_post_regen() { done # Reload nginx if conf looks good, otherwise display error and exit unhappy - nginx -t 2>/dev/null || { + nginx -t 2> /dev/null || { nginx -t exit 1 } diff --git a/hooks/conf_regen/19-postfix b/hooks/conf_regen/19-postfix index d955fd60d..d5e117d2f 100755 --- a/hooks/conf_regen/19-postfix +++ b/hooks/conf_regen/19-postfix @@ -43,7 +43,7 @@ do_pre_regen() { chown postfix ${pending_dir}/etc/postfix chown postfix ${pending_dir}/etc/postfix/sasl_passwd - cat <<<"[${relay_host}]:${relay_port} ${relay_user}:${relay_password}" >${postfix_dir}/sasl_passwd + cat <<< "[${relay_host}]:${relay_port} ${relay_user}:${relay_password}" > ${postfix_dir}/sasl_passwd fi # Use this postfix server as a backup MX @@ -51,10 +51,8 @@ do_pre_regen() { export backup_mx_emails="$(yunohost settings get 'email.smtp.smtp_backup_mx_emails_whitelisted' | sed "s/,/ /g")" rm -f ${postfix_dir}/relay_recipients touch ${postfix_dir}/relay_recipients - if [ -n "${backup_mx_domains}" ] && [ -n "${backup_mx_emails}" ] - then - for mail in ${backup_mx_emails} - do + if [ -n "${backup_mx_domains}" ] && [ -n "${backup_mx_emails}" ]; then + for mail in ${backup_mx_emails}; do echo "$mail OK" >> ${postfix_dir}/relay_recipients done postmap ${postfix_dir}/relay_recipients @@ -68,7 +66,7 @@ do_pre_regen() { cat postsrsd \ | sed "s/{{ main_domain }}/${main_domain}/g" \ | sed "s/{{ domain_list }}/${domain_list}/g" \ - >"${default_dir}/postsrsd" + > "${default_dir}/postsrsd" # adapt it for IPv4-only hosts ipv6="$(jq -r '.smtp_allow_ipv6' <<< "$YNH_SETTINGS" | int_to_bool)" diff --git a/hooks/conf_regen/25-dovecot b/hooks/conf_regen/25-dovecot index 6421cfafa..f45c6da9b 100755 --- a/hooks/conf_regen/25-dovecot +++ b/hooks/conf_regen/25-dovecot @@ -41,7 +41,7 @@ do_post_regen() { mkdir -p "/etc/dovecot/yunohost.d/post-ext.d" # create vmail user - id vmail >/dev/null 2>&1 \ + id vmail > /dev/null 2>&1 \ || { mkdir -p /var/vmail; adduser --system --ingroup mail --uid 500 vmail --home /var/vmail --no-create-home; } # Delete legacy home for vmail that existed in the past but was empty, poluting /home/ diff --git a/hooks/conf_regen/34-mysql b/hooks/conf_regen/34-mysql index 9ef8efe21..45456e63d 100755 --- a/hooks/conf_regen/34-mysql +++ b/hooks/conf_regen/34-mysql @@ -3,8 +3,7 @@ set -e . /usr/share/yunohost/helpers -if ! dpkg --list | grep -q 'ii *mariadb-server ' -then +if ! dpkg --list | grep -q 'ii *mariadb-server '; then echo 'mysql/mariadb is not installed, skipping' exit 0 fi diff --git a/hooks/conf_regen/35-postgresql b/hooks/conf_regen/35-postgresql index 3a3843d69..3acc4bb44 100755 --- a/hooks/conf_regen/35-postgresql +++ b/hooks/conf_regen/35-postgresql @@ -3,42 +3,42 @@ set -e . /usr/share/yunohost/helpers -if ! dpkg --list | grep -q "ii *postgresql-$PSQL_VERSION " -then +if ! dpkg --list | grep -q "ii *postgresql-$PSQL_VERSION "; then echo 'postgresql is not installed, skipping' exit 0 fi -if [ ! -e "/etc/postgresql/$PSQL_VERSION" ] -then +if [ ! -e "/etc/postgresql/$PSQL_VERSION" ]; then ynh_die --message="It looks like postgresql was not properly configured ? /etc/postgresql/$PSQL_VERSION is missing ... Could be due to a locale issue, c.f.https://serverfault.com/questions/426989/postgresql-etc-postgresql-doesnt-exist" fi - do_pre_regen() { return 0 } do_post_regen() { #regen_conf_files=$1 - + # Make sure postgresql is started and enabled # (N.B. : to check the active state, we check the cluster state because # postgresql could be flagged as active even though the cluster is in # failed state because of how the service is configured..) systemctl is-active postgresql@$PSQL_VERSION-main -q || ynh_systemd_action --service_name=postgresql --action=restart systemctl is-enabled postgresql -q || systemctl enable postgresql --quiet - + # If this is the very first time, we define the root password # and configure a few things if [ ! -f "$PSQL_ROOT_PWD_FILE" ] || [ -z "$(cat $PSQL_ROOT_PWD_FILE)" ]; then - ynh_string_random >$PSQL_ROOT_PWD_FILE + ynh_string_random > $PSQL_ROOT_PWD_FILE fi - [ ! -e $PSQL_ROOT_PWD_FILE ] || { chown root:postgres $PSQL_ROOT_PWD_FILE; chmod 440 $PSQL_ROOT_PWD_FILE; } - + [ ! -e $PSQL_ROOT_PWD_FILE ] || { + chown root:postgres $PSQL_ROOT_PWD_FILE + chmod 440 $PSQL_ROOT_PWD_FILE + } + sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$(cat $PSQL_ROOT_PWD_FILE)'" postgres - + # force all user to connect to local databases using hashed passwords # https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF # Note: we can't use peer since YunoHost create users with nologin diff --git a/hooks/conf_regen/37-mdns b/hooks/conf_regen/37-mdns index bd813e588..6fc248ac2 100755 --- a/hooks/conf_regen/37-mdns +++ b/hooks/conf_regen/37-mdns @@ -5,8 +5,7 @@ set -e _generate_config() { echo "domains:" # Add yunohost.local (only if yunohost.local ain't already in ynh_domains) - if ! echo "$YNH_DOMAINS" | tr ' ' '\n' | grep -q --line-regexp 'yunohost.local' - then + if ! echo "$YNH_DOMAINS" | tr ' ' '\n' | grep -q --line-regexp 'yunohost.local'; then echo " - yunohost.local" fi for domain in $YNH_DOMAINS; do @@ -15,10 +14,8 @@ _generate_config() { [[ "$domain" =~ ^[^.]+\.local$ ]] || continue echo " - $domain" done - if [[ -e /etc/yunohost/mdns.aliases ]] - then - for localalias in $(cat /etc/yunohost/mdns.aliases | grep -v "^ *$") - do + if [[ -e /etc/yunohost/mdns.aliases ]]; then + for localalias in $(cat /etc/yunohost/mdns.aliases | grep -v "^ *$"); do echo " - $localalias.local" done fi @@ -37,10 +34,10 @@ do_pre_regen() { mkdir -p ${pending_dir}/etc/systemd/system/ cp yunomdns.service ${pending_dir}/etc/systemd/system/ - getent passwd mdns &>/dev/null || useradd --no-create-home --shell /usr/sbin/nologin --system --user-group mdns + getent passwd mdns &> /dev/null || useradd --no-create-home --shell /usr/sbin/nologin --system --user-group mdns mkdir -p ${pending_dir}/etc/yunohost - _generate_config >${pending_dir}/etc/yunohost/mdns.yml + _generate_config > ${pending_dir}/etc/yunohost/mdns.yml } do_post_regen() { diff --git a/hooks/conf_regen/43-dnsmasq b/hooks/conf_regen/43-dnsmasq index 90e3ed2d7..c53a7ef6f 100755 --- a/hooks/conf_regen/43-dnsmasq +++ b/hooks/conf_regen/43-dnsmasq @@ -18,12 +18,12 @@ do_pre_regen() { cp plain/etcdefault ${pending_dir}/etc/default/dnsmasq # add resolver file - cat plain/resolv.dnsmasq.conf | grep "^nameserver" | shuf >${pending_dir}/etc/resolv.dnsmasq.conf + cat plain/resolv.dnsmasq.conf | grep "^nameserver" | shuf > ${pending_dir}/etc/resolv.dnsmasq.conf # retrieve variables - ipv4=$(curl --max-time 10 -s -4 https://ip.yunohost.org 2>/dev/null || true) + ipv4=$(curl --max-time 10 -s -4 https://ip.yunohost.org 2> /dev/null || true) ynh_validate_ip4 "$ipv4" || ipv4='127.0.0.1' - ipv6=$(curl --max-time 10 -s -6 https://ip6.yunohost.org 2>/dev/null || true) + ipv6=$(curl --max-time 10 -s -6 https://ip6.yunohost.org 2> /dev/null || true) ynh_validate_ip6 "$ipv6" || ipv6='' interfaces="$(ip -j addr show | jq -r '[.[].ifname]|join(" ")')" wireless_interfaces="lo" @@ -51,8 +51,7 @@ do_pre_regen() { conf_files=$(ls -1 /etc/dnsmasq.d \ | awk '/^[^\.]+\.[^\.]+.*$/ { print $1 }') for domain in $conf_files; do - if [[ ! $YNH_DOMAINS =~ $domain ]] && [[ ! $domain =~ \.local$ ]] - then + if [[ ! $YNH_DOMAINS =~ $domain ]] && [[ ! $domain =~ \.local$ ]]; then touch "${dnsmasq_dir}/${domain}" fi done @@ -68,27 +67,27 @@ do_post_regen() { # Fuck it, those domain/search entries from dhclient are usually annoying # lying shit from the ISP trying to MiTM if grep -q -E "^ *(domain|search)" /run/resolvconf/resolv.conf; then - if grep -q -E "^ *(domain|search)" /run/resolvconf/interface/*.dhclient 2>/dev/null; then + if grep -q -E "^ *(domain|search)" /run/resolvconf/interface/*.dhclient 2> /dev/null; then sed -E "s/^(domain|search)/#\1/g" -i /run/resolvconf/interface/*.dhclient fi - grep -q '^supersede domain-name "";' /etc/dhcp/dhclient.conf 2>/dev/null || echo 'supersede domain-name "";' >>/etc/dhcp/dhclient.conf - grep -q '^supersede domain-search "";' /etc/dhcp/dhclient.conf 2>/dev/null || echo 'supersede domain-search "";' >>/etc/dhcp/dhclient.conf - grep -q '^supersede search "";' /etc/dhcp/dhclient.conf 2>/dev/null || echo 'supersede search "";' >>/etc/dhcp/dhclient.conf + grep -q '^supersede domain-name "";' /etc/dhcp/dhclient.conf 2> /dev/null || echo 'supersede domain-name "";' >> /etc/dhcp/dhclient.conf + grep -q '^supersede domain-search "";' /etc/dhcp/dhclient.conf 2> /dev/null || echo 'supersede domain-search "";' >> /etc/dhcp/dhclient.conf + grep -q '^supersede search "";' /etc/dhcp/dhclient.conf 2> /dev/null || echo 'supersede search "";' >> /etc/dhcp/dhclient.conf systemctl restart resolvconf fi # Some stupid things like rabbitmq-server used by onlyoffice won't work if # the *short* hostname doesn't exists in /etc/hosts -_- short_hostname=$(hostname -s) - grep -q "127.0.0.1.*$short_hostname" /etc/hosts || echo -e "\n127.0.0.1\t$short_hostname" >>/etc/hosts + grep -q "127.0.0.1.*$short_hostname" /etc/hosts || echo -e "\n127.0.0.1\t$short_hostname" >> /etc/hosts [[ -n "$regen_conf_files" ]] || return 0 # Remove / disable services likely to conflict with dnsmasq for SERVICE in systemd-resolved bind9; do - systemctl is-enabled $SERVICE &>/dev/null && systemctl disable $SERVICE 2>/dev/null - systemctl is-active $SERVICE &>/dev/null && systemctl stop $SERVICE + systemctl is-enabled $SERVICE &> /dev/null && systemctl disable $SERVICE 2> /dev/null + systemctl is-active $SERVICE &> /dev/null && systemctl stop $SERVICE done systemctl restart dnsmasq diff --git a/hooks/conf_regen/52-fail2ban b/hooks/conf_regen/52-fail2ban index 0789556c4..118a33eaf 100755 --- a/hooks/conf_regen/52-fail2ban +++ b/hooks/conf_regen/52-fail2ban @@ -25,8 +25,7 @@ do_pre_regen() { do_post_regen() { regen_conf_files=$1 - if ls -l /etc/fail2ban/jail.d/*.conf - then + if ls -l /etc/fail2ban/jail.d/*.conf; then chown root:root /etc/fail2ban/jail.d/*.conf chmod 644 /etc/fail2ban/jail.d/*.conf fi diff --git a/maintenance/shfmt.sh b/maintenance/shfmt.sh new file mode 100755 index 000000000..dcfc25f0f --- /dev/null +++ b/maintenance/shfmt.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +shfmt_args=( + --indent 4 + --keep-padding # keep column alignment paddings + --space-redirects # redirect operators will be followed by a space + --binary-next-line # binary ops like && and | may start a line + --case-indent # switch cases will be indented +) + +shfmt "${shfmt_args[@]}" "$@" \ + helpers/helpers \ + helpers/helpers.v2.1.d/* \ + helpers/helpers.v2.d/* \ + hooks/*