support/scripts: comonalise checking merged status

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-bin.

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@free.fr>
Acked-by: Arnout Vandecappelle <arnout@mind.be>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
This commit is contained in:
Yann E. MORIN
2025-09-01 11:01:13 +02:00
committed by Romain Naour
parent 151893aa08
commit 4c57c030da

View File

@@ -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"