Mercurial > code > home > repos > infra
diff apt/apt.py @ 326:5b88b38f2471
huge reorg, reog toplevel functions in preparation of a ui with nice task lists
author | drewp@bigasterisk.com |
---|---|
date | Mon, 20 Jan 2025 21:55:08 -0800 |
parents | 11d3bcedb9f0 |
children |
line wrap: on
line diff
--- a/apt/apt.py Mon Jan 20 14:10:19 2025 -0800 +++ b/apt/apt.py Mon Jan 20 21:55:08 2025 -0800 @@ -1,32 +1,19 @@ -import shlex +import io -from pyinfra import host +from pyinfra.context import host from pyinfra.facts.server import Arch from pyinfra.operations import apt, files, server TZ = 'America/Los_Angeles' -def pkg_keys(): - files.directory(path='/etc/apt/keyrings/') # for raspi - for url, name in [ - ('https://repo.steampowered.com/steam/archive/stable/steam.gpg', 'steam.gpg'), - ]: - files.download(src=url, dest=f'/usr/share/keyrings/{name}') +def ubuntuReleases(): + if 'pi' not in host.groups: + files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal") - apt.packages(packages=['curl', 'gpg']) - server.shell(commands=[ - f"curl -fsSL {shlex.quote(url)} | gpg --dearmor > /etc/apt/keyrings/{name}" for (url, name) in [ - ('https://packages.microsoft.com/keys/microsoft.asc', 'ms.gpg'), - ('https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key', 'nodesource.gpg'), - ('https://dl.google.com/linux/linux_signing_key.pub', 'chrome.gpg'), - ('https://ftp-master.debian.org/keys/archive-key-11.asc', 'bullseye.gpg'), - ('https://ftp-master.debian.org/keys/archive-key-11-security.asc', 'bullseye-security.gpg'), - ('https://packages.cloud.google.com/apt/doc/apt-key.gpg', 'coral.gpg'), - ('https://hub.unity3d.com/linux/keys/public', 'unityhub.gpg'), - ('https://nvidia.github.io/libnvidia-container/gpgkey', 'nvidia.gpg'), - ] - ]) +def pkgKeys(): + files.directory(path='/etc/apt/keyrings/') # for raspi + files.sync(src='apt/keyrings/', dest='/usr/share/keyrings/', delete=False) # also these #-rw-r--r-- 1 root root 2794 Mar 26 2021 /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg @@ -36,15 +23,12 @@ def arch386(): + if host.get_fact(Arch) != 'x86_64': + return server.shell(commands=['dpkg --add-architecture i386']) -def old_deleteme_apt_sources(): - files.template(src='apt/templates/sources.list.j2', dest='/etc/apt/sources.list') - apt_update() - - -def apt_update(): +def aptUpdate(): apt.packages(update=True, cache_time=86400, packages=['tzdata'], @@ -59,22 +43,28 @@ # and steam-launcher -def flatpak_sources(): +def flatpakSources(): apt.packages(update=True, cache_time=86400, packages=['flatpak']) server.shell(commands='flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo') -if host.get_fact(Arch) == 'x86_64': - arch386() +def sources(): + files.put(src=io.StringIO("# see .d\n"), dest="/etc/apt/sources.list") + if 'pi' in host.groups: + osName = "pi" + elif host.name == 'pipe': + osName = "odroid" + else: + osName = "ubuntu" + files.template(src=f'apt/templates/{osName}.sources.j2', dest=f'/etc/apt/sources.list.d/{osName}.sources') + files.template(src='apt/templates/more.sources.j2', dest='/etc/apt/sources.list.d/more.sources') -pkg_keys() -using_new_sources = ['tofu'] -if host.name in using_new_sources: - # todo: rm /etc/apt/sources.list.d/*.list - files.template(src='apt/templates/ubuntu.sources.j2', dest='/etc/apt/sources.list.d/ubuntu.sources') - files.template(src='apt/templates/more.sources.j2', dest='/etc/apt/sources.list.d/more.sources') - apt_update() -else: - old_deleteme_apt_sources() -flatpak_sources() +operations = [ + ubuntuReleases, + arch386, + pkgKeys, + sources, + aptUpdate, + flatpakSources, +]