From c6b64acaef1716ada4cfa5e8cfa35479f9d79a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 9 Apr 2024 14:00:08 +0200 Subject: [PATCH] Symlink /usr/sbin to /usr/bin if possible /usr/local/sbin is also symlinked to /usr/local/bin if possible. 'return 0' is dropped because that causes issues with rpm: https://github.com/rpm-software-management/rpm/issues/3029 --- filesystem.spec | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/filesystem.spec b/filesystem.spec index 0620b97..0883102 100644 --- a/filesystem.spec +++ b/filesystem.spec @@ -176,7 +176,6 @@ end posix.mkdir("/var") posix.symlink("../run", "/var/run") posix.symlink("../run/lock", "/var/lock") -return 0 %global sbin_filenames %{lua: print('{\\n') @@ -2283,6 +2282,55 @@ while b do b = rpm.next_file() end + +%global merge_scriptlet %{expand: +--# Symlink /usr/sbin→/usr/bin and /usr/local/sbin→/usr/local/bin if possible + +for _,path in pairs({"/usr/sbin", "/usr/local/sbin"}) do + st = posix.stat(path) + if st and st.type ~= "link" then + good = true + + items = rpm.glob(path.."/*") + for _,v in pairs(items) do + --# rpm.glob() returns the original pattern if match fails :((( + if v ~= path.."/*" then + st = posix.stat(v) + + if not st then + print("Could not stat "..v) + else + if st.type ~= "link" then + print("/usr/sbin cannot be merged, found "..v) + good = false + break + end + + target = posix.readlink(v) + name = v:match("^.+/(.+)$") + if target ~= "../bin/"..name then + print("/usr/sbin cannot be merged, "..v.." points to "..target) + good = false + break + end + end + end + end + + if good then + print("All files under "..path.." are symlinks; linking to ./bin...") + + for _,v in pairs(items) do + os.remove(v) + end + os.remove(path) + posix.symlink("bin", path) + print("...done") + end + end +end +} + %posttrans -p --# we need to restorecon on some dirs created in %pretrans or by other packages if posix.access ("/usr/sbin/restorecon", "x") then @@ -2290,6 +2338,11 @@ if posix.access ("/usr/sbin/restorecon", "x") then rpm.execute("/usr/sbin/restorecon", "-r", "/usr/lib/debug") end +%merge_scriptlet + +%transfiletriggerpostun -p -- /sbin /usr/sbin +%merge_scriptlet + %files content %dir %{_datadir}/filesystem %{_datadir}/filesystem/paths