[Buildroot] [PATCH 04/13] support/scripts: comonalise checking merged status
Yann E. MORIN
yann.morin.1998 at free.fr
Wed May 14 16:58:16 UTC 2025
Rather than repeat the same canned sequence over and over again, move it
to a function that we can reuse as many times as needed. This will come
handy when we later need to check merged sbin.
Switch to using bash as it allows for nicer functions (local variables),
but we anyway require it globally already so that's not an additional
dependency.
Signed-off-by: Yann E. MORIN <yann.morin.1998 at free.fr>
---
support/scripts/check-merged-usr.sh | 46 ++++++++++++++++-------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/support/scripts/check-merged-usr.sh b/support/scripts/check-merged-usr.sh
index 433857cd8c..ed0c58e9b7 100755
--- a/support/scripts/check-merged-usr.sh
+++ b/support/scripts/check-merged-usr.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
#
# Check if a given custom skeleton or overlay complies to the merged /usr
# requirements:
@@ -10,30 +10,36 @@
# /usr/lib/
# /usr/sbin/
#
-# Output: the list of non-compliant paths (empty if compliant).
+# Input:
+# $1: the root directory (skeleton, overlay) to check
+# Output:
+# stdout: the list of non-compliant paths (empty if compliant).
#
+# The directory to check for merged-usr
+root="${1}"
+
# Extract the inode numbers for all of those directories. In case any is
# a symlink, we want to get the inode of the pointed-to directory, so we
# append '/.' to be sure we get the target directory. Since the symlinks
# can be anyway (/bin -> /usr/bin or /usr/bin -> /bin), we do that for
-# all of them.
+# each of them.
#
-lib_inode=$(stat -c '%i' "${1}/lib/." 2>/dev/null)
-bin_inode=$(stat -c '%i' "${1}/bin/." 2>/dev/null)
-sbin_inode=$(stat -c '%i' "${1}/sbin/." 2>/dev/null)
-usr_lib_inode=$(stat -c '%i' "${1}/usr/lib/." 2>/dev/null)
-usr_bin_inode=$(stat -c '%i' "${1}/usr/bin/." 2>/dev/null)
-usr_sbin_inode=$(stat -c '%i' "${1}/usr/sbin/." 2>/dev/null)
-not_merged_dirs=""
-test -z "$lib_inode" || \
- test "$lib_inode" = "$usr_lib_inode" || \
- not_merged_dirs="/lib"
-test -z "$bin_inode" || \
- test "$bin_inode" = "$usr_bin_inode" || \
- not_merged_dirs="$not_merged_dirs /bin"
-test -z "$sbin_inode" || \
- test "$sbin_inode" = "$usr_sbin_inode" || \
- not_merged_dirs="$not_merged_dirs /sbin"
-echo "${not_merged_dirs# }"
+test_merged() {
+ local root="${1}"
+ local dir1="${2}"
+ local dir2="${3}"
+ local inode1 inode2
+
+ inode1="$(stat -c '%i' "${root}${dir1}/." 2>/dev/null)"
+ inode2="$(stat -c '%i' "${root}${dir2}/." 2>/dev/null)"
+
+ test -z "${inode1}" || \
+ test "${inode1}" = "${inode2}" || \
+ printf '%s\n' "${dir1}"
+}
+
+test_merged "${root}" "/lib" "/usr/lib"
+test_merged "${root}" "/bin" "/usr/bin"
+test_merged "${root}" "/sbin" "/usr/sbin"
--
2.47.0
More information about the buildroot
mailing list