view 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 source

import io

from pyinfra.context import host
from pyinfra.facts.server import Arch
from pyinfra.operations import apt, files, server

TZ = 'America/Los_Angeles'


def ubuntuReleases():
    if 'pi' not in host.groups:
        files.line(path='/etc/update-manager/release-upgrades', line="^Prompt=", replace="Prompt=normal")

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
    #-rw-r--r-- 1 root root 1733 Mar 26  2021 /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg

    # raspi needs wget http://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -


def arch386():
    if host.get_fact(Arch) != 'x86_64':
        return
    server.shell(commands=['dpkg --add-architecture i386'])


def aptUpdate():
    apt.packages(update=True,
                 cache_time=86400,
                 packages=['tzdata'],
                 force=True,
                 _env={
                     'TZ': TZ,
                     'LANG': 'en_US.UTF-8',
                     'DEBIAN_FRONTEND': 'noninteractive'
                 })

    # squib 1st setup seemed to need more updates for node(nodesource)
    # and steam-launcher


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')


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')


operations = [
    ubuntuReleases,
    arch386,
    pkgKeys,
    sources,
    aptUpdate,
    flatpakSources,
]