1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#!/bin/sh
set -e
echo "Setting up postgres resources"
runuser -u postgres -- createuser dovecot
runuser -u postgres -- createdb -O dovecot dovecot
cat <<EOF | runuser -u dovecot -- psql dovecot
CREATE TABLE users (
userid VARCHAR(128) NOT NULL,
domain VARCHAR(128) NOT NULL,
password VARCHAR(64) NOT NULL,
home VARCHAR(255) NOT NULL,
uid INTEGER NOT NULL,
gid INTEGER NOT NULL
);
insert into users values(
'dep8',
'example.com',
'test',
'/srv/dovecot-dep8',
65534,
65534
);
EOF
echo "Setting up dovecot for the test"
# Move aside 10-auth.conf to disable passwd-based auth
if [ -f /etc/dovecot/conf.d/10-auth.conf ]; then
mv /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.bak
fi
cat >/etc/dovecot/local.conf <<-EOF
mail_driver = maildir
mail_path = ~/Maildir
mail_inbox_path = ~/Maildir
auth_mechanisms = plain
sql_driver = pgsql
pgsql /var/run/postgresql {
parameters {
dbname = dovecot
}
}
passdb sql {
query = SELECT userid AS username, domain, password \
FROM users \
WHERE userid = '%{user | username}' AND domain = '%{user | domain}'
}
userdb sql {
query = SELECT home, uid, gid \
FROM users \
WHERE userid = '%{user | username}' AND domain = '%{user | domain}'
# For using doveadm -A:
iterate_query = SELECT userid AS username, domain FROM users
}
EOF
mkdir -p /srv/dovecot-dep8
chown nobody:nogroup /srv/dovecot-dep8
echo "Restarting the service"
systemctl restart dovecot
echo "Sending a test message via the LDA"
/usr/lib/dovecot/dovecot-lda -f "test@example.com" -d dep8@example.com <<EOF
Return-Path: <test@example.com>
Message-Id: <dep8-test-1@debian.org>
From: Test User <test@example.com>
To: dep8 <dep8@example.com>
Subject: DEP-8 test
This is just a test
EOF
echo "Verifying that the email was correctly delivered"
if [ -z "$(doveadm search -u dep8@example.com header message-id dep8-test-1@debian.org)" ]; then
echo "Message not found"
exit 1
fi
echo "Done"
echo
|