33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import json
|
|
import os
|
|
import pathlib
|
|
import subprocess
|
|
|
|
class Plugin:
|
|
async def whoami(self, *args):
|
|
return os.getuid()
|
|
|
|
def _systemd_status(self, service = "tailscaled.service"):
|
|
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"])
|
|
return result.stdout.parse().split(": ")[1]
|
|
|
|
async def install_state(self, *args):
|
|
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=shot"])
|
|
sysexts = json.load(sysext.stdout)
|
|
for hier in sysexts:
|
|
if hier.hierarchy != "/usr":
|
|
continue
|
|
|
|
if hier.extensions == "none":
|
|
if pathlib.Path("/etc/extensions/tailscale").exists():
|
|
return "installed"
|
|
|
|
if "tailscale" in hier.extensions:
|
|
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
|