mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-01 21:23:51 -09:00
By moving the loop over the overlays into the script, we can generate better error messages about how and why a skeleton or a specific overlay is improperly setup for merged-usr. We can also now rely on its exit code to decide whether the skeleton or the overlays are properly setup, rather than stash the stdout/stderr to a Makefile variable and test the emptiness thereof. Introduce a --type option to pass the type of root to verify, for better error reporting. This will incidentally be usefull in a future commit, when we need to take different actions based on whether the root is a skeleton or an overlay. Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr> Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> Signed-off-by: Romain Naour <romain.naour@smile.fr>
98 lines
2.1 KiB
Bash
Executable File
98 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Check if a given custom skeleton or overlay complies to the merged /usr
|
|
# requirements:
|
|
# /
|
|
# /bin -> usr/bin
|
|
# /lib -> usr/lib
|
|
# /sbin -> usr/sbin
|
|
# /usr/bin/
|
|
# /usr/lib/
|
|
# /usr/sbin/
|
|
#
|
|
# Input:
|
|
# --type TYPE the type of root to check: 'skeleton' or 'overlay'
|
|
# $*: the root directories (skeleton, overlays) to check
|
|
# Output:
|
|
# stdout: the list of non-compliant paths (empty if compliant).
|
|
# Exit code:
|
|
# 0: in case of success (stdout will be empty)
|
|
# !0: if any path is improperly merged
|
|
#
|
|
|
|
opts="type:"
|
|
ARGS="$(getopt -n check-merged -o "" -l "${opts}" -- "${@}")" || exit 1
|
|
eval set -- "${ARGS}"
|
|
|
|
type=
|
|
while :; do
|
|
case "${1}" in
|
|
(--type)
|
|
type="${2}"
|
|
shift 2
|
|
;;
|
|
(--)
|
|
shift
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
report_error() {
|
|
local type="${1}"
|
|
local root="${2}"
|
|
local fmt="${3}"
|
|
shift 3
|
|
|
|
if ${first}; then
|
|
printf "The %s in %s is not properly setup:\n" \
|
|
"${type}" "${root}"
|
|
fi
|
|
first=false
|
|
# shellcheck disable=SC2059 # fmt *is* a format string
|
|
printf " - ${fmt}" "${@}"
|
|
is_success=false
|
|
}
|
|
|
|
# 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
|
|
# each of them.
|
|
#
|
|
|
|
is_valid_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}"
|
|
}
|
|
|
|
test_merged() {
|
|
local type="${1}"
|
|
local root="${2}"
|
|
local dir1="${3}"
|
|
local dir2="${4}"
|
|
|
|
if ! is_valid_merged "${root}" "${dir1}" "${dir2}"; then
|
|
report_error "${type}" "${root}" \
|
|
'%s should be missing, or be a relative symlink to %s\n' \
|
|
"${dir1}" "${dir2}"
|
|
fi
|
|
}
|
|
|
|
is_success=true
|
|
for root; do
|
|
first=true
|
|
test_merged "${type}" "${root}" "/lib" "/usr/lib"
|
|
test_merged "${type}" "${root}" "/bin" "/usr/bin"
|
|
test_merged "${type}" "${root}" "/sbin" "/usr/sbin"
|
|
done
|
|
|
|
${is_success}
|