From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 14E68138334 for ; Sun, 14 Jul 2019 13:00:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5BE3CE08CE; Sun, 14 Jul 2019 13:00:37 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 24BB4E08C0 for ; Sun, 14 Jul 2019 13:00:37 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6A1B9347AA5 for ; Sun, 14 Jul 2019 13:00:35 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 97EB7731 for ; Sun, 14 Jul 2019 13:00:30 +0000 (UTC) From: "Thomas Deutschmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Deutschmann" Message-ID: <1563105498.97999e87aba2a55e3e719742f25eb53265a46df3.whissi@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: / X-VCS-Repository: proj/genkernel X-VCS-Files: gen_initramfs.sh X-VCS-Directories: / X-VCS-Committer: whissi X-VCS-Committer-Name: Thomas Deutschmann X-VCS-Revision: 97999e87aba2a55e3e719742f25eb53265a46df3 X-VCS-Branch: master Date: Sun, 14 Jul 2019 13:00:30 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 0dc71d41-efc6-40d3-b8f5-e199d4ae5acf X-Archives-Hash: f3fef3526e45eb9d2a5de7ee07cda493 commit: 97999e87aba2a55e3e719742f25eb53265a46df3 Author: Thomas Deutschmann gentoo org> AuthorDate: Sun Jul 14 10:40:22 2019 +0000 Commit: Thomas Deutschmann gentoo org> CommitDate: Sun Jul 14 11:58:18 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=97999e87 gen_initramfs.sh: Add copy_system_binaries() function Difference to copy_binaries() is, that copy_system_binaries() does NOT try to recreate directory structure. Any system binary to copy will be placed into same destination directory. Because we focus on *system* binaries, it's safe to assume that everything belongs to the same directory. This assumption will allow us to copy from crossdev environments (i.e. /usr/$CHOST). Signed-off-by: Thomas Deutschmann gentoo.org> gen_initramfs.sh | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index df168d8..2b00d5e 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -62,6 +62,114 @@ copy_binaries() { || gen_die "Binary '${binary}' or some of its library dependencies could not be copied!" } +# @FUNCTION: copy_system_binaries +# @USAGE: +# @DESCRIPTION: +# Copies system binaries into dest dir. +# +# Difference to copy_binaries() is, that copy_system_binaries() does NOT +# try to recreate directory structure. Any system binary to copy will be +# placed into same DESTination DIRectory. +# Because we focus on *system* binaries, it's safe to assume that everything +# belongs to the same directory. This assumption will allow us to copy from +# crossdev environments (i.e. /usr/$CHOST). +copy_system_binaries() { + [[ ${#} -lt 2 ]] \ + && gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid usage of ${FUNCNAME}(): Function takes at least two arguments (${#} given)!" + + local destdir=${1} + shift + + [[ ! -d "${destdir}" ]] \ + && gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid usage of ${FUNCNAME}(): Destdir '${destdir}' does NOT exist!" + + if [ ! -f "${TEMP}/.system_binaries_copied" ] + then + touch "${TEMP}/.system_binaries_copied" \ + || gen_die "Failed to set '${TEMP}/.system_binaries_copied' marker!" + fi + + local binary binary_realpath binary_basename base_dir + local binary_dependency binary_dependency_basename + for binary in "$@" + do + [[ -e "${binary}" ]] \ + || gen_die "$(get_useful_function_stack)System binary '${binary}' could not be found!" + + print_info 5 "System binary '${binary}' should be copied to '${destdir}' ..." + + binary_basename=$(basename "${binary}") + if [[ -z "${binary_basename}" ]] + then + gen_die "$(get_useful_function_stack)Failed to determine basename of '${binary}'!" + else + print_info 5 "System binary's basename is '${binary_basename}'." + fi + + if [[ -e "${destdir}/${binary_basename}" ]] + then + print_info 5 "System binary '${binary_basename}' already exists in '${destdir}'; Skipping ..." + continue + fi + + if [[ -L "${binary}" ]] + then + binary_realpath=$(realpath "${binary}") + if [[ -z "${binary_realpath}" ]] + then + gen_die "$(get_useful_function_stack)Failed to resolve path to '${binary}'!" + elif [[ ! -e "${binary_realpath}" ]] + then + gen_die "$(get_useful_function_stack)System binary '${binary}' was resolved to '${binary_realpath}' but file does NOT exist!" + else + print_info 5 "System binary '${binary}' resolved to '${binary_realpath}'." + binary=${binary_realpath} + fi + fi + + base_dir=$(dirname "${binary}") + if [[ -z "${base_dir}" ]] + then + gen_die "$(get_useful_function_stack)Failed to determine directory of '${binary}'!" + else + print_info 5 "System binary dirname set to '${base_dir}'." + fi + + if LC_ALL=C lddtree "${binary}" 2>&1 | fgrep -q 'not found' + then + gen_die "$(get_useful_function_stack)System binary '${binary}' is linked to missing libraries and may need to be re-built!" + fi + + local is_first=1 + while IFS= read -r -u 3 binary_dependency + do + binary_dependency_basename=$(basename "${binary_dependency}") + if [[ -z "${binary_dependency_basename}" ]] + then + gen_die "$(get_useful_function_stack)Failed to determine basename of '${binary_dependency}'!" + fi + + if [[ ${is_first} -eq 1 ]] + then + # `lddtree --list` first line is always the binary itself + print_info 5 "Copying '${base_dir}/${binary_dependency_basename}' to '${destdir}/' ..." + cp -aL "${base_dir}/${binary_dependency_basename}" "${destdir}/${binary_basename}" \ + || gen_die "$(get_useful_function_stack)Failed to copy '${base_dir}/${binary_dependency_basename}' to '${destdir}'!" + + is_first=0 + elif [[ -e "${destdir}/${binary_dependency_basename}" ]] + then + print_info 5 "System binary '${binary_basename}' already exists in '${destdir}'; Skipping ..." + continue + else + print_info 5 "Need to copy dependency '${base_dir}/${binary_dependency_basename}' ..." + "${FUNCNAME}" "${destdir}" "${base_dir}/${binary_dependency_basename}" + fi + done 3< <(lddtree --list "${binary}" 2>/dev/null) + IFS="${GK_DEFAULT_IFS}" + done +} + log_future_cpio_content() { print_info 2 "=================================================================" 1 0 1 print_info 2 "About to add these files from '${PWD}' to cpio archive:" 1 0 1 @@ -1413,7 +1521,7 @@ create_initramfs() { append_data 'overlay' fi - if [ -f "${TEMP}/.binaries_copied" ] + if [[ -f "${TEMP}/.binaries_copied" || -f "${TEMP}/.system_binaries_copied" ]] then append_data 'linker' else