diff --git a/Makefile b/Makefile index b8678ea15b..77ca3b4702 100644 --- a/Makefile +++ b/Makefile @@ -782,17 +782,10 @@ endif # For a merged /usr, ensure that /lib, /bin and /sbin and their /usr # counterparts are appropriately setup as symlinks ones to the others. ifeq ($(BR2_ROOTFS_MERGED_USR),y) - - $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ - @$(call MESSAGE,"Sanity check in overlay $(d)")$(sep) \ - $(Q)not_merged_dirs="$$(support/scripts/check-merged-usr.sh $(d))"; \ - test -n "$$not_merged_dirs" && { \ - echo "ERROR: The overlay in $(d) is not" \ - "using a merged /usr for the following directories:" \ - $$not_merged_dirs; \ - exit 1; \ - } || true$(sep)) - + @$(call MESSAGE,"Sanity check in overlays $(call qstrip,$(BR2_ROOTFS_OVERLAY))") + support/scripts/check-merged-usr.sh \ + --type overlay \ + $(call qstrip,$(BR2_ROOTFS_OVERLAY)) endif # merged /usr $(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \ diff --git a/package/skeleton-custom/skeleton-custom.mk b/package/skeleton-custom/skeleton-custom.mk index b05c834b94..c194108307 100644 --- a/package/skeleton-custom/skeleton-custom.mk +++ b/package/skeleton-custom/skeleton-custom.mk @@ -26,17 +26,16 @@ endif # For a merged /usr, ensure that /lib, /bin and /sbin and their /usr # counterparts are appropriately setup as symlinks ones to the others. ifeq ($(BR2_ROOTFS_MERGED_USR),y) -SKELETON_CUSTOM_NOT_MERGED_USR_DIRS = \ - $(shell support/scripts/check-merged-usr.sh $(SKELETON_CUSTOM_PATH)) +define SKELETON_CUSTOM_NOT_MERGED_USR_DIRS + support/scripts/check-merged-usr.sh \ + --type skeleton \ + $(SKELETON_CUSTOM_PATH) +endef endif # merged /usr -ifeq ($(BR2_PACKAGE_SKELETON_CUSTOM)$(BR_BUILDING),yy) -ifneq ($(SKELETON_CUSTOM_NOT_MERGED_USR_DIRS),) -$(error The custom skeleton in $(SKELETON_CUSTOM_PATH) is not \ - using a merged /usr for the following directories: \ - $(SKELETON_CUSTOM_NOT_MERGED_USR_DIRS)) -endif -endif +define SKELETON_CUSTOM_CONFIGURE_CMDS + $(SKELETON_CUSTOM_NOT_MERGED_USR_DIRS) +endef # The target-dir-warning file and the lib{32,64} symlinks are the only # things we customise in the custom skeleton. @@ -49,9 +48,7 @@ define SKELETON_CUSTOM_INSTALL_TARGET_CMDS endef # For the staging dir, we don't really care what we install, but we -# need the /lib and /usr/lib appropriately setup. Since we ensure, -# above, that they are correct in the skeleton, we can simply copy the -# skeleton to staging. +# need the /lib and /usr/lib appropriately setup. define SKELETON_CUSTOM_INSTALL_STAGING_CMDS $(call SYSTEM_RSYNC,$(SKELETON_CUSTOM_PATH),$(STAGING_DIR)) $(call SYSTEM_USR_SYMLINKS_OR_DIRS,$(STAGING_DIR)) diff --git a/support/scripts/check-merged-usr.sh b/support/scripts/check-merged-usr.sh index 6d31c81c21..c3b5c6419a 100755 --- a/support/scripts/check-merged-usr.sh +++ b/support/scripts/check-merged-usr.sh @@ -11,16 +11,48 @@ # /usr/sbin/ # # Input: -# $1: the root directory (skeleton, overlay) to check +# --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). +# 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 +# 0: in case of success (stdout will be empty) +# !0: if any path is improperly merged # -# The directory to check for merged-usr -root="${1}" +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 @@ -42,19 +74,24 @@ is_valid_merged() { } test_merged() { - local root="${1}" - local dir1="${2}" - local dir2="${3}" + local type="${1}" + local root="${2}" + local dir1="${3}" + local dir2="${4}" if ! is_valid_merged "${root}" "${dir1}" "${dir2}"; then - printf '%s\n' "${dir1}" - is_success=false + report_error "${type}" "${root}" \ + '%s should be missing, or be a relative symlink to %s\n' \ + "${dir1}" "${dir2}" fi } is_success=true -test_merged "${root}" "/lib" "/usr/lib" -test_merged "${root}" "/bin" "/usr/bin" -test_merged "${root}" "/sbin" "/usr/sbin" +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}