Skip to content

Instantly share code, notes, and snippets.

@bahamut45
Last active August 29, 2015 14:09
Show Gist options
  • Save bahamut45/5949b2d5703561e6a629 to your computer and use it in GitHub Desktop.
Save bahamut45/5949b2d5703561e6a629 to your computer and use it in GitHub Desktop.
Repose droit pour owncloud
#!/bin/bash
###### Variables #######
owncloud_dir=/var/www/owncloud
sabnzb_dir=/var/Downloads
user_data=/var/www/owncloud/data
tmp_dir=/tmp/repose-droit
now=$(date +"%d_%m_%Y_%H_%M_%S")
lock=${tmp_dir}/repose-droit-${now}.lock
if [ -d $tmp_dir ];
then
rm -rf $tmp_dir/*
else
mkdir $tmp_dir
fi
# On recupère la liste des dossiers qui ne sont pas au spécification
for user in `ls -l ${user_data} | grep "^d" | grep -v "updater_backup" | awk '{print $9}'`;
do
find ${user_data}/${user}/files -type f ! -perm 644 >> ${tmp_dir}/perm-${user}-files.txt
find ${user_data}/${user}/files -type d ! -perm 755 >> ${tmp_dir}/perm-${user}-directory.txt
find ${user_data}/${user}/files ! -user www-data >> ${tmp_dir}/user-${user}.txt
done
# On recupere les dossiers et fichiers de sabnzbd
find ${sabnzb_dir}/ -type f ! -perm 644 >> ${tmp_dir}/perm-sabnzbd-files.txt
find ${sabnzb_dir}/ -type d ! -perm 755 >> ${tmp_dir}/perm-sabnzbd-directory.txt
find ${sabnzb_dir}/ ! -user www-data >> ${tmp_dir}/user-sabnzbd.txt
# Nettoyage des résultats vide
find ${tmp_dir} -size 0 -print0 | xargs -0 rm
# Parcours des fichiers présents dans /tmp/repose-droit
for file in `ls ${tmp_dir}`;
do
touch ${lock}
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
if [[ ${file} == *directory* ]]
then
for d in `cat ${tmp_dir}/${file}`;
do
chmod 755 "$d"
done
elif [[ ${file} == *files* ]]
then
for f in `cat ${tmp_dir}/${file}`;
do
chmod 644 "$f"
done
elif [[ ${file} == *user* ]]
then
for u in `cat ${tmp_dir}/${file}`;
do
chown www-data:www-data "$u"
done
fi
# restore $IFS
IFS=$SAVEIFS
done
if [ -f $lock ];
then
# on se deplace dans le dossier owncloud pour forcer le scan
cd ${owncloud_dir}
php console.php files:scan --all >> /var/log/repose-droit/last-scan-owncloud-${now}.txt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment