Skip to content

Commit

Permalink
Better custom repo installation
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Sep 21, 2023
1 parent 1dbb067 commit 416eac9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
26 changes: 24 additions & 2 deletions modoboa_installer/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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"

Expand All @@ -42,6 +42,28 @@ def prepare_system(self):
def restore_system(self):
utils.exec_cmd("rm -f {}".format(self.policy_file))

def add_custom_repository(self,
name: str,
url: str,
key_url: str,
codename: str,
with_source: bool = True):
key_file = f"/etc/apt/keyrings/{name}.gpg"
utils.exec_cmd(

Check warning on line 52 in modoboa_installer/package.py

View check run for this annotation

Codecov / codecov/patch

modoboa_installer/package.py#L51-L52

Added lines #L51 - L52 were not covered by tests
f"wget -O - {key_url} | gpg --dearmor | sudo tee {key_file} > /dev/null"
)
line_types = ["deb"]
if with_source:
line_types.append("deb-src")
for line_type in line_types:
line = (

Check warning on line 59 in modoboa_installer/package.py

View check run for this annotation

Codecov / codecov/patch

modoboa_installer/package.py#L55-L59

Added lines #L55 - L59 were not covered by tests
f"{line_type} [arch=amd64 signed-by={key_file}] "
f"{url} {codename} main"
)
target_file = f"/etc/apt/source.list.d/{name}.list"
utils.exec_cmd(f'echo "{line} | sude tee {target_file}')
self.index_updated = False

Check warning on line 65 in modoboa_installer/package.py

View check run for this annotation

Codecov / codecov/patch

modoboa_installer/package.py#L63-L65

Added lines #L63 - L65 were not covered by tests

def update(self):
"""Update local cache."""
if self.index_updated:
Expand Down Expand Up @@ -82,7 +104,7 @@ class RPMPackage(Package):

def __init__(self, dist_name):
"""Initialize backend."""
super(RPMPackage, self).__init__(dist_name)
super().__init__(dist_name)

Check warning on line 107 in modoboa_installer/package.py

View check run for this annotation

Codecov / codecov/patch

modoboa_installer/package.py#L107

Added line #L107 was not covered by tests
if "centos" in dist_name:
self.install("epel-release")

Expand Down
14 changes: 9 additions & 5 deletions modoboa_installer/scripts/rspamd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ def install_packages(self):
if debian_based_dist:
utils.mkdir_safe(
"/etc/apt/keyrings",
stat.S_IRWXU | stat.S_IRUSR | stat.S_IXUSR,
stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP |
stat.S_IROTH | stat.S_IXOTH,
0, 0
)

if codename.lower() == "bionic":
if codename == "bionic":
package.backend.install("software-properties-common")
utils.exec_cmd("add-apt-repository ppa:ubuntu-toolchain-r/test")

utils.exec_cmd("wget -O- https://rspamd.com/apt-stable/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/rspamd.gpg > /dev/null")
utils.exec_cmd(f"echo \"deb [arch=amd64 signed-by=/etc/apt/keyrings/rspamd.gpg] http://rspamd.com/apt-stable/ {codename} main\" | sudo tee /etc/apt/sources.list.d/rspamd.list")
utils.exec_cmd(f"echo \"deb-src [arch=amd64 signed-by=/etc/apt/keyrings/rspamd.gpg] http://rspamd.com/apt-stable/ {codename} main\" | sudo tee -a /etc/apt/sources.list.d/rspamd.list")
package.backend.add_custom_repository(
"rspamd",
"http://rspamd.com/apt-stable/",
"https://rspamd.com/apt-stable/gpg.key",
codename
)
package.backend.update()

return super().install_packages()
Expand Down

0 comments on commit 416eac9

Please sign in to comment.