2022-05-09 17:39:23 +00:00
|
|
|
import json
|
2022-05-09 17:17:53 +00:00
|
|
|
import os
|
2022-05-09 17:39:23 +00:00
|
|
|
import pathlib
|
|
|
|
import subprocess
|
2022-05-09 17:17:53 +00:00
|
|
|
|
2022-04-03 18:43:50 +00:00
|
|
|
class Plugin:
|
2022-05-09 17:17:53 +00:00
|
|
|
async def whoami(self, *args):
|
|
|
|
return os.getuid()
|
2022-04-03 18:43:50 +00:00
|
|
|
|
2022-05-09 17:39:23 +00:00
|
|
|
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):
|
2022-05-09 17:40:50 +00:00
|
|
|
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=short"])
|
2022-05-09 17:39:23 +00:00
|
|
|
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"
|
2022-04-04 15:30:38 +00:00
|
|
|
|
|
|
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
2022-04-12 22:31:39 +00:00
|
|
|
async def _main(self):
|
2022-05-09 17:17:53 +00:00
|
|
|
pass
|