Skip to content

Commit

Permalink
Install dovecot from backports if Debian 12
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Oct 16, 2024
1 parent 69b966a commit 33cad9b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions modoboa_installer/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import utils


class Package(object):
class Package:
"""Base classe."""

def __init__(self, dist_name):
Expand All @@ -29,10 +29,16 @@ class DEBPackage(Package):
FORMAT = "deb"

def __init__(self, dist_name):
super(DEBPackage, self).__init__(dist_name)
super().__init__(dist_name)
self.index_updated = False
self.policy_file = "/usr/sbin/policy-rc.d"

def enable_backports(self, codename):
code, output = utils.exec_cmd(f"grep {codename}-backports /etc/apt/sources.list")
if code:
with open(f"/etc/apt/sources.list.d/backports.list", "w") as fp:
fp.write(f"deb http://deb.debian.org/debian {codename}-backports main\n")

def prepare_system(self):
"""Make sure services don't start at installation."""
with open(self.policy_file, "w") as fp:
Expand Down
11 changes: 10 additions & 1 deletion modoboa_installer/scripts/dovecot.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ def get_packages(self):
if package.backend.FORMAT == "deb":
if "pop3" in self.config.get("dovecot", "extra_protocols"):
packages += ["dovecot-pop3d"]
return super().get_packages() + packages
packages += super().get_packages()
backports_codename = getattr(self, "backports_codename", None)
if backports_codename:
packages = [f"{package}/{backports_codename}-backports" for package in packages]
return packages

def install_packages(self):
"""Preconfigure Dovecot if needed."""
name, version = utils.dist_info()
name = name.lower()
if name.startswith("debian") and version.startswith("12"):
package.backend.enable_backports("bookworm")
self.backports_codename = "bookworm"
package.backend.preconfigure(
"dovecot-core", "create-ssl-cert", "boolean", "false")
super().install_packages()
Expand Down
4 changes: 2 additions & 2 deletions modoboa_installer/scripts/postfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_packages(self):
packages = ["postfix-{}".format(self.db_driver)]
else:
packages = []
return super(Postfix, self).get_packages() + packages
return super().get_packages() + packages

def install_packages(self):
"""Preconfigure postfix package installation."""
Expand All @@ -46,7 +46,7 @@ def install_packages(self):

package.backend.preconfigure(
"postfix", "main_mailer_type", "select", "No configuration")
super(Postfix, self).install_packages()
super().install_packages()

def get_template_context(self):
"""Additional variables."""
Expand Down

0 comments on commit 33cad9b

Please sign in to comment.