diff --git a/src/share/yang/modules/utils/check-hashes.sh b/src/share/yang/modules/utils/check-hashes.sh index 0e6067738a..398d26b921 100755 --- a/src/share/yang/modules/utils/check-hashes.sh +++ b/src/share/yang/modules/utils/check-hashes.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -21,20 +21,34 @@ set -eu script_path=$(cd "$(dirname "${0}")" && pwd) cd "${script_path}/.." +amend=false +if test "${1-}" = '-a' || test "${1-}" = '--amend'; then + amend=true +fi + +exit_code=0 for m in *.yang do hash1=$(yanglint -f yin "${m}" | openssl dgst -sha256 | sed 's/(stdin)= //') - h="hashes/$(basename "${m}").hash" + h="hashes/$(basename "${m}" .yang).hash" if test -f "${h}" then hash2=$(cat "${h}") if test "$hash1" != "$hash2" then + exit_code=$((exit_code | 1)) printf 'hash mismatch on %s expected %s in %s\n' "${m}" "${hash1}" "${h}" - exit 1 + if "${amend}"; then + printf '%s\n' "${hash1}" > "${h}" + fi fi else + exit_code=$((exit_code | 2)) printf 'missing hash file %s for %s\n' "${h}" "${m}" - exit 2 + if "${amend}"; then + printf '%s\n' "${hash1}" > "${h}" + fi fi done + +exit "${exit_code}"