#!/usr/bin/lua5.1 local invoker = require "invoker" local gfmt = string.format local function grep_segfault(syslog) if not invoker.statfile(syslog) then return false end local _, output = invoker.invoke(invoker.OUTPUT, "bash", "-c", gfmt("grep -e segfault %s | tail", syslog)) if type(output) ~= "string" then return false end if string.find(output, "libmutter-15.so", 1, true) then io.stdout:write("Warning, gnome-shell segfault found.\n") io.stdout:flush() return true end return false end local function restore_gnome_settings() local hdir = "/home/lnxall" if not invoker.chdir(hdir) then io.stderr:write(gfmt("Error, chdir(%s) has failed.\n", hdir)) io.stderr:flush() return false end io.stdout:write("Restoring configuration...\n"); io.stdout:flush() io.stdout:flush() for i = 1, 3 do invoker.invoke(0, "systemctl", "stop", "gdm") invoker.invoke(0, "rm", "-rf", "/root/.config/dconf") invoker.invoke(0, "rm", "-rf", ".config", ".cache", ".local") end invoker.invoke(0, "bash", "-c", "tar -Jxf /home/settings-20251202-093734.tar.xz ; sync ; reboot") invoker.invoke(0, "bash", "-c", "sleep 5 ; reboot") end local function check_segfault() invoker.setname("GNOME_SEGFAULT") while true do if grep_segfault("/tmp/syslog") or grep_segfault("/var/log/messages") then local dt = os.date("*t") invoker.rename("/var/log/messages", gfmt("/var/log/messages-%d%02d%02d", dt.year, dt.month, dt.day)) restore_gnome_settings() break end invoker.waitsec(invoker.uptime() <= 600 and 5 or 300) end os.exit(0) end check_segfault()