Commit ae07ebb0 authored by Claudemir Todo Bom's avatar Claudemir Todo Bom

* execução de teste do script de correção de caminhos

parent 2fe144fa
Pipeline #259 passed with stage
in 1 minute and 46 seconds
......@@ -4,41 +4,57 @@ cat /etc/default/wwmail | sed -e 's/: /=/g' > /tmp/wwmail.$$.tmp
source /tmp/wwmail.$$.tmp
rm /tmp/wwmail.$$.tmp
DRYRUN=1
while [ "$1" ] ; do
if [ $1 == "-u" ] ; then
unset DRYRUN
fi
shift
done
echo "select address,maildir from users" | mysql -N -u ${WW_ISP_USER} -p${WW_ISP_PASS} ${WW_ISP_DB} | while read USER MAILDIR ; do
DOMAIN="$(echo ${USER} | sed -e 's/^.*@//')"
LOCALPART="$(echo ${USER} | sed -e 's/@.*$//')"
DOMAINDIR="/var/spool/maildir/${DOMAIN}"
[ ${DRYRUN} ] && echo VERIFIED
if [ -e "${DOMAINDIR}" ] && ! [ -d "${DOMAINDIR}" ] ; then
echo "${DOMAINDIR} / ${USER} existe e não é um diretório - abort" 1>&2
exit 1
fi
if ! [ -e "${DOMAINDIR}" ] ; then
mkdir -p "${DOMAINDIR}"
chown mail.mail "${DOMAINDIR}"
[ ${DRYRUN} ] || mkdir -p "${DOMAINDIR}"
[ ${DRYRUN} ] || chown mail.mail "${DOMAINDIR}"
fi
ORIG="$(dirname ${MAILDIR})/$(basename ${MAILDIR})"
DEST="/var/spool/maildir/${DOMAIN}/${LOCALPART}"
if [ "${ORIG}" == "${DEST}" ] ; then
continue
fi
if ! [ -e "${MAILDIR}" ] ; then
echo "nao existe: ${MAILDIR}" 1>&2
echo "origem nao existe: ${MAILDIR} (${USER})" 1>&2
if ! [ -e "${DEST}" ] ; then
echo "alterado" 1>&2
echo "UPDATE users SET maildir='${DEST}/' where address='${USER}';"
[ ${DRYRUN} ] || echo "UPDATE users SET maildir='${DEST}/' where address='${USER}';"
echo UPDATED
continue
fi
fi
if [ "${ORIG}" == "${DEST}" ] ; then
continue
fi
if [ -e "${ORIG}" ] ; then
if [ -e "${DEST}" ] ; then
#echo "origem: ${ORIG} -> ${DEST} destino já existe: ${DEST}" 1>&2
mv "${DEST}" /var/spool/maildir/backup/
echo "origem e destinos já existem: ${ORIG} -> ${DEST}" 1>&2
[ ${DRYRUN} ] || mv "${DEST}" /var/spool/maildir/backup/
[ ${DRYRUN} ] && echo BACKEDUP
fi
mv "${ORIG}" "${DEST}"
echo "UPDATE users SET maildir='${DEST}/' where address='${USER}';"
[ ${DRYRUN} ] || mv "${ORIG}" "${DEST}"
[ ${DRYRUN} ] || echo "UPDATE users SET maildir='${DEST}/' where address='${USER}';"
[ ${DRYRUN} ] && echo MOVED
fi
done | mysql -f -N -u ${WW_ISP_USER} -p${WW_ISP_PASS} ${WW_ISP_DB}
done | {
[ ${DRYRUN} ] || mysql -f -N -u ${WW_ISP_USER} -p${WW_ISP_PASS} ${WW_ISP_DB}
[ ${DRYRUN} ] && echo "Execução de teste" && sort | uniq -c && echo -e "\n\n Repita com o parâmetro -u para executar as modificações"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment