From 5520ac312a647337dd80a1226763f01f5e999214 Mon Sep 17 00:00:00 2001 From: Vasiliy Stelmachenok <92667539+ventureoo@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:37:17 +0300 Subject: [PATCH] chwd: Add conditional_packages hook (#56) --- scripts/chwd | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/chwd b/scripts/chwd index ce19779..0c2a6e0 100755 --- a/scripts/chwd +++ b/scripts/chwd @@ -107,7 +107,17 @@ end local function exec_hook(hook) if hook ~= "" then - os.execute(hook) + local file = io.popen(("/bin/bash -c '%s'"):format(hook), "r") + + if file then + local output = file:read('*all') + file:close() + return output + else + print("ERROR: Unkown shell invocation error", hook) + end + else + print("WARNING: An unknown hook is being called", hook) end end @@ -123,7 +133,8 @@ local function get_profile(name, path) ["pre_install"] = "", ["post_install"] = "", ["post_remove"] = "", - ["pre_remove"] = "" + ["pre_remove"] = "", + ["conditional_packages"] = "" } for line in io.lines(path) do @@ -209,10 +220,24 @@ local function main() if options.install then exec_hook(hooks["pre_install"]) + + local conditional_packages = exec_hook(hooks["conditional_packages"]) + + if conditional_packages then + packages = packages .. " " .. conditional_packages + end + install(packages) exec_hook(hooks["post_install"]) elseif options.remove then exec_hook(hooks["pre_remove"]) + + local conditional_packages = exec_hook(hooks["conditional_packages"]) + + if conditional_packages then + packages = packages .. " " .. conditional_packages + end + remove(packages) exec_hook(hooks["post_remove"]) else