from pyinfra.api import deploy
from pyinfra.operations import apt
from pyinfra.operations import server


@deploy
def deploy_tailscale():
    server.shell(
        name="Install tailscale signing key",
        commands=[
            "curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.noarmor.gpg "
            "| tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null 2>&1",
        ],
    )
    apt.repo(
        name="Add tailscale repository",
        src="deb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] "
            "https://pkgs.tailscale.com/stable/debian bookworm main",
        filename="tailscale",
    )
    apt.packages(
        name="Install tailscale",
        packages=["tailscale"],
        update=True,
    )