diff --git a/scripts/utils-general.sh b/scripts/utils-general.sh index a553624b..2c0fff12 100644 --- a/scripts/utils-general.sh +++ b/scripts/utils-general.sh @@ -48,3 +48,40 @@ check_folder_age() { fi } +# Usage: check_git_match [] +check_git_match() { + local target_ref="$1" + local repo_dir="${2:-.}" + + pushd "$repo_dir" > /dev/null || return 2 + + local current_tag current_branch current_commit_long current_commit_short + current_tag=$(git describe --tags --exact-match 2>/dev/null || true) + current_branch=$(git symbolic-ref --short HEAD 2>/dev/null || true) + current_commit_long=$(git rev-parse HEAD 2>/dev/null || true) + current_commit_short=$(git rev-parse --short HEAD 2>/dev/null || true) + + if [[ -n "$current_tag" && "$target_ref" == "$current_tag" ]]; then + echo "match: tag ($current_tag)" + popd > /dev/null + return 0 + elif [[ -n "$current_branch" && "$target_ref" == "$current_branch" ]]; then + echo "match: branch ($current_branch)" + popd > /dev/null + return 0 + elif [[ -n "$current_commit_long" && "$target_ref" == "$current_commit_long" ]]; then + echo "match: commit (long $current_commit_long)" + popd > /dev/null + return 0 + elif [[ -n "$current_commit_short" && "$target_ref" == "$current_commit_short" ]]; then + echo "match: commit (short $current_commit_short)" + popd > /dev/null + return 0 + else + echo "no match found for $target_ref" + printf "Version inconsistency. Please fix ${repo_dir}\n" + printf "(expected: ${target_ref}, got: ${current_tag} ${current_branch} ${current_commit_long} ${current_commit_short})\n" + popd > /dev/null + exit 1 + fi +} diff --git a/scripts/utils-openssl.sh b/scripts/utils-openssl.sh index aa2eb5c7..7cf043a9 100755 --- a/scripts/utils-openssl.sh +++ b/scripts/utils-openssl.sh @@ -39,12 +39,7 @@ USE_CUR_TAG=${USE_CUR_TAG:-0} clone_openssl() { if [ -d ${OPENSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then - OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current)) - if [ "${OPENSSL_TAG_CUR}" != "${OPENSSL_TAG}" ]; then # force a rebuild - printf "Version inconsistency. Please fix ${OPENSSL_SOURCE_DIR} (expected: ${OPENSSL_TAG}, got: ${OPENSSL_TAG_CUR})\n" - do_cleanup - exit 1 - fi + check_git_match "${OPENSSL_TAG}" "${OPENSSL_SOURCE_DIR}" fi if [ ! -d ${OPENSSL_SOURCE_DIR} ]; then @@ -83,7 +78,7 @@ clone_openssl() { } install_openssl() { - printf "\nInstalling OpenSSL ${OPENSSL_TAG} ..." + printf "\nInstalling OpenSSL ${OPENSSL_TAG} ...\n" clone_openssl cd ${OPENSSL_SOURCE_DIR} diff --git a/scripts/utils-wolfssl.sh b/scripts/utils-wolfssl.sh index 9dfae91a..5827205b 100755 --- a/scripts/utils-wolfssl.sh +++ b/scripts/utils-wolfssl.sh @@ -44,12 +44,7 @@ clone_wolfssl() { cp -pr ${WOLFSSL_FIPS_BUNDLE}/* ${WOLFSSL_SOURCE_DIR}/ else if [ -d ${WOLFSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then - WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current)) - if [ "${WOLFSSL_TAG_CUR}" != "${WOLFSSL_TAG}" ]; then # force a rebuild - printf "Version inconsistency. Please fix ${WOLFSSL_SOURCE_DIR} (expected: ${WOLFSSL_TAG}, got: ${WOLFSSL_TAG_CUR})\n" - do_cleanup - exit 1 - fi + check_git_match "${WOLFSSL_TAG}" "${WOLFSSL_SOURCE_DIR}" fi if [ ! -d ${WOLFSSL_SOURCE_DIR} ]; then