view packages.py @ 300:e9950e0185b0

more hosts
author drewp@bigasterisk.com
date Wed, 07 Aug 2024 00:58:20 -0700
parents 5f3e053ba888
children c72f268ee846
line wrap: on
line source

from io import StringIO

from pyinfra import host
from pyinfra.operations import apt, files, server, systemd

import package_lists


def kitty():
    vers = '0.31.0'  # see https://github.com/kovidgoyal/kitty/releases
    home = '/home/drewp'
    local = f"{home}/.local/kitty"
    dl = f'/tmp/kitty-{vers}-x86_64.txz'
    files.download(src=f"https://github.com/kovidgoyal/kitty/releases/download/v{vers}/kitty-{vers}-x86_64.txz", dest=dl)
    files.directory(path=local)
    server.shell(commands=[
        f"mkdir -p {local}",  # https://github.com/Fizzadar/pyinfra/issues/777
        f"aunpack --extract-to={local} {dl}",
    ])
    files.link(target="{local}/bin/kitty", path="{home}/bin/kitty")


def nodejs():
    apt.packages(packages=['libnode72'], present=False, force=True)
    apt.packages(packages=['nodejs'], latest=True)
    server.shell(commands=[
        "rm -f /usr/local/bin/pnp{m,x}",
        "corepack enable",
        # https://github.com/pnpm/pnpm/releases
        # but also https://pnpm.io/installation#compatibility
        "corepack prepare 'pnpm@8.6.3' --activate",
    ])


def podman():
    # frigate build wants to mount a single file from the host, which needs podman 4.5.1
    # https://github.com/containers/podman/issues/12123#issuecomment-1620439593
    server.shell(commands='apt --fix-broken install')
    apt.deb(src="http://ftp.osuosl.org/pub/ubuntu/pool/main/g/gpgme1.0/libgpgme11t64_1.18.0-4.1ubuntu4_amd64.deb")
    server.shell(commands='apt --fix-broken install')
    apt.deb(src="http://ftp.osuosl.org/pub/ubuntu/pool/universe/c/conmon/conmon_2.1.10+ds1-1build2_amd64.deb")
    apt.deb(src="http://ftp.osuosl.org/pub/ubuntu/pool/universe/libp/libpod/podman_4.9.3+ds1-1build2_amd64.deb")
    apt.packages(packages=['libsubid4', 'buildah', 'podman-docker'], latest=True)


def pdm():
    # https://github.com/pdm-project/pdm/blob/main/CHANGELOG.md
    server.shell(commands=["pip install --break-system-packages 'pdm==2.12.4'"])


def proper_locate():
    apt.packages(packages='mlocate', present=False)
    if 'pi' not in host.groups and host.name not in ['prime', 'pipe']:
        apt.packages(packages='plocate')


def proper_man():
    if 'small' in host.groups or 'pi' in host.groups:
        apt.packages(packages=['mandb'], present=False)


def no_unwanted_services():
    systemd.service(service='nginx', enabled=False, running=False)


apt.packages(packages=package_lists.setup, latest=True)


def roblox():
    server.shell(commands='flatpak install -y org.freedesktop.Platform/x86_64/23.08')
    server.shell(commands='flatpak install -y flathub org.vinegarhq.Vinegar')  # (roblox runner)
    files.put(
        src=StringIO(
            #"#!/bin/sh\nexec flatpak run org.vinegarhq.Vinegar player run 'roblox-player:1'\n"
            "#!/bin/sh\n exec /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=vinegar org.vinegarhq.Vinegar player run -app\n"
        ),
        dest='/usr/local/bin/roblox.real',
        mode='755')

    for desktopFile in [
            '/var/lib/flatpak/exports/share/applications/org.vinegarhq.Vinegar.app.desktop',
            '/var/lib/flatpak/app/org.vinegarhq.Vinegar/current/active/export/share/applications/org.vinegarhq.Vinegar.player.desktop',
    ]:
        files.line(path=desktopFile, line="^Exec", replace='Exec=/usr/local/bin/roblox')
    files.link(target='/usr/local/bin/run_while_allowed', path='/usr/local/bin/roblox', force=True)


def kube_node():

    # avoid having to this workaround:
    # https://longhorn.io/kb/troubleshooting-volume-with-multipath/
    apt.packages(packages=['multipath-tools'], force=True, present=False)

    apt.packages(packages=[
        # https://longhorn.io/docs/1.6.1/deploy/install/#installation-requirements
        'open-iscsi',
        'nfs-common',
        'cryptsetup',
    ])


proper_locate()
proper_man()

apt.packages(packages=package_lists.general, latest=True)
apt.packages(packages=package_lists.debug, latest=True)

if host.name == "pipe":
    apt.packages(packages=package_lists.for_pipe, latest=True)

if host.name != 'pipe':
    apt.packages(packages=['reptyr'])

if host.name == "prime":
    apt.packages(packages=package_lists.for_prime, latest=True)

if host.name == 'plus':
    apt.packages(packages=package_lists.laptop, latest=True)

if host.data.get('gpu'):
    apt.packages(packages=package_lists.k8s_node_with_nvidia_gpu(host.name))

if host.data.get('k8s_admin'):
    podman()

is_kube_node = host.name in ['dash', 'slash', 'ditto', 'ws-printer', 'li-drums']
if is_kube_node:
    kube_node()
    
if host.name == 'ditto':
    apt.packages(packages=package_lists.for_ditto, latest=True)

if 'pi' not in host.groups:
    kitty()
    apt.packages(packages=package_lists.non_pi, latest=True)

if 'pi' in host.groups:
    apt.packages(packages=package_lists.pi_setup)

desktop_env = host.name in ['dash', 'slash', 'plus', 'dot', 'squib', 'pillow', 'tofu']
if desktop_env:
    apt.packages(packages=package_lists.xorg + package_lists.desktop, latest=True)
    # broken, per https://vinegarhq.org/
    # roblox()
if desktop_env or host.name in ['bang', 'ditto']:
    pdm()

no_unwanted_services()

# todo: ./mrv2-v1.0.8-Linux-amd64.deb