view packages.py @ 186:db4b3a07a3dc

run pigpiod
author drewp@bigasterisk.com
date Fri, 07 Apr 2023 17:23:20 -0700
parents b6b11048d0fb
children 466108f0a509
line wrap: on
line source

from pyinfra import host
from pyinfra.facts.server import LinuxDistribution
from pyinfra.operations import apt, files, server, systemd
import package_lists

is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux']


def kitty():
    vers = '0.27.1'  # 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(local)
    server.shell([
        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([
        "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@7.30.1' --activate",
    ])


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


def proper_man():
    if host.name in ['pipe', 'prime'] or is_pi:
        apt.packages(packages=['mandb'], present=False)

kw = dict(latest=True)


apt.packages(packages=package_lists.setup, **kw)

if not is_pi:
    if host.name != 'pipe':
        apt.packages(packages=['reptyr'])
    kitty()
else:
    apt.packages(packages=package_lists.pi_setup)

proper_locate()
proper_man()


apt.packages(packages=package_lists.general, **kw)
apt.packages(packages=package_lists.debug, **kw)

if host.name in ["bang" ,'ditto']:
    apt.packages(packages=package_lists.for_bang_ditto, **kw)

if host.name == "pipe":
    apt.packages(packages=package_lists.for_pipe, **kw)

if host.name == "prime":
    apt.packages(packages=package_lists.for_prime, **kw)

if host.name == 'plus':
    apt.packages(packages=package_lists.laptop, **kw)

desktop_env = host.name in ['dash', 'slash', 'plus']
if desktop_env:
    apt.packages(packages=package_lists.xorg + package_lists.desktop, **kw)

if not is_pi:
    apt.packages(packages=package_lists.non_pi, **kw)
    if host.name != 'prime': # couldn't get prime to install a newer version than 18.7.0
        nodejs()
else:
    # move to another file?
    files.template(src="templates/pigpiod.service.j2", dest=f"/etc/systemd/system/pigpiod.service")
    systemd.service(service='pigpiod', daemon_reload=True, enabled=True)