From a54fe4a2e4656580895b9ce5e7650e67b4f8e545 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 20 May 2016 00:01:51 +0200 Subject: [PATCH] trap et maj ynh 2.4 --- manifest.json | 3 +++ manifest2.2.json | 30 ++++++++++++++++++++++++++ scripts/backup | 7 +++++- scripts/install | 41 ++++++++++++++++++++++++++++++++--- scripts/remove | 56 +++++++++++++++++++++++++++++++++++++----------- scripts/restore | 7 +++++- scripts/upgrade | 7 +++++- 7 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 manifest2.2.json diff --git a/manifest.json b/manifest.json index 7fc46cd..b25075f 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "MiniDLNA", "id": "minidlna", "packaging_format": 1, + "requirements": { + "yunohost": ">= 2.4" + }, "description": { "en": "Light DLNA server to share media files over the LAN", "fr": "Serveur DLNA léger pour partager les fichiers multimédia sur le réseau local" diff --git a/manifest2.2.json b/manifest2.2.json new file mode 100644 index 0000000..7fc46cd --- /dev/null +++ b/manifest2.2.json @@ -0,0 +1,30 @@ +{ + "name": "MiniDLNA", + "id": "minidlna", + "packaging_format": 1, + "description": { + "en": "Light DLNA server to share media files over the LAN", + "fr": "Serveur DLNA léger pour partager les fichiers multimédia sur le réseau local" + }, + "url": "http://minidlna.sourceforge.net/", + "licence": "free", + "maintainer": { + "name": "Maniack Crudelis", + "email": "maniackc_dev@crudelis.fr" + }, + "multi_instance": "false", + "services": [], + "arguments": { + "install" : [ + { + "name": "version", + "ask": { + "en": "Select the minidlna version to install", + "fr": "Choix de la version de minidlna à installer" + }, + "choices": ["A. Version of the Debian repositories (recommended)", "B. Latest version available for Debian"], + "default": "A. Version of the Debian repositories (recommended)" + } + ] + } +} diff --git a/scripts/backup b/scripts/backup index ae7249d..032a117 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=minidlna +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=minidlna +fi version=$(sudo yunohost app setting $app version) port=$(sudo yunohost app setting $app port) diff --git a/scripts/install b/scripts/install index bab3622..42e9fe4 100644 --- a/scripts/install +++ b/scripts/install @@ -1,8 +1,43 @@ #!/bin/bash -# Renseigne les variables à partir des arguments. -version=$1 -app=minidlna +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +# Retrieve arguments +if [ $ynh_version = "2.4" ] +then + version=$YNH_APP_ARG_VERSION + + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + version=$1 + app=minidlna +fi + + +# Delete files and db if exit with an error +EXIT_PROPERLY () { + trap '' ERR + echo -e "\e[91m \e[1m" # Shell in light red bold + echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!" + + if [ $ynh_version = "2.2" ]; then + /bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique. + fi + exit 1 +} +TRAP_ON () { # Activate signal capture + trap EXIT_PROPERLY ERR # Capturing exit signals on error +} +TRAP_OFF () { # Ignoring signal capture until TRAP_ON +# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien. +# Mais pas la fonction TRAP_OFF... +# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction. + trap '' ERR # Ignoring exit signals +} +TRAP_ON + # Cherche un port libre. port=48200 diff --git a/scripts/remove b/scripts/remove index 7c8116f..a06eeb9 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,31 +1,61 @@ #!/bin/bash # Récupère les infos de l'application. -app=minidlna -version=$(sudo yunohost app setting $app version) +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME + + # Source app helpers + . /usr/share/yunohost/helpers +else + app=minidlna +fi port=$(sudo yunohost app setting $app port) # Ferme les ports dans le firewall -sudo yunohost firewall disallow TCP $port > /dev/null 2>&1 -sudo yunohost firewall disallow UDP 1900 > /dev/null 2>&1 # Découverte SSDP pour UPNP. +if sudo yunohost firewall list | grep -q "\- $port$" +then + echo "Close port $port" + sudo yunohost firewall disallow TCP $port > /dev/null +fi +if sudo yunohost firewall list | grep -q "\- 1900$" +then + echo "Close port 1900" + sudo yunohost firewall disallow UDP 1900 > /dev/null +fi # Suppression du paquet minidlna -sudo apt-get -y purge minidlna -if [ $version = "B" ] -then - sudo rm /etc/apt/sources.list.d/minidlna.list +if [ -e "/usr/sbin/minidlnad" ] || [ -e "/usr/bin/minidlnad" ]; then + echo "Remove minidlna package" + sudo apt-get -y purge minidlna +fi +if [ -e "/etc/apt/sources.list.d/minidlna.list" ]; then + echo "Delete apt config" + sudo rm "/etc/apt/sources.list.d/minidlna.list" fi # Suppression du paramètre inotify pour minidlna. -sudo rm /etc/sysctl.d/90-inotify_minidlna.conf -# Et rechargement de la config du noyau. -sudo sysctl --system +if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then + echo "Delete kernel config" + sudo rm "/etc/sysctl.d/90-inotify_minidlna.conf" + # Et rechargement de la config du noyau. + sudo sysctl --system +fi # Retire le service du monitoring de Yunohost. -sudo yunohost service remove minidlna +if sudo yunohost service status | grep -q minidlna # Test l'existence du service dans Yunohost +then + echo "Remove minidlna service" + sudo yunohost service remove minidlna +fi # Suppression des log -sudo rm -r /var/log/minidlna.log +if [ -e "/var/log/minidlna.log" ]; then + echo "Delete log" + sudo rm "/var/log/minidlna.log" +fi # Régénère la configuration de SSOwat sudo yunohost app ssowatconf + +echo -e "\e[0m" # Restore normal color diff --git a/scripts/restore b/scripts/restore index afc99fa..d2f23dc 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=minidlna +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=minidlna +fi version=$(sudo yunohost app setting $app version) port=$(sudo yunohost app setting $app port) diff --git a/scripts/upgrade b/scripts/upgrade index aa2386b..69a295f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,12 @@ #!/bin/bash # Récupère les infos de l'application. -app=minidlna +ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2) +if [ $ynh_version = "2.4" ]; then + app=$YNH_APP_INSTANCE_NAME +else + app=minidlna +fi version=$(sudo yunohost app setting $app version) port=$(sudo yunohost app setting $app port)