Upating mailboxes quota fixing script to work with arguments
This commit is contained in:
parent
fbb834c75e
commit
a65afb62c3
|
@ -4,29 +4,67 @@
|
||||||
#You can call this script either without arguments, inwich case each maildir quotas will be recalculated
|
#You can call this script either without arguments, inwich case each maildir quotas will be recalculated
|
||||||
#or you can call it with a directory reffering to a maildir to just sync one mailbox
|
#or you can call it with a directory reffering to a maildir to just sync one mailbox
|
||||||
|
|
||||||
#basic checks
|
#gerer les options : tout , 1boite , un domaine, un compte
|
||||||
if [ $# -gt 1 ]; then
|
while getopts "a:m:d:c:" optname
|
||||||
echo "usage : update_quota_mail.sh (Maildir)."
|
do
|
||||||
exit
|
case "$optname" in
|
||||||
fi
|
"a")
|
||||||
|
maildirs=`find "$ALTERNC_MAIL/" -maxdepth 2 -mindepth 2 -type d`
|
||||||
if [ $# -eq 1 ];then
|
;;
|
||||||
if [ ! -d "$1" ];then
|
"m")
|
||||||
echo "$1 is not a directory, aborting."
|
if [[ "$OPTARG" =~ ^[^\@]*@[^\@]*$ ]] ; then
|
||||||
|
if [[ "$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")" ]]; then
|
||||||
|
maildirs=$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")
|
||||||
|
else
|
||||||
|
echo "Bad mail provided"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Bad mail provided"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"d")
|
||||||
|
if [[ "$OPTARG" =~ ^[a-z\-]+(\.[a-z\-]+)+$ ]] ; then
|
||||||
|
if [[ "$(mysql_query "select domaine from domaines where domaine = '$OPTARG'")" ]]; then
|
||||||
|
maildirs=$(mysql_query "select userdb_home from dovecot_view where user like '%@$OPTARG'")
|
||||||
|
else
|
||||||
|
echo "Bad domain provided"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Bad domain provided 2"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"c")
|
||||||
|
if [[ "$OPTARG" =~ ^[a-z]*$ ]] ; then
|
||||||
|
if [[ "$(mysql_query "select domaine from domaines where domaine = '$1'")" ]]; then
|
||||||
|
maildirs=$(mysql_query "select userdb_home from dovecot_view where userdb_uid = $OPTARG")
|
||||||
|
else
|
||||||
|
echo "Bad account provided"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Bad account provided"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"?")
|
||||||
|
echo "Unknown option $OPTARG - stop processing"
|
||||||
exit
|
exit
|
||||||
else
|
;;
|
||||||
d="$1"
|
":")
|
||||||
fi
|
echo "No argument value for option $OPTARG - stop processing"
|
||||||
else
|
exit
|
||||||
#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=`find "$ALTERNC_MAIL/" -maxdepth 2 -mindepth 2 -type d`
|
# Should not occur
|
||||||
fi
|
echo "Unknown error while processing options"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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 $d ; do
|
for i in $maildirs ; do
|
||||||
|
|
||||||
if [ -d "$i" ];then
|
if [ -d "$i" ];then
|
||||||
user=`ls -l $i| tail -n 1|cut -d' ' -f 3`
|
user=`ls -l $i| tail -n 1|cut -d' ' -f 3`
|
||||||
|
|
Loading…
Reference in New Issue