From bd34d059f3a92b2f3f553acb50ed28a49a80a7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20L=C3=BCke?= Date: Wed, 20 Jan 2021 12:09:33 +0100 Subject: [PATCH] Fall back to source repository license files if not in portage When a license file is newly added, portage may not yet have it in the shared folder and the license inclusion step fails. Fall back to the source repositories and look for the license file there, too. Print a warning if not found instead of failing to build. --- build_library/build_image_util.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index 8b515aebfd..e528aaffa1 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -452,8 +452,23 @@ EOF sudo lbzip2 -9 "${root_fs_dir}"/usr/share/licenses/licenses.json # Copy all needed licenses to a "common" subdirectory and compress them local license_list # define before assignment because it would mask any error - license_list="$(jq -r '.[] | "/var/gentoo/repos/gentoo/licenses/\(.licenses | .[])"' "${json_input}" | sort | uniq)" - sudo cp ${license_list} "${root_fs_dir}"/usr/share/licenses/common/ + license_list="$(jq -r '.[] | "\(.licenses | .[])"' "${json_input}" | sort | uniq)" + local license_dirs=( + "/mnt/host/source/src/third_party/coreos-overlay/licenses/" + "/mnt/host/source/src/third_party/portage-stable/" + "/var/gentoo/repos/gentoo/licenses/" + "none" + ) + for license_file in ${license_list}; do + for license_dir in ${license_dirs[*]}; do + if [ "${license_dir}" = "none" ]; then + warn "The license file \"${license_file}\" was not found" + elif [ -f "${license_dir}${license_file}" ]; then + sudo cp "${license_dir}${license_file}" "${root_fs_dir}"/usr/share/licenses/common/ + break + fi + done + done # Compress the licenses just with gzip because there is no big difference as they are single files sudo gzip -9 "${root_fs_dir}"/usr/share/licenses/common/* }