use proper python file io
Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
parent
90c9fd1cde
commit
d871074d29
23
main.py
23
main.py
|
@ -8,22 +8,21 @@ class Plugin:
|
||||||
return os.getuid()
|
return os.getuid()
|
||||||
|
|
||||||
def _systemd_status(self, service = "tailscaled.service"):
|
def _systemd_status(self, service = "tailscaled.service"):
|
||||||
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"])
|
result = subprocess.run(["/bin/sh", "-c", "systemctl status tailscaled.service | grep active"], stdout=subprocess.PIPE)
|
||||||
return result.stdout.parse().split(": ")[1]
|
return result.stdout.decode("utf-8").split(": ")[1]
|
||||||
|
|
||||||
async def install_state(self, *args):
|
async def install_state(self, *args):
|
||||||
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=short"])
|
sysext = subprocess.run(["/usr/bin/systemd-sysext", "list", "--json=short"], stdout=subprocess.PIPE)
|
||||||
sysexts = json.load(sysext.stdout)
|
sysexts = json.load(sysext.stdout.decode("utf-8"))
|
||||||
for hier in sysexts:
|
|
||||||
if hier.hierarchy != "/usr":
|
if sysexts.len() == 0:
|
||||||
|
return "not installed"
|
||||||
|
|
||||||
|
for ext in sysexts:
|
||||||
|
if ext.name != "tailscale":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if hier.extensions == "none":
|
return self._systemd_status()
|
||||||
if pathlib.Path("/etc/extensions/tailscale").exists():
|
|
||||||
return "installed"
|
|
||||||
|
|
||||||
if "tailscale" in hier.extensions:
|
|
||||||
return self._systemd_status()
|
|
||||||
|
|
||||||
return "impossible state"
|
return "impossible state"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue