From dfa27c49503da0afaf8e74169e9d7e62b4bdf64a Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 01:06:29 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 2 + manifest.toml | 3 +- scripts/_common.sh | 9 +-- scripts/actions/reset_db | 44 ------------ scripts/backup | 17 ++--- scripts/config | 140 --------------------------------------- scripts/install | 48 ++++++-------- scripts/remove | 18 ++--- scripts/restore | 28 +++----- scripts/upgrade | 57 +++++++--------- 10 files changed, 70 insertions(+), 296 deletions(-) delete mode 100755 scripts/actions/reset_db delete mode 100644 scripts/config diff --git a/.gitignore b/.gitignore index f0ff6f7..6929c0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.swp *~ Notes +*.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 3ccbd61..c4987da 100644 --- a/manifest.toml +++ b/manifest.toml @@ -17,7 +17,8 @@ website = "http://minidlna.sourceforge.net" cpe = "cpe:2.3:a:readymedia_project:readymedia" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false diff --git a/scripts/_common.sh b/scripts/_common.sh index e97e4ad..a029d15 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= #================================================= @@ -9,7 +9,7 @@ #================================================= IS_PACKAGE_CHECK() { - if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then + if ynh_in_ci_tests; then return 0 else return 1 @@ -19,8 +19,3 @@ IS_PACKAGE_CHECK() { #================================================= # FUTUR OFFICIAL HELPERS #================================================= - - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= diff --git a/scripts/actions/reset_db b/scripts/actions/reset_db deleted file mode 100755 index 0f4c22b..0000000 --- a/scripts/actions/reset_db +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} - -#================================================= -# CHECK IF ARGUMENTS ARE CORRECT -#================================================= - -#================================================= -# CHECK IF AN ACTION HAS TO BE DONE -#================================================= - -#================================================= -# SPECIFIC ACTION -#================================================= -# RESET THE DATABASE -#================================================= -ynh_script_progression --message="Resetting the database..." --weight=9 - -# Get the last value for `db_dir` in the config file of minidlna -db_directory=$(tac /etc/minidlna.conf | grep --max-count=1 "db_dir=" | cut -d'=' -f 2) - -ynh_systemd_action --action=stop --service_name=$app -ynh_secure_remove --file="$db_directory/files.db" -ynh_systemd_action --action=start --service_name=$app - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/backup b/scripts/backup index 6cc779f..9863f9e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,29 +1,20 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/sysctl.d/90-inotify_minidlna.conf" +ynh_backup "/etc/sysctl.d/90-inotify_minidlna.conf" -ynh_backup --src_path="/etc/minidlna.conf" +ynh_backup "/etc/minidlna.conf" #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/config b/scripts/config deleted file mode 100644 index f80be5c..0000000 --- a/scripts/config +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source _common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} - -#================================================= -# SPECIFIC CODE -#================================================= -# DECLARE GENERIC FUNCTION -#================================================= - -config_file="/etc/minidlna.conf" - -get_config_value() { - option_name="$1" - # Get the value of this option in the config file - grep "^$option_name=" "$config_file" | cut -d'=' -f2 -} - -#================================================= -# LOAD VALUES -#================================================= - -# Load the real value from the app config or elsewhere. -# Then get the value from the form. -# If the form has a value for a variable, take the value from the form, -# Otherwise, keep the value from the app config. - -# root_container -old_root_container="$(get_config_value root_container)" -root_container="${YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_ROOT_CONTAINER:-$old_root_container}" - -# friendly_name -old_friendly_name="$(get_config_value friendly_name)" -friendly_name="${YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_FRIENDLY_NAME:-$old_friendly_name}" - -# Overwrite settings.json file -old_overwrite_settings="$(ynh_app_setting_get --app=$app --key=overwrite_settings)" -overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}" - -# Type of admin mail configuration -old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)" -admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}" - -#================================================= -# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND -#================================================= - -show_config() { - # here you are supposed to read some config file/database/other then print the values - # echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" - - if [ "$root_container" = "." ]; then - root_container="Standard container" - elif [ "$root_container" = "B" ]; then - root_container="Browse Directory" - elif [ "$root_container" = "M" ]; then - root_container="Music" - elif [ "$root_container" = "P" ]; then - root_container="Pictures" - elif [ "$root_container" = "V" ]; then - root_container="Video" - fi - ynh_return "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_ROOT_CONTAINER=$root_container" - ynh_return "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_FRIENDLY_NAME=$friendly_name" - - ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings" - - ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" -} - -#================================================= -# MODIFY THE CONFIGURATION -#================================================= - -apply_config() { - restart_minidlna=0 - - # Change configuration if needed - # root_container - if [ "$root_container" = "Standard container" ]; then - root_container="." - elif [ "$root_container" = "Browse Directory" ]; then - root_container="B" - elif [ "$root_container" = "Music" ]; then - root_container="M" - elif [ "$root_container" = "Pictures" ]; then - root_container="P" - elif [ "$root_container" = "Video" ]; then - root_container="V" - fi - if [ "$root_container" != "$old_root_container" ] - then - ynh_replace_string --match_string="root_container=.*" --replace_string="root_container=$root_container" --target_file="$config_file" - ynh_app_setting_set --app=$app --key=root_container --value="$root_container" - restart_minidlna=1 - fi - - # friendly_name - if [ "$friendly_name" != "$old_friendly_name" ] - then - ynh_replace_string --match_string="friendly_name=.*" --replace_string="friendly_name=$friendly_name" --target_file="$config_file" - ynh_app_setting_set --app=$app --key=friendly_name --value="$friendly_name" - restart_minidlna=1 - fi - - if [ $restart_minidlna -eq 1 ] - then - ynh_systemd_action --service_name=$app --action="restart" - fi - - # Set overwrite_settings - ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings" - - # Set admin_mail_html - ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" -} - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT -#================================================= - -case $1 in - show) show_config;; - apply) apply_config;; -esac diff --git a/scripts/install b/scripts/install index 8c01510..3aa7b67 100644 --- a/scripts/install +++ b/scripts/install @@ -1,45 +1,37 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=2 +ynh_script_progression "Storing installation settings..." -ynh_app_setting_set --app="$app" --key=overwrite_settings --value=1 -ynh_app_setting_set --app="$app" --key=admin_mail_html --value=1 +ynh_app_setting_set --key=overwrite_settings --value=1 +ynh_app_setting_set --key=admin_mail_html --value=1 -#================================================= -# STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=15 +ynh_script_progression "Configuring firewall..." # Discovery Protocol SSDP for UPNP. -ynh_exec_fully_quiet yunohost firewall allow --no-upnp UDP 1900 +yunohost firewall allow --no-upnp UDP 1900 #================================================= # SPECIFIC SETUP #================================================= # CREATE YUNOHOST.MULTIMEDIA DIRECTORY #================================================= -ynh_script_progression --message="Creating yunohost.multimedia directory..." --weight=8 +ynh_script_progression "Creating yunohost.multimedia directory..." ynh_multimedia_build_main_dir #================================================= # INCREASE INOTIFY'S LIMITS #================================================= -ynh_script_progression --message="Increasing inotify's limits..." --weight=1 +ynh_script_progression "Increasing inotify's limits..." # Increase the maximum number of files inotify can monitor. cp -a ../conf/90-inotify_minidlna.conf /etc/sysctl.d/ @@ -51,38 +43,38 @@ fi #================================================= # CONFIGURE MINIDLNA #================================================= -ynh_script_progression --message="Configuring MiniDLNA..." --weight=2 +ynh_script_progression "Configuring MiniDLNA..." -ynh_replace_string --match_string="^#*media_dir=.*" --replace_string="media_dir=/home/yunohost.multimedia/share" --target_file=/etc/minidlna.conf -ynh_replace_string --match_string="^#*port=.*" --replace_string="port=$port" --target_file=/etc/minidlna.conf +ynh_replace --match="^#*media_dir=.*" --replace="media_dir=/home/yunohost.multimedia/share" --file=/etc/minidlna.conf +ynh_replace --match="^#*port=.*" --replace="port=$port" --file=/etc/minidlna.conf friendly_name="Yunohost DLNA" -ynh_app_setting_set --app="$app" --key=friendly_name --value="$friendly_name" -ynh_replace_string --match_string="^#*friendly_name=.*" --replace_string="friendly_name=$friendly_name" --target_file=/etc/minidlna.conf +ynh_app_setting_set --key=friendly_name --value="$friendly_name" +ynh_replace --match="^#*friendly_name=.*" --replace="friendly_name=$friendly_name" --file=/etc/minidlna.conf root_container="B" -ynh_replace_string --match_string="^#*root_container=.*" --replace_string="root_container=$root_container" --target_file=/etc/minidlna.conf -ynh_app_setting_set --app="$app" --key=root_container --value="$root_container" -ynh_replace_string --match_string="^#wide_links=.*" --replace_string="wide_links=yes" --target_file=/etc/minidlna.conf +ynh_replace --match="^#*root_container=.*" --replace="root_container=$root_container" --file=/etc/minidlna.conf +ynh_app_setting_set --key=root_container --value="$root_container" +ynh_replace --match="^#wide_links=.*" --replace="wide_links=yes" --file=/etc/minidlna.conf # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="/etc/minidlna.conf" +ynh_store_file_checksum "/etc/minidlna.conf" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add "$app" --log="/var/log/$app.log" --needs_exposed_ports="1900" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=4 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="restart" --log_path="/var/log/$app.log" +ynh_systemctl --service="$app" --action="restart" --log_path="/var/log/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index b918c7a..77b7946 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -16,8 +10,8 @@ source /usr/share/yunohost/helpers #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null; then - ynh_script_progression --message="Removing $app service integration..." +if ynh_hide_warnings yunohost service status $app >/dev/null; then + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi @@ -25,17 +19,17 @@ fi # CLOSE A PORT #================================================= -ynh_exec_fully_quiet yunohost firewall disallow UDP 1900 +yunohost firewall disallow UDP 1900 #================================================= # SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." --weight=1 +ynh_script_progression "Removing various files..." if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then - ynh_secure_remove --file="/etc/sysctl.d/90-inotify_minidlna.conf" + ynh_safe_rm "/etc/sysctl.d/90-inotify_minidlna.conf" # Reload the kernel configuration. if ! IS_PACKAGE_CHECK # LXC doesn't allow sysctl to play with kernel options. then @@ -47,4 +41,4 @@ fi # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index c8370de..d35ba1c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -15,47 +9,47 @@ source /usr/share/yunohost/helpers #================================================= # OPEN PORTS #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=15 +ynh_script_progression "Configuring firewall..." # Discovery Protocol SSDP for UPNP. -ynh_exec_fully_quiet yunohost firewall allow --no-upnp UDP 1900 +yunohost firewall allow --no-upnp UDP 1900 #================================================= # CREATE YUNOHOST.MULTIMEDIA DIRECTORY #================================================= -ynh_script_progression --message="Creating yunohost.multimedia directory..." --weight=6 +ynh_script_progression "Creating yunohost.multimedia directory..." ynh_multimedia_build_main_dir #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring various files..." --weight=1 +ynh_script_progression "Restoring various files..." -ynh_restore_file --origin_path="/etc/sysctl.d/90-inotify_minidlna.conf" +ynh_restore "/etc/sysctl.d/90-inotify_minidlna.conf" if ! IS_PACKAGE_CHECK; then # LXC doesn't allow sysctl to play with kernel options. sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf fi # Delete the current config of minidlna, in order to replace it by the version from the backup -ynh_secure_remove --file="/etc/minidlna.conf" -ynh_restore_file --origin_path="/etc/minidlna.conf" +ynh_safe_rm "/etc/minidlna.conf" +ynh_restore "/etc/minidlna.conf" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add "$app" --log="/var/log/$app.log" --needs_exposed_ports="1900" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action=restart --log_path="/var/log/$app.log" +ynh_systemctl --service="$app" --action=restart --log_path="/var/log/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index ea5b6e4..d1a40d0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,62 +1,51 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." # If overwrite_settings doesn't exist, create it +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=overwrite_settings --value=1 if [ -z "${overwrite_settings:-}" ]; then overwrite_settings=1 - ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings + ynh_app_setting_set --key=overwrite_settings --value=$overwrite_settings fi # If root_container doesn't exist, create it +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=root_container --value="B" if [ -z "${root_container:-}" ]; then root_container="B" - ynh_app_setting_set --app=$app --key=root_container --value=$root_container + ynh_app_setting_set --key=root_container --value=$root_container fi # If friendly_name doesn't exist, create it +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=friendly_name --value="YunoHost DLNA" if [ -z "${friendly_name:-}" ]; then friendly_name="YunoHost DLNA" - ynh_app_setting_set --app=$app --key=friendly_name --value=$friendly_name + ynh_app_setting_set --key=friendly_name --value=$friendly_name fi # If version exists, remove the backport source list, as it's no longer used. if [ -n "${version:-}" ]; then - ynh_secure_remove --file="/etc/apt/sources.list.d/minidlna.list" - ynh_app_setting_delete --app=$app --key=version + ynh_safe_rm "/etc/apt/sources.list.d/minidlna.list" + ynh_app_setting_delete --key=version fi -#================================================= -# SPECIFIC UPGRADE #================================================= # UPGRADE THE YUNOHOST.MULTIMEDIA DIRECTORY #================================================= -ynh_script_progression --message="Upgrading the yunohost.multimedia directory..." --weight=3 +ynh_script_progression "Upgrading the yunohost.multimedia directory..." ynh_multimedia_build_main_dir #================================================= # INCREASE INOTIFY'S LIMITS #================================================= -ynh_script_progression --message="Increasing inotify's limits..." --weight=2 +ynh_script_progression "Increasing inotify's limits..." # Increase the maximum number of files inotify can monitor. cp -a ../conf/90-inotify_minidlna.conf /etc/sysctl.d/ @@ -69,40 +58,40 @@ fi #================================================= # CONFIGURE MINIDLNA #================================================= -ynh_script_progression --message="Reconfiguring MiniDLNA..." --weight=2 +ynh_script_progression "Reconfiguring MiniDLNA..." # Overwrite the settings config file only if it's allowed if [ $overwrite_settings -eq 1 ] then # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. - ynh_backup_if_checksum_is_different --file="/etc/minidlna.conf" + ynh_backup_if_checksum_is_different "/etc/minidlna.conf" - ynh_replace_string --match_string="^#*media_dir=.*" --replace_string="media_dir=/home/yunohost.multimedia/share" --target_file=/etc/minidlna.conf - ynh_replace_string --match_string="^#*port=.*" --replace_string="port=$port" --target_file=/etc/minidlna.conf - ynh_replace_string --match_string="^#*friendly_name=.*" --replace_string="friendly_name=$friendly_name" --target_file=/etc/minidlna.conf - ynh_replace_string --match_string="^#*root_container=.*" --replace_string="root_container=$root_container" --target_file=/etc/minidlna.conf - ynh_replace_string --match_string="^#wide_links=.*" --replace_string="wide_links=yes" --target_file=/etc/minidlna.conf + ynh_replace --match="^#*media_dir=.*" --replace="media_dir=/home/yunohost.multimedia/share" --file=/etc/minidlna.conf + ynh_replace --match="^#*port=.*" --replace="port=$port" --file=/etc/minidlna.conf + ynh_replace --match="^#*friendly_name=.*" --replace="friendly_name=$friendly_name" --file=/etc/minidlna.conf + ynh_replace --match="^#*root_container=.*" --replace="root_container=$root_container" --file=/etc/minidlna.conf + ynh_replace --match="^#wide_links=.*" --replace="wide_links=yes" --file=/etc/minidlna.conf # Calculate and store the config file checksum into the app settings - ynh_store_file_checksum --file="/etc/minidlna.conf" + ynh_store_file_checksum "/etc/minidlna.conf" fi #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app --log="/var/log/$app.log" --needs_exposed_ports="1900" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=7 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="restart" --log_path="/var/log/$app.log" +ynh_systemctl --service=$app --action="restart" --log_path="/var/log/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"