1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minidlna_ynh.git synced 2024-09-03 19:36:34 +02:00
minidlna_ynh/scripts/config
2022-03-13 17:21:40 +01:00

140 lines
4.6 KiB
Bash

#!/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