mirror of
https://github.com/YunoHost-Apps/minidlna_ynh.git
synced 2024-09-03 19:36:34 +02:00
Merge pull request #12 from YunoHost-Apps/testing
Panel-config + actions fully tested
This commit is contained in:
commit
d399c61f77
11 changed files with 397 additions and 25 deletions
25
actions.json
Normal file
25
actions.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
[{
|
||||
"id": "install_standard",
|
||||
"name": "Install the version from stable repository",
|
||||
"command": "/bin/bash scripts/actions/install_standard",
|
||||
"user": "root",
|
||||
"accepted_return_codes": [0]
|
||||
},
|
||||
{
|
||||
"id": "install_backports",
|
||||
"name": "Install the version from backports repository",
|
||||
"command": "/bin/bash scripts/actions/install_backports",
|
||||
"user": "root",
|
||||
"accepted_return_codes": [0]
|
||||
},
|
||||
{
|
||||
"id": "reset_db",
|
||||
"name": "Reinitialise the database",
|
||||
"command": "/bin/bash scripts/actions/reset_db",
|
||||
"user": "root",
|
||||
"accepted_return_codes": [0],
|
||||
"description": {
|
||||
"en": "Remove the database and force Minidlna to create a new one.",
|
||||
"fr": "Supprime la base de donnée et force Minidlna a en recréer une nouvelle."
|
||||
}
|
||||
}]
|
38
config_panel.json
Normal file
38
config_panel.json
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "Minidlna configuration panel",
|
||||
"version": "0.1",
|
||||
"panel": [{
|
||||
"name": "Minidlna configuration",
|
||||
"id": "main",
|
||||
"sections": [{
|
||||
"name": "Minidlna configuration",
|
||||
"id": "minidlna_configuration",
|
||||
"options": [{
|
||||
"name": "Type of directory shown to the clients ?",
|
||||
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>Standard container, Browse Directory, Music, Pictures or Video.",
|
||||
"id": "root_container",
|
||||
"type": "text",
|
||||
"//": "\"choices\" : [\"Standard container\", \"Browse Directory\", \"Music\", \"Pictures\", \"Video\"]",
|
||||
"default" : "Browse Directory"
|
||||
},
|
||||
{
|
||||
"name": "Name of DLNA server shown to clients ?",
|
||||
"id": "friendly_name",
|
||||
"type": "text",
|
||||
"default": "Yunohost DLNA"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "Overwriting config files",
|
||||
"id": "overwrite_files",
|
||||
"options": [{
|
||||
"name": "Overwrite the config file minidlna.conf ?",
|
||||
"help": "If the file is overwritten, a backup will be created.",
|
||||
"id": "overwrite_settings",
|
||||
"type": "bool",
|
||||
"default": true
|
||||
}]
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -30,6 +30,24 @@ IS_PACKAGE_CHECK () {
|
|||
return $(env | grep -c container=lxc)
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# BOOLEAN CONVERTER
|
||||
#=================================================
|
||||
|
||||
bool_to_01 () {
|
||||
local var="$1"
|
||||
[ "$var" = "true" ] && var=1
|
||||
[ "$var" = "false" ] && var=0
|
||||
echo "$var"
|
||||
}
|
||||
|
||||
bool_to_true_false () {
|
||||
local var="$1"
|
||||
[ "$var" = "1" ] && var=true
|
||||
[ "$var" = "0" ] && var=false
|
||||
echo "$var"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
@ -517,7 +535,7 @@ EOF
|
|||
ynh_store_file_checksum "$finalfail2banjailconf"
|
||||
ynh_store_file_checksum "$finalfail2banfilterconf"
|
||||
|
||||
systemctl reload fail2ban
|
||||
systemctl restart fail2ban
|
||||
local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
|
||||
if [ -n "$fail2ban_error" ]
|
||||
then
|
||||
|
@ -532,7 +550,7 @@ EOF
|
|||
ynh_remove_fail2ban_config () {
|
||||
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
|
||||
systemctl reload fail2ban
|
||||
systemctl restart fail2ban
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
|
47
scripts/actions/install_backports
Executable file
47
scripts/actions/install_backports
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/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
|
||||
#=================================================
|
||||
|
||||
if [ -e /etc/apt/sources.list.d/minidlna.list ]
|
||||
then
|
||||
ynh_die "You are already using the version from backports repository." 0
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC ACTION
|
||||
#=================================================
|
||||
# RE-INSTALL MINIDLNA FROM BACKPORTS
|
||||
#=================================================
|
||||
|
||||
# Remove the current version of minidlna
|
||||
ynh_package_remove minidlna
|
||||
|
||||
# Then install the version from backports
|
||||
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
||||
test -z "$codename" && (ynh_die "codename empty")
|
||||
|
||||
ynh_replace_string "__CODENAME__" "$codename" /etc/yunohost/apps/$app/conf/minidlna.list
|
||||
cp -a /etc/yunohost/apps/$app/conf/minidlna.list /etc/apt/sources.list.d/
|
||||
ynh_apt update
|
||||
ynh_package_install -t $codename-backports minidlna
|
40
scripts/actions/install_standard
Executable file
40
scripts/actions/install_standard
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# CHECK IF ARGUMENTS ARE CORRECT
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# CHECK IF AN ACTION HAS TO BE DONE
|
||||
#=================================================
|
||||
|
||||
if [ ! -e /etc/apt/sources.list.d/minidlna.list ]
|
||||
then
|
||||
ynh_die "You are already using the version from the stable repository." 0
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC ACTION
|
||||
#=================================================
|
||||
# RE-INSTALL MINIDLNA FROM STABLE
|
||||
#=================================================
|
||||
|
||||
# Remove the current version of minidlna
|
||||
ynh_package_remove minidlna
|
||||
ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list"
|
||||
|
||||
ynh_apt update
|
||||
ynh_package_install minidlna
|
37
scripts/actions/reset_db
Executable file
37
scripts/actions/reset_db
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/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
|
||||
#=================================================
|
||||
# LIST ALL PADS FROM THE DATABASE
|
||||
#=================================================
|
||||
|
||||
# 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_system_reload --service_name=minidlna --action=stop
|
||||
ynh_secure_remove "$db_directory/files.db"
|
||||
ynh_system_reload --service_name=minidlna --action=start
|
133
scripts/config
Normal file
133
scripts/config
Normal file
|
@ -0,0 +1,133 @@
|
|||
#!/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 overwrite_settings)"
|
||||
old_overwrite_settings=$(bool_to_true_false $old_overwrite_settings)
|
||||
overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}"
|
||||
|
||||
#=================================================
|
||||
# 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
|
||||
echo "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_ROOT_CONTAINER=$root_container"
|
||||
echo "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_FRIENDLY_NAME=$friendly_name"
|
||||
|
||||
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# 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 "root_container=.*" "root_container=$root_container" "$config_file"
|
||||
ynh_app_setting_set $app root_container "$root_container"
|
||||
restart_minidlna=1
|
||||
fi
|
||||
|
||||
# friendly_name
|
||||
if [ "$friendly_name" != "$old_friendly_name" ]
|
||||
then
|
||||
ynh_replace_string "friendly_name=.*" "friendly_name=$friendly_name" "$config_file"
|
||||
ynh_app_setting_set $app friendly_name "$friendly_name"
|
||||
restart_minidlna=1
|
||||
fi
|
||||
|
||||
if [ $restart_minidlna -eq 1 ]
|
||||
then
|
||||
ynh_system_reload --service_name=minidlna --action=restart
|
||||
fi
|
||||
|
||||
# Set overwrite_settings
|
||||
overwrite_settings=$(bool_to_01 $overwrite_settings)
|
||||
ynh_app_setting_set $app overwrite_settings "$overwrite_settings"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
|
||||
#=================================================
|
||||
|
||||
case $1 in
|
||||
show) show_config;;
|
||||
apply) apply_config;;
|
||||
esac
|
|
@ -44,6 +44,7 @@ ynh_app_setting_set $app port $port
|
|||
|
||||
# Enregistre les infos dans la config YunoHost
|
||||
ynh_app_setting_set $app version ${version:0:1}
|
||||
ynh_app_setting_set $app overwrite_settings "1"
|
||||
|
||||
#=================================================
|
||||
# CREATE YUNOHOST.MULTIMEDIA DIRECTORY
|
||||
|
@ -62,11 +63,11 @@ if [ ${version:0:1} = "B" ]
|
|||
then # Installation de la version minidlna disponible dans backport. (En cas de problème avec la version actuelle des dépots)
|
||||
ynh_replace_string "__CODENAME__" "$codename" ../conf/minidlna.list
|
||||
cp -a ../conf/minidlna.list /etc/apt/sources.list.d/
|
||||
apt-get update
|
||||
apt-get -t $codename-backports -y install minidlna
|
||||
ynh_apt update
|
||||
ynh_package_install -t $codename-backports minidlna
|
||||
else # Installation de la version minidlna des dépots courants.
|
||||
apt-get update
|
||||
apt-get -y install minidlna
|
||||
ynh_apt update
|
||||
ynh_package_install minidlna
|
||||
fi
|
||||
ynh_app_setting_set $app version ${version:0:1}
|
||||
|
||||
|
@ -95,8 +96,12 @@ yunohost service add minidlna --log "/var/log/minidlna.log"
|
|||
# Modifie la configuration de minidlna
|
||||
ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*friendly_name=.*" "friendly_name=Yunohost DLNA" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*root_container=.*" "root_container=B" /etc/minidlna.conf
|
||||
friendly_name="Yunohost DLNA"
|
||||
ynh_app_setting_set $app friendly_name "$friendly_name"
|
||||
ynh_replace_string "^#*friendly_name=.*" "friendly_name=$friendly_name" /etc/minidlna.conf
|
||||
root_container="B"
|
||||
ynh_replace_string "^#*root_container=.*" "root_container=$root_container" /etc/minidlna.conf
|
||||
ynh_app_setting_set $app root_container "$root_container"
|
||||
ynh_replace_string "^#wide_links=.*" "wide_links=yes" /etc/minidlna.conf
|
||||
ynh_store_file_checksum "/etc/minidlna.conf" # Enregistre la somme de contrôle du fichier de config
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ ynh_exec_fully_quiet yunohost firewall disallow UDP 1900
|
|||
# REMOVE MINIDNLA
|
||||
#=================================================
|
||||
|
||||
apt-get -y purge minidlna
|
||||
ynh_apt purge minidlna
|
||||
ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -49,11 +49,11 @@ then # Installation de la version minidlna disponible dans backport. (En cas de
|
|||
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
||||
ynh_restore_file "/etc/apt/sources.list.d/minidlna.list"
|
||||
ynh_replace_string " [a-z]*-backports" " $codename-backports" /etc/apt/sources.list.d/minidlna.list
|
||||
apt-get update
|
||||
apt-get -t $codename-backports -y install minidlna
|
||||
ynh_apt update
|
||||
ynh_package_install -t $codename-backports minidlna
|
||||
else # Installation de la version minidlna des dépots courants.
|
||||
apt-get update
|
||||
apt-get -y install minidlna
|
||||
ynh_apt update
|
||||
ynh_package_install minidlna
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -17,6 +17,9 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
version=$(ynh_app_setting_get $app version)
|
||||
port=$(ynh_app_setting_get $app port)
|
||||
overwrite_settings=$(ynh_app_setting_get $app overwrite_settings)
|
||||
root_container=$(ynh_app_setting_get $app root_container)
|
||||
friendly_name=$(ynh_app_setting_get $app friendly_name)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
@ -24,6 +27,28 @@ port=$(ynh_app_setting_get $app port)
|
|||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
|
||||
# If overwrite_settings doesn't exist, create it
|
||||
if [ -z "$overwrite_settings" ]; then
|
||||
overwrite_settings=1
|
||||
ynh_app_setting_set $app overwrite_settings $overwrite_settings
|
||||
fi
|
||||
|
||||
# If root_container doesn't exist, create it
|
||||
if [ -z "$root_container" ]; then
|
||||
root_container="B"
|
||||
ynh_app_setting_set $app root_container $root_container
|
||||
fi
|
||||
|
||||
# If friendly_name doesn't exist, create it
|
||||
if [ -z "$friendly_name" ]; then
|
||||
friendly_name="Yunohost DLNA"
|
||||
ynh_app_setting_set $app friendly_name $friendly_name
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
|
@ -52,11 +77,11 @@ then # Installation de la version minidlna disponible dans backport. (En cas de
|
|||
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
||||
ynh_replace_string "__CODENAME__" "$codename" ../conf/minidlna.list
|
||||
cp -a ../conf/minidlna.list /etc/apt/sources.list.d/
|
||||
apt-get update
|
||||
apt-get -t $codename-backports -y install minidlna
|
||||
ynh_apt update
|
||||
ynh_package_install -t $codename-backports minidlna
|
||||
else # Installation de la version minidlna des dépots courants.
|
||||
apt-get update
|
||||
apt-get -y install minidlna
|
||||
ynh_apt update
|
||||
ynh_package_install minidlna
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -81,14 +106,18 @@ yunohost service add minidlna --log "/var/log/minidlna.log"
|
|||
# CONFIGURE MINIDLNA
|
||||
#=================================================
|
||||
|
||||
# Modifie la configuration de minidlna
|
||||
ynh_backup_if_checksum_is_different "/etc/minidlna.conf" # Créé un backup du fichier de config si il a été modifié.
|
||||
ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*friendly_name=.*" "friendly_name=Yunohost DLNA" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*root_container=.*" "root_container=B" /etc/minidlna.conf
|
||||
ynh_replace_string "^#wide_links=.*" "wide_links=yes" /etc/minidlna.conf
|
||||
ynh_store_file_checksum "/etc/minidlna.conf"
|
||||
# Overwrite the settings config file only if it's allowed
|
||||
if [ $overwrite_settings -eq 1 ]
|
||||
then
|
||||
# Modifie la configuration de minidlna
|
||||
ynh_backup_if_checksum_is_different "/etc/minidlna.conf" # Créé un backup du fichier de config si il a été modifié.
|
||||
ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*friendly_name=.*" "friendly_name=$friendly_name" /etc/minidlna.conf
|
||||
ynh_replace_string "^#*root_container=.*" "root_container=$root_container" /etc/minidlna.conf
|
||||
ynh_replace_string "^#wide_links=.*" "wide_links=yes" /etc/minidlna.conf
|
||||
ynh_store_file_checksum "/etc/minidlna.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RESTART MINIDLNA'S SERVICE
|
||||
|
|
Loading…
Add table
Reference in a new issue