From 8681f7a4f3a15d45503dc58181a549f17e4253b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 9 Apr 2024 12:12:55 +0200 Subject: [PATCH] Symlink bin filenames to sbin for compatibility When packages are rebuilt in a merged buildroot and their contents migrate from /usr/sbin to /usr/bin, we want to provide compat symlinks so that the old names still work. This scriptlet covers all packages that have files in /usr/sbin in F40. We have just one scriptlet in filesystem because that's easier than having separate scriptlets in each package. When the package for which we created a symlink is removed, we remove the symlink. The list of filenames was initially created using 'dnf repoquery', but it seems that this is unreliable. Additional files were generated using: (ls -1 /usr/sbin/|sort -g|sed 's/.*/ "\0",/'; sed -n -e '/^ "acme/,/^ "zramctl"/p' -- /usr/bin +--# This implements filesystem(unmerged-sbin-symlinks) feature. +st = posix.stat("/usr/sbin") +if not st or st.type == "link" then + return +end + +filenames = %sbin_filenames + +a = rpm.next_file() +while a do + name = a:match("^.+/(.+)$") + if filenames[name] then + b = "/usr/sbin/"..name + sta = posix.stat(a) + stb = posix.stat(b) + print(a, sta, b, stb) + + if sta and not stb then + print('Symlinking /usr/sbin/'..name..'->/usr/bin/'..name) + posix.symlink("../bin/"..name, "/usr/sbin/"..name) + end + end + + a = rpm.next_file() +end + +%filetriggerpostun -p -- /usr/bin +--# This implements filesystem(unmerged-sbin-symlinks) feature. +st = posix.stat("/usr/sbin") +if not st or st.type == "link" then + return +end + +filenames = %sbin_filenames + +a = rpm.next_file() +while a do + name = a:match("^.+/(.+)$") + if filenames[name] then + b = "/usr/sbin/"..name + sta = posix.stat(a) + stb = posix.stat(b) + print(a, sta, b, stb) + + if sta and not stb then + print('Symlinking '..b..'->/usr/bin/'..name) + posix.symlink("../bin/"..name, b) + elseif not sta and stb and stb.type == "link" then + target = posix.readlink(b) + if target == "../bin/"..name then + print('Removing', b) + os.remove(b) + else + print('Not touching '..b..' -> '..target) + end + end + end + + a = rpm.next_file() +end + +%filetriggerpostun -p -- /sbin /usr/sbin +--# This implements filesystem(unmerged-sbin-symlinks) feature. +st = posix.stat("/usr/sbin") +if not st or st.type == "link" then + return +end + +filenames = %sbin_filenames + +b = rpm.next_file() +while b do + name = b:match("^.+/(.+)$") + print('filetriggerpostun', b) + + if filenames[name] then + a = "/usr/bin/"..name + sta = posix.stat(a) + stb = posix.stat(b) + + if sta and not stb then + print('Symlinking /usr/sbin/'..name..'->'..a) + posix.symlink("../bin/"..name, "/usr/sbin/"..name) + end + end + + b = rpm.next_file() +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 @@ -184,8 +2294,6 @@ end %dir %{_datadir}/filesystem %{_datadir}/filesystem/paths - - %files -f filelist %defattr(0755,root,root,0755) %dir %attr(555,root,root) /