#!/bin/bash
if [ $(CreoleGet ad_recycle_bin non) = 'oui' ];then
    ad_recycle_bin_purge=$(CreoleGet ad_recycle_bin_purge)
    if [[ "$(CreoleGet ad_homes_share_recycle)" = "oui" ]]
    then
        # corbeille des répertoires personnels
        dirname=$(basename $(CreoleGet ad_recycle_bin_dir))
        safe_dirname=$(echo "$dirname" |sed -e 's/\./\\./g')
        home_path=$(CreoleGet ad_home_share_path)
        #suppression de tous de type de fichier non répertoire puis suppression des répertoires vides #4727
        find /$home_path ! -type d -ctime +$ad_recycle_bin_purge -path "*/$safe_dirname/*" -delete &>/dev/null
        find /$home_path -type d -empty -ctime +$ad_recycle_bin_purge -path "*/$safe_dirname/*" -delete &>/dev/null
    fi

    # corbeilles des répertoires partagés
    if [[ "$(CreoleGet ad_additional_share non)" = "oui" ]]
    then
        additional_shares_path=( $(CreoleGet ad_additional_share_path) )
        additional_shares_recycle=( $(CreoleGet ad_additional_share_recycle) )
        for i in "${!additional_shares_path[@]}"
        do
            if [[ "${additional_shares_recycle[i]}" = "oui" ]]
            then
                dirname=$(basename $(CreoleGet ad_recycle_bin_dir))
                safe_dirname=$(echo "$dirname" |sed -e 's/\./\\./g')
                share_path="${additional_shares_path[i]}"
                #suppression de tous de type de fichier non répertoire puis suppression des répertoires vides #4727
                find "${additional_shares_path[i]}" ! -type d -ctime +$ad_recycle_bin_purge -path "*/$safe_dirname/*" -delete &>/dev/null
                find "${additional_shares_path[i]}" -type d -empty -ctime +$ad_recycle_bin_purge -path "*/$safe_dirname/*" -delete &>/dev/null
            fi
        done
    fi

fi
