#!/bin/bash

WATCH_DIRS=("mp3" "flac" "Classique" "Clips" "Concerts" "Chansons Francaises") # Répertoire à surveiller
#SCRIPT="/opt/domoticz/scripts/Musique.sh"  # Script à exécuter

mount -t cifs //musique.home/sdcard/Musique /mnt/Musique -o username=souti,password=setaou,rw,uid=$(id -u),gid=$(id -g)


for dir in "${WATCH_DIRS[@]}"; do
    inotifywait -m -e create,modify,delete,move "/media/WDBlue/Musique/$dir" |
    while read -r directory events filename; do
        echo "Changement détecté dans $directory : $events sur $filename"
        #bash "$SCRIPT" "$directory" "$filename" "$events"
		lockfile-create "/tmp/synchro.lockfile"
		rsync -aprvhu  --size-only "$directory/" "/mnt/Musique/$dir/" > "/tmp/synch_directory"
		lockfile-remove "/tmp/synchro.lockfile"
    done &
done

