local shell=require("shell") local fs=require("filesystem") local args,opts=shell.parse(...) local BASE="/usr/share/optimize" local ok,man=pcall(dofile,BASE.."/manifest.lua") if not ok then io.stderr:write("optimize: manifest missing ("..tostring(man)..")\n")return 1 end local function read(p)local f=io.open(p,"rb")if not f then return nil end local d=f:read("*a")f:close()return d end local function setCfg(key,value) local cfg={} local d=read("/etc/yaru.cfg") if d then local s,t=pcall(require("serialization").unserialize,d)if s and type(t)=="table"then cfg=t end end cfg[key]=value local f=assert(io.open("/etc/yaru.cfg","w"))f:write(require("serialization").serialize(cfg))f:close() end local cmd=args[1]or"status" if cmd=="status"then print("Optimisation package "..man.version) for _,p in ipairs(man.patched)do local cur,orig=read(p),read(BASE.."/orig"..p) local state=not orig and"no backup"or cur==orig and"original"or"patched" print(string.format(" %-24s %s",p,state)) end for _,p in ipairs(man.added)do print(string.format(" %-24s %s",p,fs.exists(p)and"installed"or"absent"))end local d=read("/etc/yaru.cfg")or"" print(" desktop autostart: "..(d:find("autostart%s*=%s*false")and"off"or"on")) elseif cmd=="rollback"then io.write(opts.keep and"Restore the original OpenOS system files (desktop stays installed)? [y/N] " or"Restore original OpenOS files and REMOVE the desktop? [y/N] ") local a=io.read() if not a or not a:lower():match("^y")then print("cancelled")return end for _,p in ipairs(man.patched)do local orig=read(BASE.."/orig"..p) if orig then local f,err=io.open(p,"wb") if f then f:write(orig)f:close()print("restored "..p)else io.stderr:write(p..": "..tostring(err).."\n")end end end if not opts.keep then for _,p in ipairs(man.added)do if fs.exists(p)then fs.remove(p)print("removed "..p)end end for _,p in ipairs(man.state)do if fs.exists(p)then fs.remove(p)end end print("Backups kept in "..BASE.." (delete it to free space).") end print("Done. Reboot to apply.") elseif cmd=="desktop"then local on=args[2]~="off" setCfg("autostart",on) print("desktop autostart "..(on and"enabled"or"disabled")) else io.stderr:write("usage: optimize status | rollback [--keep] | desktop on|off\n")return 1 end