File size: 2,060 Bytes
7ea15a2
6337ffb
 
 
0568707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6337ffb
 
 
 
 
 
211a1f0
 
 
 
b5f7c2b
211a1f0
 
c3a40c5
e579122
c3a40c5
211a1f0
6337ffb
 
 
 
 
 
7ea15a2
 
6337ffb
7ea15a2
6337ffb
7ea15a2
6337ffb
 
 
 
 
7ea15a2
6337ffb
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Verify that a clean-install test left no Eggcracker paths behind."""

from __future__ import annotations

import sys as _bootstrap_sys

if not _bootstrap_sys.flags.isolated or not _bootstrap_sys.flags.no_site:
    raise SystemExit(
        "privileged verifier requires /usr/bin/python3 -I -S scripts/verify_uninstalled.py"
    )

import posix as _bootstrap_posix

try:
    _bootstrap_posix.readlink(__file__)
except OSError:
    pass
else:
    raise SystemExit("refusing a symlinked privileged verifier")

import grp
import os
import pwd
import subprocess
from pathlib import Path

PATHS = (
    Path("/usr/local/lib/lumi-eggcracker"), Path("/usr/local/bin/eggcracker"),
    Path("/etc/lumi-eggcracker"), Path("/etc/systemd/system/lumi-eggcracker.service"),
    Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
    Path("/etc/tmpfiles.d/lumi-eggcracker.conf"),
    Path("/var/lib/lumi-eggcracker"), Path("/run/lumi-eggcracker"),
    Path("/run/lumi-eggcracker-watchdog"),
    Path("/var/lib/lumi-eggcracker-install-journal.json"),
    Path("/var/lib/lumi-eggcracker-uninstall-journal.json"),
    Path("/run/lock/lumi-eggcracker-lifecycle.lock"),
)


def main() -> int:
    if os.geteuid() != 0:
        raise SystemExit("uninstall verifier must run as root")
    if any(path.exists() or path.is_symlink() for path in PATHS):
        raise SystemExit("Eggcracker installation path remains")
    units = subprocess.run(["/usr/bin/systemctl", "list-units", "lumi-eggcracker*", "--all", "--plain", "--no-legend"], capture_output=True, text=True, check=False)
    if units.stdout.strip():
        raise SystemExit("Eggcracker unit remains")
    try:
        pwd.getpwnam("lumi-eggcracker-workload")
    except KeyError:
        pass
    else:
        raise SystemExit("created workload account remains")
    try:
        grp.getgrnam("lumi-eggcracker-workload")
    except KeyError:
        print('{"result":"PASS"}')
        return 0
    raise SystemExit("created workload group remains")


if __name__ == "__main__":
    raise SystemExit(main())