Fix sxmo_power.sh polkit multi-session auth and dmenu PATH

This commit is contained in:
Luxferre
2026-10-21 17:59:11 +03:00
parent d240f25131
commit 1ee112561c
4 changed files with 62 additions and 32 deletions
+51 -28
View File
@@ -14,39 +14,62 @@ usage() {
run_polkit_login1() {
method="$1"
python3 - "$method" <<'PYEOF' >/dev/null 2>&1
import os, pty, select, sys
import os, pty, select, sys, time
method = sys.argv[1]
ppid = os.getpid()
if method == "Reboot":
acts = "org.freedesktop.login1.reboot org.freedesktop.login1.reboot-multiple-sessions org.freedesktop.login1.reboot-ignore-inhibit"
acts = [
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
]
else:
acts = "org.freedesktop.login1.power-off org.freedesktop.login1.power-off-multiple-sessions org.freedesktop.login1.power-off-ignore-inhibit"
cmd = (
"pkttyagent --process $$ & AG=$!; sleep 0.15; "
"for act in " + acts + "; do "
"pkcheck --action-id $act --process $$ -u >/dev/null 2>&1 || true; "
"done; "
"kill $AG 2>/dev/null || true; "
"exec busctl call --allow-interactive-authorization=true "
"org.freedesktop.login1 /org/freedesktop/login1 "
"org.freedesktop.login1.Manager " + method + " b true"
)
pid, fd = pty.fork()
if pid == 0:
os.execlp("sh", "sh", "-c", cmd)
while True:
r, _, _ = select.select([fd], [], [], 3.0)
if not r:
break
acts = [
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
]
for act in acts:
cmd = (
f"pkttyagent --process {ppid} & AG=$!; sleep 0.25; "
f"pkcheck --action-id {act} --process {ppid} -u >/dev/null 2>&1; "
f"RC=$?; kill $AG 2>/dev/null || true; exit $RC"
)
pid, fd = pty.fork()
if pid == 0:
os.execlp("sh", "sh", "-c", cmd)
t0 = time.time()
buf = b""
while time.time() - t0 < 5.0:
r, _, _ = select.select([fd], [], [], 0.2)
if r:
try:
d = os.read(fd, 1024)
if not d:
break
buf += d
if b"assword:" in buf or b"password:" in buf.lower():
buf = b""
os.write(fd, b"147147\n")
except OSError:
break
try:
d = os.read(fd, 1024)
if not d:
break
if b"assword:" in d or b"password" in d.lower():
os.write(fd, b"147147\n")
os.close(fd)
except OSError:
break
_, st = os.waitpid(pid, 0)
sys.exit(os.WEXITSTATUS(st))
pass
os.waitpid(pid, 0)
os.execlp(
"busctl",
"busctl",
"call",
"--allow-interactive-authorization=true",
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
method,
"b",
"true",
)
PYEOF
}
Binary file not shown.