Extraire les droits attribués dans une arborescence

Le script permet d’afficher (ou de stocker dans un fichier) les droits attribués pour chaque dossier d’une arborescence (groupes uniquement).

#!/bin/sh
# extraitDroitDossier.sh
# @author : Eric Quinton
# @date : 2011-04-28
# modification : 6/4/12
#script permettant d'extraire la liste des droits attribues a un dossier et aux sous-dossiers
# fournit une liste avec une entree par dossier, chaque groupe etant separe par un espace
# Recuperation des parametres d'entree
PROFONDEUR=1
while getopts "p:c:d:-:h" OPT
do
       # Gestion des options longues
       if test $OPT = '-'  ; then
               LONGOPT="${OPTARG%%=*}"
               OPTARG="${OPTARG#*=}"
               case $LONGOPT in 
                       chemin) OPT="c";;
                       destination) OPT="d";;
                        profondeur) OPT="p";;
                       help) OPT="h";;
                       *) echo "option longue non permise -- $LONGOPT" >&2 ;exit
65 ;;
               esac
       fi
      case $OPT in 
               
               c) CHEMIN=$OPTARG;;
               d) DEST=$OPTARG;;
                p) PROFONDEUR=$OPTARG;;
               h) echo "Utilisation : extraitDroitsDossier.sh [arguments]"
               echo "[--chemin=chemin|-c chemin] : chemin de base a interroger"
                echo "[--profondeur=nombre|-p nombre] : nombre de sous-dossiers a traiter"
               echo "[--destination=destination|-d destination] : destination du resultat (pour l'ecran : ne pas renseigner)"
               exit 0
               ;;
               *) echo "option inconnue. creaationDossier.sh -h pour plus d'informations"
               exit 65
               ;;
       esac
done
# Verification que le chemin est renseigne
if test -z $CHEMIN ; then
        echo "Le dossier a interroger n'est pas renseigne"
        exit 65
fi
# Verification de l'existence d'un fichier de destination
if test ! -z $DEST ;then
        if test -f $DEST 
        then
                echo -n "Le fichier $DEST existe. L'ecraser (o,n)"
                read REPONSE
                if (test "$REPONSE" = "o")
                then
                        rm $DEST
                else
                        exit 1
                fi
        fi
fi
# Lancement de l'extraction
find $CHEMIN -maxdepth $PROFONDEUR -type d|while read DOSSIER
do
                RESULT=`getfacl "$DOSSIER" 2>/dev/null|grep -v ^.*---|grep -v ^#\ owner|grep -v ^default| grep -v ^#\ group|grep -v ^user|grep -v ^mask|grep -v ^group:: |sed s/^..file..//`
                if test "$RESULT"
                then
                        if test "$DEST" 
                        then
                                echo /$RESULT >> $DEST
                        else
                                echo /$RESULT
                        fi
                fi
done