Updating dovecot quota's synching scripts

This commit is contained in:
Steven Mondji-Lerider 2013-01-23 19:26:42 +00:00
parent 235aea23ea
commit 479c715e72
1 changed files with 38 additions and 21 deletions

View File

@ -1,31 +1,48 @@
#! /bin/bash #!/bin/bash
. /usr/lib/alternc/functions.sh . /usr/lib/alternc/functions.sh
#Fist we set the quotas no 0 (infinite for each already existing account #You can call this script either without arguments, inwich case each maildir quotas will be recalculated
t=`mysql_query "UPDATE mailbox SET quota='0' WHERE quota IS NULL"` #or you can call it with a directory reffering to a maildir to just sync one mailbox
#basic checks
if [ $# -gt 1 ]; then
echo "usage : update_quota_mail.sh (Maildir)."
exit
fi
if [ $# -eq 1 ];then
if [ ! -d "$1" ];then
echo "$1 is not a directory, aborting."
exit
else
d="$1"
fi
else
#Fist we set the quotas no 0 (infinite for each already existing account
t=`mysql_query "UPDATE mailbox SET quota='0' WHERE quota IS NULL"`
d="$ALTERNC_LOC/mail/*/*"
fi
#Then we loop through every maildir to get the maildir size #Then we loop through every maildir to get the maildir size
for i in $ALTERNC_LOC/mail/*/* ; do for i in $d ; do
user=`ls -l $i| tail -n 1|cut -d' ' -f 3` if [ -d "$i" ];then
size=`du -s $i|awk '{print $1}'` user=`ls -l $i| tail -n 1|cut -d' ' -f 3`
q=`mysql_query "SELECT * FROM mailbox where path = '$i' "` size=`du -s $i|awk '{print $1}'`
#when counting mails we eclude dovecot specific files #when counting mails we exclude specific files
mail_count=`find $i -type f |grep -v dovecot* |wc -l` mail_count=`find $i -type f -printf "%f\n"| egrep '^[0-9]+\.M'|wc -w`
echo "folder : "$i echo "folder : "$i
echo "mail count : "$mail_count echo "mail count : "$mail_count
echo "dir size : "$size echo "dir size : "$size
echo "" echo ""
if [ -z "$q" ]; then
echo "no mail folder found for user $user "
else
#update the mailbox table accordingly #update the mailbox table accordingly
q=`mysql_query "UPDATE mailbox SET bytes=$size WHERE path='$i' "` mysql_query "UPDATE mailbox SET bytes=$size WHERE path='$i' "
q=`mysql_query "UPDATE mailbox SET messages=$mail_count WHERE path='$i' "` mysql_query "UPDATE mailbox SET messages=$mail_count WHERE path='$i' "
fi else
echo "The maildir $i does not exists. It's quota won't be resync"
fi
done done