msimerson / Mail-Toaster-6

Mail Toaster 6
https://github.com/msimerson/Mail-Toaster-6/wiki
BSD 3-Clause "New" or "Revised" License
46 stars 16 forks source link

Provisioning Dovecot fails to convert from Vpopmail backend to SQL backend #482

Closed greenshrike closed 3 years ago

greenshrike commented 3 years ago

The provision script checks the Dovecot config to see if it is still using the vpopmail driver and, if so, converts the Dovecot config over to the SQL backend instead.

This is checked with the code:

configure_dovecot_sql_conf()
{
        local _localconf="$ZFS_DATA_MNT/dovecot/etc/local.conf"
        if ! grep -q -E 'driver\s*=\s*vpopmail' $_localconf; then
                tell_status "passdb conversion to SQL already complete"
                return
        fi

However, the grep doesn't work on FreeBSD 12.2 or FreeBSD 11 with the system grep command, resulting in the vpopmail->SQL conversion never getting done.

cgreen:Vmail1:/home/cgreen# uname -r
12.2-STABLE
cgreen:Vmail1:/home/cgreen# which grep
/usr/bin/grep
cgreen:Vmail1:/home/cgreen# echo "driver = vpopmail" > /tmp/grep-test
cgreen:Vmail1:/home/cgreen# grep -q "driver = vpopmail" /tmp/grep-test && echo found || echo not found
found
cgreen:Vmail1:/home/cgreen# grep -q "driver.*=.*vpopmail" /tmp/grep-test && echo found || echo not found
found
cgreen:Vmail1:/home/cgreen# grep -q -E 'driver\s*=\s*vpopmail' /tmp/grep-test && echo found || echo not found
not found
cgreen:Vmail1:/home/cgreen# rm /tmp/grep-test
cgreen:Smtp1:/etc/mail# uname -r
11.4-STABLE
cgreen:Smtp1:/etc/mail# which grep
/usr/bin/grep
cgreen:Smtp1:/etc/mail# echo "driver = vpopmail" > /tmp/grep-test
cgreen:Smtp1:/etc/mail# grep -q "driver = vpopmail" /tmp/grep-test && echo found || echo not found
found
cgreen:Smtp1:/etc/mail# grep -q "driver.*=.*vpopmail" /tmp/grep-test && echo found || echo not found
found
cgreen:Smtp1:/etc/mail# grep -q -E 'driver\s*=\s*vpopmail' /tmp/grep-test && echo found || echo not found
not found
cgreen:Smtp1:/etc/mail# rm /tmp/grep-test

Using \s for whitespace doesn't seem to be supported by FreeBSD's system grep in at least some versions of FreeBSD.

Changing the regex to:

configure_dovecot_sql_conf()
{
        local _localconf="$ZFS_DATA_MNT/dovecot/etc/local.conf"
        if ! grep -q -E 'driver = vpopmail' $_localconf; then
                tell_status "passdb conversion to SQL already complete"
                return
        fi

got the script to actually do the conversion. However, driver.*vpopmail or driver.*=.*vpopmail is probably less fragile.

msimerson commented 3 years ago

Please review the linked PR.

greenshrike commented 3 years ago

Regex works for me on 11.4 and 12.2.

\s new in grep for FreeBSD 13 or something? I don't have one of those boxes handy to test.

Cheers.

msimerson commented 3 years ago

I think \s was me forgetting that grep -E is only extended regex, not pcre, which I'm much more familiar with.