1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minidlna_ynh.git synced 2024-09-03 19:36:34 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-31 01:06:29 +02:00 committed by Alexandre Aubin
parent aa08d886e2
commit dfa27c4950
10 changed files with 70 additions and 296 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*.swp
*~
Notes
*.sw[op]
.DS_Store

View file

@ -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

View file

@ -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
#=================================================

View file

@ -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

View file

@ -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)."

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"