taildeck-plugin/main.py

32 lines
980 B
Python
Raw Normal View History

import json
import os
import pathlib
import subprocess
2022-04-03 18:43:50 +00:00
class Plugin:
async def whoami(self, *args):
return os.getuid()
2022-04-03 18:43:50 +00:00
def _systemd_status(self, service = "tailscaled.service"):
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"], stdout=subprocess.PIPE)
return result.stdout.decode("utf-8").split(": ")[1]
async def install_state(self, *args):
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=short"], stdout=subprocess.PIPE)
sysexts = json.load(sysext.stdout.decode("utf-8"))
if sysexts.len() == 0:
return "not installed"
for ext in sysexts:
if ext.name != "tailscale":
continue
return self._systemd_status()
return "impossible state"
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):
pass