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

Option wide_links et nouveaux helpers

This commit is contained in:
Maniack Crudelis 2017-05-01 20:42:27 +02:00
parent fca547486f
commit dd00adb212
6 changed files with 305 additions and 190 deletions

View file

@ -1,14 +1,229 @@
#!/bin/bash #!/bin/bash
#=================================================
#=================================================
# TESTING
#=================================================
#=================================================
# Remove a file or a directory securely
#
# usage: ynh_secure_remove path_to_remove
# | arg: path_to_remove - File or directory to remove
ynh_secure_remove () {
path_to_remove=$1
forbidden_path=" \
/var/www \
/home/yunohost.app"
if [[ "$forbidden_path" =~ "$path_to_remove" \
# Match all path or subpath in $forbidden_path
|| "$path_to_remove" =~ ^/[[:alnum:]]+$ \
# Match all first level path from / (Like /var, /root, etc...)
|| "${path_to_remove:${#path_to_remove}-1}" = "/" ]]
# Match if the path finish by /. Because it's seems there is an empty variable
then
echo "Avoid deleting of $path_to_remove." >&2
else
if [ -e "$path_to_remove" ]
then
sudo rm -R "$path_to_remove"
else
echo "$path_to_remove doesn't deleted because it's not exist." >&2
fi
fi
}
ynh_setup_source () {
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d= -f2-)
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2-)
arch_format=$(cat ../conf/app.src | grep ARCH_FORMAT | cut -d= -f2-)
local_source="/opt/yunohost-apps-src/$YNH_APP_ID/source.$arch_format"
if test -e "$local_source"
then # Use the local source file if it is present
cp $local_source source.$arch_format
else # If not, download the source
wget -nv -O source.$arch_format $src_url
fi
# Check the control sum
echo "$src_checksum source.$arch_format" \
| md5sum -c --status || ynh_die "Corrupt source"
# Extract source into the app dir
sudo mkdir -p "$final_path"
if [ $(echo "$arch_format" | tr '[:upper:]' '[:lower:]') = "zip" ]
then # Zip format
# Using of a temp directory, because unzip doesn't manage --strip-components
temp_dir=$(mktemp -d)
unzip -quo source.zip -d "$temp_dir"
sudo cp -a $temp_dir/*/. "$final_path"
ynh_secure_remove "$temp_dir"
elif [ $(echo "$arch_format" | tr '[:upper:]' '[:lower:]') = "tar.gz" ]; then
sudo tar -x -f source.tar.gz -C "$final_path" --strip-components 1
else
ynh_die "Format d'archive non reconnu."
fi
# Apply patches
if test -f ../sources/patches/*.patch; then
(cd "$DEST" \
&& for p in ${PKG_DIR}/patches/*.patch; do \
sudo patch -p1 < $p; done) \
|| ynh_die "Unable to apply patches"
fi
# Add supplementary files
if test -e "../sources/extra_files"; then
sudo cp -a ../sources/extra_files/. "$final_path"
fi
}
ynh_backup_abstract () {
# A intégrer à ynh_backup directement.
ynh_backup "$@"
echo "$2" "$1" >> backup_list
}
ynh_restore_file () {
file_and_dest=$(grep "^$1" backup_list)
backup_file=${file_and_dest%% *}
backup_dest=${file_and_dest#* }
if [ -f "$backup_dest" ]; then
ynh_die "There is already a file at this path: $backup_dest"
fi
if test -d "$backup_file"; then
sudo cp -a "$backup_file/." "$backup_dest"
else
sudo cp -a "$backup_file" "$backup_dest"
fi
}
ynh_fpm_config () {
finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
ynh_compare_checksum_config "$finalphpconf" 1
sudo cp ../conf/php-fpm.conf "$finalphpconf"
ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
ynh_replace_string "__USER__" "$app" "$finalphpconf"
sudo chown root: "$finalphpconf"
ynh_store_checksum_config "$finalphpconf"
if [ -e "../conf/php-fpm.ini" ]
then
finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
ynh_compare_checksum_config "$finalphpini" 1
sudo cp ../conf/php-fpm.ini "$finalphpini"
sudo chown root: "$finalphpini"
ynh_store_checksum_config "$finalphpini"
fi
sudo systemctl reload php5-fpm
}
ynh_remove_fpm_config () {
ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini"
sudo systemctl reload php5-fpm
}
ynh_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_compare_checksum_config "$finalnginxconf" 1
sudo cp ../conf/nginx.conf "$finalnginxconf"
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if test -n "${path_url:-}"; then
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
fi
if test -n "${domain:-}"; then
ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf"
fi
if test -n "${port:-}"; then
ynh_replace_string "__PORT__" "$port" "$finalnginxconf"
fi
if test -n "${app:-}"; then
ynh_replace_string "__NAME__" "$app" "$finalnginxconf"
fi
if test -n "${final_path:-}"; then
ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
fi
ynh_store_checksum_config "$finalnginxconf"
sudo systemctl reload nginx
}
ynh_remove_nginx_config () {
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx
}
ynh_store_checksum_config () {
config_file_checksum=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_set $app $config_file_checksum $(sudo md5sum "$1" | cut -d' ' -f1)
}
ynh_compare_checksum_config () {
current_config_file=$1
compress_backup=${2:-0} # If $2 is empty, compress_backup will set at 0
config_file_checksum=checksum_${current_config_file//[\/ ]/_} # Replace all '/' and ' ' by '_'
checksum_value=$(ynh_app_setting_get $app $config_file_checksum)
if [ -n "$checksum_value" ]
then # Proceed only if a value was stocked into the app config
if ! echo "$checksum_value $current_config_file" | sudo md5sum -c --status
then # If the checksum is now different
backup_config_file="$current_config_file.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')"
if [ $compress_backup -eq 1 ]
then
sudo tar --create --gzip --file "$backup_config_file.tar.gz" "$current_config_file" # Backup the current config file and compress
backup_config_file="$backup_config_file.tar.gz"
else
sudo cp -a "$current_config_file" "$backup_config_file" # Backup the current config file
fi
echo "Config file $current_config_file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_config_file" >&2
echo "$backup_config_file" # Return the name of the backup file
fi
fi
}
ynh_systemd_config () {
finalsystemdconf="/etc/systemd/system/$app.service"
ynh_compare_checksum_config "$finalsystemdconf" 1
sudo cp ../conf/systemd.service "$finalsystemdconf"
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if test -n "${final_path:-}"; then
ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf"
fi
if test -n "${app:-}"; then
ynh_replace_string "__APP__" "$app" "$finalsystemdconf"
fi
ynh_store_checksum_config "$finalsystemdconf"
sudo chown root: "$finalsystemdconf"
sudo systemctl enable $app
sudo systemctl daemon-reload
}
ynh_remove_systemd_config () {
finalsystemdconf="/etc/systemd/system/$app.service"
if [ -e "$finalsystemdconf" ]; then
sudo systemctl stop $app
sudo systemctl disable $app
ynh_secure_remove "$finalsystemdconf"
fi
}
#=================================================
#=================================================
#================================================= #=================================================
# CHECKING # CHECKING
#================================================= #=================================================
CHECK_USER () { # Vérifie la validité de l'user admin
# $1 = Variable de l'user admin.
ynh_user_exists "$1" || ynh_die "Wrong user"
}
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine. CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path_url -a $app sudo yunohost app checkurl $domain$path_url -a $app
} }
@ -44,117 +259,6 @@ ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null
$@ > /dev/null 2>&1 $@ > /dev/null 2>&1
} }
#=================================================
# SETUP
#=================================================
SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d'>' -f2)
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2)
# Download sources from the upstream
wget -nv -O source.tar.gz $src_url
# Vérifie la somme de contrôle de la source téléchargée.
echo "$src_checksum source.tar.gz" | md5sum -c --status || ynh_die "Corrupt source"
# Extract source into the app dir
sudo mkdir -p $final_path
sudo tar -x -f source.tar.gz -C $final_path --strip-components 1
# Copie les fichiers additionnels ou modifiés.
if test -e "../sources/ajouts"; then
sudo cp -a ../sources/ajouts/. "$final_path"
fi
}
SETUP_SOURCE_ZIP () { # Télécharge la source, décompresse et copie dans $final_path
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d'>' -f2)
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2)
# Download sources from the upstream
wget -nv -O source.zip $src_url
# Vérifie la somme de contrôle de la source téléchargée.
echo "$src_checksum source.zip" | md5sum -c --status || ynh_die "Corrupt source"
# Extract source into the app dir
sudo mkdir -p $final_path
temp_dir=$(mktemp -d)
unzip -quo source.zip -d $temp_dir # On passe par un dossier temporaire car unzip ne permet pas d'ignorer le dossier parent.
sudo cp -a $temp_dir/*/. $final_path
rm -r $temp_dir
# Copie les fichiers additionnels ou modifiés.
if test -e "../sources/ajouts"; then
sudo cp -a ../sources/ajouts/. "$final_path"
fi
}
POOL_FPM () { # Créer le fichier de configuration du pool php-fpm et le configure.
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo chown root: $finalphpconf
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
sudo cp ../conf/php-fpm.ini $finalphpini
sudo chown root: $finalphpini
sudo systemctl reload php5-fpm
}
YNH_CURL () {
data_post=$1
url_access=$2
sleep 1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 --data "$data_post" "https://localhost$path_url$url_access" 2>&1
}
#=================================================
# REMOVE
#=================================================
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
echo "Delete nginx config"
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx
fi
}
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config
echo "Delete fpm config"
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
fi
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config
echo "Delete php config"
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini"
fi
sudo systemctl reload php5-fpm
}
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
no_var=0
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
do
no_var=1
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée.
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière.
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable.
if test -z "$real_var" || [ "$real_var" = "/" ]; then
WARNING echo "Variable $only_var is empty, suppression of $chaine cancelled."
return 1
fi
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine.
done
if [ "$no_var" -eq 1 ]
then
if [ -e "$chaine" ]; then
echo "Delete directory $chaine"
sudo rm -r "$chaine"
fi
return 0
else
WARNING echo "No detected variable."
return 1
fi
}
#================================================= #=================================================
# BACKUP # BACKUP
#================================================= #=================================================
@ -206,24 +310,6 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
fi fi
} }
#=================================================
# CONFIGURATION
#=================================================
STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
# $2 = Nom complet et chemin du fichier de conf.
ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1)
}
CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié.
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
# $2 = Nom complet et chemin du fichier de conf.
if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then
sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup.
fi
}
#================================================= #=================================================
# PACKAGE CHECK BYPASSING... # PACKAGE CHECK BYPASSING...
#================================================= #=================================================
@ -240,19 +326,6 @@ IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé)
# Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant # Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant
#================================================= #=================================================
# Ignore the yunohost-cli log to prevent errors with conditionals commands
# usage: ynh_no_log COMMAND
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command
# It's a very badly hack...
ynh_no_log() {
ynh_cli_log=/var/log/yunohost/yunohost-cli.log
sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move
eval $@
exit_code=$?
sudo mv ${ynh_cli_log}-move ${ynh_cli_log}
return $?
}
# Normalize the url path syntax # Normalize the url path syntax
# Handle the slash at the beginning of path and its absence at ending # Handle the slash at the beginning of path and its absence at ending
# Return a normalized url path # Return a normalized url path
@ -261,6 +334,7 @@ ynh_no_log() {
# ynh_normalize_url_path example -> /example # ynh_normalize_url_path example -> /example
# ynh_normalize_url_path /example -> /example # ynh_normalize_url_path /example -> /example
# ynh_normalize_url_path /example/ -> /example # ynh_normalize_url_path /example/ -> /example
# ynh_normalize_url_path / -> /
# #
# usage: ynh_normalize_url_path path_to_normalize # usage: ynh_normalize_url_path path_to_normalize
# | arg: url_path_to_normalize - URL path to normalize before using it # | arg: url_path_to_normalize - URL path to normalize before using it
@ -333,7 +407,7 @@ ynh_make_valid_dbid () {
# } # }
# This function is optionnal. # This function is optionnal.
# #
# Usage: ynh_exit_properly is used only by the helper ynh_check_error. # Usage: ynh_exit_properly is used only by the helper ynh_abort_if_errors.
# You must not use it directly. # You must not use it directly.
ynh_exit_properly () { ynh_exit_properly () {
exit_code=$? exit_code=$?
@ -364,7 +438,8 @@ ynh_abort_if_errors () {
trap ynh_exit_properly EXIT # Capturing exit signals on shell script trap ynh_exit_properly EXIT # Capturing exit signals on shell script
} }
# Install dependencies with a equivs control file # Define and install dependencies with a equivs control file
# This helper can/should only be called once per app
# #
# usage: ynh_install_app_dependencies dep [dep [...]] # usage: ynh_install_app_dependencies dep [dep [...]]
# | arg: dep - the package name to install in dependence # | arg: dep - the package name to install in dependence
@ -506,3 +581,46 @@ ynh_system_user_delete () {
echo "The user $1 was not found" >&2 echo "The user $1 was not found" >&2
fi fi
} }
# Curl abstraction to help with POST requests to local pages (such as installation forms)
#
# $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))
#
# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"
#
# usage: ynh_local_curl "page_uri" "key1=value1" "key2=value2" ...
# | arg: page_uri - Path (relative to $path_url) of the page where POST data will be sent
# | arg: key1=value1 - (Optionnal) POST key and corresponding value
# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value
# | arg: ... - (Optionnal) More POST keys and values
ynh_local_curl () {
# Define url of page to curl
full_page_url=https://localhost$path_url$1
# Concatenate all other arguments with '&' to prepare POST data
POST_data=""
for arg in "${@:2}"
do
POST_data="${POST_data}${arg}&"
done
# (Remove the last character, which is an unecessary '&')
POST_data=${POST_data::-1}
# Curl the URL
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 --data "$POST_data" "$full_page_url" 2>&1
}
# Substitute/replace a string by another in a file
#
# usage: ynh_replace_string match_string replace_string target_file
# | arg: match_string - String to be searched and replaced in the file
# | arg: replace_string - String that will replace matches
# | arg: target_file - File in which the string will be replaced.
ynh_replace_string () {
delimit=@
match_string=${1//${delimit}/"\\${delimit}"} # Escape the delimiter if it's in the string.
replace_string=${2//${delimit}/"\\${delimit}"}
workfile=$3
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
}

View file

@ -38,17 +38,17 @@ version=$(ynh_app_setting_get $app version)
# Copie des fichiers spécifiques à l'application # Copie des fichiers spécifiques à l'application
if [ $version = "B" ] if [ $version = "B" ]
then then
ynh_backup /etc/apt/sources.list.d/minidlna.list minidlna.list ynh_backup_abstract /etc/apt/sources.list.d/minidlna.list minidlna.list
fi fi
#================================================= #=================================================
# BACKUP OF THE INOTIFY'S CONFIG # BACKUP OF THE INOTIFY'S CONFIG
#================================================= #=================================================
ynh_backup /etc/sysctl.d/90-inotify_minidlna.conf inotify ynh_backup_abstract /etc/sysctl.d/90-inotify_minidlna.conf inotify
#================================================= #=================================================
# BACKUP OF THE CONFIG OF MINIDLNA # BACKUP OF THE CONFIG OF MINIDLNA
#================================================= #=================================================
ynh_backup /etc/minidlna.conf minidlna.conf ynh_backup_abstract /etc/minidlna.conf minidlna.conf

View file

@ -62,7 +62,7 @@ sudo ./yunohost.multimedia-master/script/ynh_media_build.sh
# Installation du paquet minidlna et ses dépendances # Installation du paquet minidlna et ses dépendances
if [ ${version:0:1} = "B" ] 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) then # Installation de la version minidlna disponible dans backport. (En cas de problème avec la version actuelle des dépots)
sudo sed -i "s@__CODENAME__@$codename@g" ../conf/minidlna.list ynh_replace_string "__CODENAME__" "$codename" ../conf/minidlna.list
sudo cp -a ../conf/minidlna.list /etc/apt/sources.list.d/ sudo cp -a ../conf/minidlna.list /etc/apt/sources.list.d/
sudo apt-get update sudo apt-get update
sudo apt-get -t $codename-backports -y install minidlna sudo apt-get -t $codename-backports -y install minidlna
@ -95,11 +95,12 @@ sudo yunohost service add minidlna --log "/var/log/minidlna.log"
#================================================= #=================================================
# Modifie la configuration de minidlna # Modifie la configuration de minidlna
sudo sed -i 's@^#*media_dir=.*@media_dir=/home/yunohost.multimedia/share@' /etc/minidlna.conf ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf
sudo sed -i "s/^#*port=.*/port=$port/" /etc/minidlna.conf ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf
sudo sed -i "s/^#*friendly_name=.*/friendly_name=Yunohost DLNA/" /etc/minidlna.conf ynh_replace_string "^#*friendly_name=.*" "friendly_name=Yunohost DLNA" /etc/minidlna.conf
sudo sed -i "s/^#*root_container=.*/root_container=B/" /etc/minidlna.conf ynh_replace_string "^#*root_container=.*" "root_container=B" /etc/minidlna.conf
STORE_MD5_CONFIG "minidlna.conf" "/etc/minidlna.conf" # Enregistre la somme de contrôle du fichier de config ynh_replace_string "^#wide_links=" "wide_links=yes" /etc/minidlna.conf
ynh_store_checksum_config "/etc/minidlna.conf" # Enregistre la somme de contrôle du fichier de config
#================================================= #=================================================
# RESTART MINIDLNA'S SERVICE # RESTART MINIDLNA'S SERVICE

View file

@ -35,16 +35,10 @@ fi
#================================================= #=================================================
# Ferme les ports dans le firewall # Ferme les ports dans le firewall
if sudo yunohost firewall list | grep -q "\- $port$" WARNING sudo yunohost firewall list --raw
then ALL_QUIET sudo yunohost firewall disallow TCP $port
echo "Close port $port" ALL_QUIET sudo yunohost firewall disallow UDP 1900
QUIET sudo yunohost firewall disallow TCP $port WARNING sudo yunohost firewall list --raw
fi
if sudo yunohost firewall list | grep -q "\- 1900$"
then
echo "Close port 1900"
QUIET sudo yunohost firewall disallow UDP 1900
fi
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
@ -57,10 +51,7 @@ if [ -e "/usr/sbin/minidlnad" ] || [ -e "/usr/bin/minidlnad" ]; then
echo "Remove minidlna package" echo "Remove minidlna package"
sudo apt-get -y purge minidlna sudo apt-get -y purge minidlna
fi fi
if [ -e "/etc/apt/sources.list.d/minidlna.list" ]; then ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list"
echo "Delete sources.list config"
sudo rm "/etc/apt/sources.list.d/minidlna.list"
fi
#================================================= #=================================================
# REMOVE INOTIFY'S CONFIG # REMOVE INOTIFY'S CONFIG
@ -69,7 +60,7 @@ fi
# Suppression du paramètre inotify pour minidlna. # Suppression du paramètre inotify pour minidlna.
if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then
echo "Delete kernel config" echo "Delete kernel config"
sudo rm "/etc/sysctl.d/90-inotify_minidlna.conf" ynh_secure_remove "/etc/sysctl.d/90-inotify_minidlna.conf"
# Et rechargement de la config du noyau. # Et rechargement de la config du noyau.
if IS_PACKAGE_CHECK; then if IS_PACKAGE_CHECK; then
sudo sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf sudo sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf

View file

@ -36,8 +36,10 @@ port=$(ynh_app_setting_get $app port)
# OPEN PORTS # OPEN PORTS
#================================================= #=================================================
sudo yunohost firewall allow --no-upnp TCP $port > /dev/null 2>&1 WARNING sudo yunohost firewall list --raw
sudo yunohost firewall allow --no-upnp UDP 1900 > /dev/null 2>&1 # Découverte SSDP pour UPNP. ALL_QUIET sudo yunohost firewall allow --no-upnp TCP $port
ALL_QUIET sudo yunohost firewall allow --no-upnp UDP 1900 # Découverte SSDP pour UPNP.
WARNING sudo yunohost firewall list --raw
#================================================= #=================================================
# CREATE YUNOHOST.MULTIMEDIA DIRECTORY # CREATE YUNOHOST.MULTIMEDIA DIRECTORY
@ -54,8 +56,8 @@ sudo ./yunohost.multimedia-master/script/ynh_media_build.sh
if [ ${version:0:1} = "B" ] 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) then # Installation de la version minidlna disponible dans backport. (En cas de problème avec la version actuelle des dépots)
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2) codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
sudo cp -a ./minidlna.list /etc/apt/sources.list.d/ ynh_restore_file minidlna.list
sudo sed -i "s@ [a-z]*-backports@ $codename-backports@g" /etc/apt/sources.list.d/minidlna.list ynh_replace_string " [a-z]*-backports" " $codename-backports" /etc/apt/sources.list.d/minidlna.list
sudo apt-get update sudo apt-get update
sudo apt-get -t $codename-backports -y install minidlna sudo apt-get -t $codename-backports -y install minidlna
else # Installation de la version minidlna des dépots courants. else # Installation de la version minidlna des dépots courants.
@ -67,12 +69,13 @@ fi
# RESTORE INOTIFY'S CONFIG # RESTORE INOTIFY'S CONFIG
#================================================= #=================================================
sudo cp -a ./inotify /etc/sysctl.d/90-inotify_minidlna.conf ynh_restore_file inotify
if IS_PACKAGE_CHECK; then if IS_PACKAGE_CHECK; then
sudo sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf sudo sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf
fi fi
sudo cp -a ./minidlna.conf /etc/ ynh_secure_remove "/etc/minidlna.conf" # Supprime la config pour la remplacer par celle du backup
ynh_restore_file minidlna.conf
sudo systemctl restart minidlna sudo systemctl restart minidlna
#================================================= #=================================================

View file

@ -43,7 +43,7 @@ sudo ./yunohost.multimedia-master/script/ynh_media_build.sh
if [ $version = "B" ] if [ $version = "B" ]
then # Installation de la version minidlna disponible dans backport. (En cas de problème avec la version actuelle des dépots) then # Installation de la version minidlna disponible dans backport. (En cas de problème avec la version actuelle des dépots)
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2) codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
sudo sed -i "s@__CODENAME__@$codename@g" ../conf/minidlna.list ynh_replace_string "__CODENAME__" "$codename" ../conf/minidlna.list
sudo cp -a ../conf/minidlna.list /etc/apt/sources.list.d/ sudo cp -a ../conf/minidlna.list /etc/apt/sources.list.d/
sudo apt-get update sudo apt-get update
sudo apt-get -t $codename-backports -y install minidlna sudo apt-get -t $codename-backports -y install minidlna
@ -75,11 +75,13 @@ sudo yunohost service add minidlna --log "/var/log/minidlna.log"
#================================================= #=================================================
# Modifie la configuration de minidlna # Modifie la configuration de minidlna
CHECK_MD5_CONFIG "minidlna.conf" "/etc/minidlna.conf" # Créé un backup du fichier de config si il a été modifié. ynh_compare_checksum_config "/etc/minidlna.conf" # Créé un backup du fichier de config si il a été modifié.
sudo sed -i 's@^#*media_dir=.*@media_dir=/home/yunohost.multimedia/share@' /etc/minidlna.conf ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf
sudo sed -i "s/^#*port=.*/port=$port/" /etc/minidlna.conf ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf
sudo sed -i "s/^#*friendly_name=.*/friendly_name=Yunohost DLNA/" /etc/minidlna.conf ynh_replace_string "^#*friendly_name=.*" "friendly_name=Yunohost DLNA" /etc/minidlna.conf
sudo sed -i "s/^#*root_container=.*/root_container=B/" /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_checksum_config "/etc/minidlna.conf"
#================================================= #=================================================
# RESTART MINIDLNA'S SERVICE # RESTART MINIDLNA'S SERVICE