#!/bin/sh
# @author : Eric Quinton
# @date : 2011-04-28
#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
while getopts "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";;
help) OPT="h";;
*) echo "option longue non permise -- $LONGOPT" >&2 ;exit
65 ;;
esac
fi
case $OPT in
c) CHEMIN=$OPTARG;;
d) DEST=$OPTARG;;
h) echo "Utilisation : extraitDroitsDossier.sh [arguments]"
echo "[--chemin=chemin|-c chemin] : chemin de base a interroger"
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
for DOSSIER in `find $CHEMIN -type d`
do
RESULT=`getfacl $DOSSIER 2>/dev/null|grep -v ^.*---|grep -v ^#\ owner|grep -v ^default| grep -v ^#\ group|grep -v ^user|grep -v ^mask |sed s/^..file..//`
if test -z $DEST
then
echo "/"$RESULT
else
echo "/"$RESULT >> $DEST
fi
done