diff --git a/modules/deb.sh b/modules/deb.sh index c250753..28572f6 100644 --- a/modules/deb.sh +++ b/modules/deb.sh @@ -82,11 +82,17 @@ function deb_from_repo_pool_get() { local -r deb_package_path="pool/${component}/${initial}/${package}/${package}_${version}_${architecture}.deb" local -r filename=$(basename $deb_package_path) - run_and_log_cmd "wget -Nq ${repo_url}/${deb_package_path} -P ${download_dir}" + run_and_log_cmd_noexit "wget -Nq ${repo_url}/${deb_package_path} -P ${download_dir}" + local exit_code=$? rm -f /tmp/Packages - log_info "Successfully downloaded ${filename}" - echo ${filename} + if [[ ${exit_code} -ne 0 ]]; then + log_warn "Could not download ${filename}" + echo "" + else + log_info "Successfully downloaded ${filename}" + echo ${filename} + fi } # Extract the binary files of a deb package into a directory @@ -145,6 +151,13 @@ function deb_get_and_install_pacakge() { else local debian_version="-1+${deb_distro}+${deb_codename}" DEB_NAME=$(deb_from_repo_pool_get "work/deb-packages" ${MENDER_APT_REPO_URL} ${deb_arch} "${package}" "${version}${debian_version}") + if [[ -z "${DEB_NAME}" ]]; then + local debian_version_fallback="-1" + DEB_NAME=$(deb_from_repo_pool_get "work/deb-packages" ${MENDER_APT_REPO_URL} ${deb_arch} "${package}" "${version}${debian_version_fallback}") + if [[ -z "${DEB_NAME}" ]]; then + log_fatal "Specified version for ${package} cannot be found, tried ${version}${debian_version} and ${version}${debian_version_fallback}" + fi + fi fi deb_extract_package "work/deb-packages/${DEB_NAME}" "work/rootfs/" } diff --git a/modules/run.sh b/modules/run.sh index a52efd3..93f9159 100644 --- a/modules/run.sh +++ b/modules/run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Copyright 2019 Northern.tech AS +# Copyright 2022 Northern.tech AS # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Run a command, capture output and log it +# Run a command, capture and log output, and exit on non-zero return code # # $1 - command to run function run_and_log_cmd() { @@ -31,3 +31,19 @@ function run_and_log_cmd() { exit ${exit_code} fi } + +# Run a command, capture and log output, and return the command's return code +# +# $1 - command to run +function run_and_log_cmd_noexit() { + local -r cmd="${1}" + local -r position="(${BASH_SOURCE[1]}:${BASH_LINENO[0]}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }" + local exit_code=0 + output="$({ eval ${cmd}; } 2>&1)" || exit_code=$? + local log_msg="Running: ${position} \n\r\n\r\t${cmd}" + if [[ "${output}" != "" ]]; then + log_msg="${log_msg}\n\t${output}\n" + fi + log_debug "${log_msg}" + return ${exit_code} +}