#!/bin/bash # # # mptldap - migrates policy mailquota to ldap # 2009 Tim Petersen #################################################################### # Usage function, helpfile # #################################################################### usage() { echo "" echo "migrate [OPTION] USER" echo "-u specifies User, if not specified, all user policy quota will be migrated" echo "-l only lists possible quota set in policy" echo "-h shows this helpfile" echo "" echo "closing with exit 0" echo "" } migrate="true" specuser="nouseratall" #################################################################### # Parse options # #################################################################### while getopts ":hu:l" opt do case $opt in \?) echo "Enter mptldap -h for helpfile" exit 1 ;; u) specuser="$OPTARG" echo "Specified user to be migrated: "$specuser"" ;; h) usage exit 0 ;; l) migrate="false" ;; :) echo "Enter mptldap -h for helpfile" exit 1 esac done # Shifting back OPTIND to receive Argument above getopts shift $(($OPTIND - 1)) #################################################################### # migrates user quotas # #################################################################### migrate() { eval $(ucr shell) if [ "$specuser" != "nouseratall" ] then allusers=$specuser else allusers=$(ldapsearch -LLLxu objectClass=univentionMail uid= | grep uid | sed s/"dn: "// | sed s/","/"\n"/ | grep uid | sed s/"uid="//) fi if [ "$specuser" != "nouseratall" ] then policyusers=$(univention_policy_result uid=$specuser,cn=users,$ldap_base | grep -B 1 univentionMailQuotaMB | head -1 | sed s/"Policy: cn="// | cut -d "," -f1) else policyusers=$(ldapsearch -LLLxu objectClass=univentionMail | grep univentionPolicyReference | grep cn | sed s/"univentionPolicyReference: "// | cut -d "," -f1 | sed s/"cn="//) fi for i in $allusers do userpolicy=$(univention_policy_result uid=$i,cn=users,$ldap_base | grep -A 1 univentionMailQuotaMB | tail -1 | sed s/"Value: "//) if [ $(echo $userpolicy | grep -E "^[0-9]+$") ] then univention-directory-manager users/user modify --dn="uid=$i,cn=users,$ldap_base" --set mailMailQuota=$userpolicy fi done for i in $policyusers do univention-directory-manager policies/mailquota modify --dn="cn=$i,cn=mail,cn=policies,$ldap_base" --set MailQuota= done } #################################################################### # only lists possible quota changes # #################################################################### onlylist() { eval $(ucr shell) allusers=$(ldapsearch -LLLxu objectClass=univentionMail uid= | grep uid | sed s/"dn: "// | sed s/","/"\n"/ | grep uid | sed s/"uid="//) for i in $allusers do userpolicy=$(univention_policy_result uid=$i,cn=users,$ldap_base | grep -A 1 univentionMailQuotaMB | tail -1 | sed s/"Value: "//) if [ $(echo $userpolicy | grep -E "^[0-9]+$") ] then echo "#################" echo "# QUOTA FOUND # user $i has set the following quota as policy attribute: $userpolicy MB" echo "#################" else echo "################# user $i has no quota set as policy attribute" fi done } #################################################################### # starting migration # #################################################################### if [ $migrate == "false" ] then onlylist else migrate fi