Better custom repo installation

This commit is contained in:
Antoine Nguyen
2023-09-21 10:24:43 +02:00
parent b4b5fa288f
commit 9f5542f07e
2 changed files with 33 additions and 7 deletions

View File

@@ -49,7 +49,29 @@ class DEBPackage(Package):
def restore_system(self): def restore_system(self):
utils.exec_cmd("rm -f {}".format(self.policy_file)) utils.exec_cmd("rm -f {}".format(self.policy_file))
def update(self, force=False): 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(
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 = (
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
def update(self):
"""Update local cache.""" """Update local cache."""
if self.index_updated and not force: if self.index_updated and not force:
return return
@@ -89,7 +111,7 @@ class RPMPackage(Package):
def __init__(self, dist_name): def __init__(self, dist_name):
"""Initialize backend.""" """Initialize backend."""
super(RPMPackage, self).__init__(dist_name) super().__init__(dist_name)
if "centos" in dist_name: if "centos" in dist_name:
self.install("epel-release") self.install("epel-release")

View File

@@ -41,17 +41,21 @@ class Rspamd(base.Installer):
if debian_based_dist: if debian_based_dist:
utils.mkdir_safe( utils.mkdir_safe(
"/etc/apt/keyrings", "/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 0, 0
) )
if codename.lower() == "bionic": if codename == "bionic":
package.backend.install("software-properties-common") package.backend.install("software-properties-common")
utils.exec_cmd("add-apt-repository ppa:ubuntu-toolchain-r/test") 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") package.backend.add_custom_repository(
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") "rspamd",
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") "http://rspamd.com/apt-stable/",
"https://rspamd.com/apt-stable/gpg.key",
codename
)
package.backend.update() package.backend.update()
return super().install_packages() return super().install_packages()