Skip to content

Commit

Permalink
fix triggers for presets, run only on services that were disabled - u…
Browse files Browse the repository at this point in the history
…se magic rpm.next_file()
  • Loading branch information
tpgxyz committed Mar 21, 2019
1 parent eba5813 commit d56fdec
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions triggers.systemd
Expand Up @@ -148,31 +148,37 @@ end
-- as part of the installation of RPM files
local systemctl = "/bin/systemctl"
local unitdir = "/lib/systemd/system/"
local path = "/lib/systemd/system-preset/"
local pfiles = assert(io.popen('/bin/ls -1 ' ..path.. "*.preset")):lines()
presets = {}

if pfiles ~= nil then
for file in pfiles do
for line in assert(io.lines(file)) do
local rpmfiles = rpm.next_file()
local presets = {}

if rpmfiles ~= nil then
for kfile,vfile in pairs(rpmfiles) do
local preset = vfile:match("^/lib/systemd/system%-preset/.*.preset$")
if preset ~= nil then
local f = assert(io.open(preset))
while true do
local line = f:read()
if line == nil then
break
end

local cmd, arg = line:match("^([^ \t]+)[ \t]+([^\n \t]+)")
if (cmd == "enable" or cmd == "disable") and string.match(arg, "%*") ~= "*" then
presets[#presets + 1] = arg:match("^%s*(.+)%s*$")
end
end
io.close()
end
f:close()
end
end
end

if posix.access(systemctl, "x") then
for key,unit in pairs(presets) do
for kunit,unit in pairs(presets) do
if posix.stat(unitdir ..unit) then
print("Executing systemd preset on: " ..unit)
os.execute(systemctl .." preset -q --now " .. unit)
local status=io.popen('systemctl is-enabled ' ..unit):read("*l")
if status == "disabled" then
print("Executing systemd preset on: " ..unit)
os.execute(systemctl .." preset -q --now " .. unit)
end
end
end
end

0 comments on commit d56fdec

Please sign in to comment.