mirror of
https://github.com/armbian/build.git
synced 2025-08-12 06:06:58 +02:00
- artifacts: u-boot/kernel - pt7 - adapt legacy/artifact versions; use common `capture_rename_legacy_debs_into_artifacts()` - artifacts: u-boot - pt6: add artifact for u-boot - use artifact version / reason in actual u-boot .deb if present - artifacts: kernel - pt5: tune kernel version, refactor - artifacts: kernel - pt4: squash unrelated bugs that show up; move `prepare_compilation_vars()` to default build - artifacts: kernel - pt3: drivers+patches+.config hashing - split file hashing function from drivers-harness; fix it so filenames are relative and sorted; sort from ${SRC}, always - aplit prepare_kernel_config_core_or_userpatches() from `kernel_config_initialize()` - artifacts: kernel - pt2: memoizing git ref2info - artifacts: kernel - pt1: versioning
51 lines
2.0 KiB
Bash
51 lines
2.0 KiB
Bash
function calculate_hash_for_all_files_in_dirs() {
|
|
declare -a dirs_to_hash=("$@")
|
|
declare -a files_to_hash=()
|
|
for dir in "${dirs_to_hash[@]}"; do
|
|
# skip if dir doesn't exist...
|
|
if [[ ! -d "${dir}" ]]; then
|
|
display_alert "calculate_hash_for_all_files_in_dirs" "skipping non-existent dir \"${dir}\"" "warn"
|
|
continue
|
|
fi
|
|
declare found_files="no"
|
|
# shellcheck disable=SC2044 # lets expand... # -L: follow symlinks
|
|
for file in $(find -L "${dir}" -type f); do
|
|
files_to_hash+=("${file}")
|
|
found_files="yes"
|
|
done
|
|
if [[ "${found_files}" == "no" ]]; then
|
|
display_alert "calculate_hash_for_all_files_in_dirs" "skipped empty dir \"${dir}\"" "warn"
|
|
fi
|
|
done
|
|
|
|
#display_alert "calculate_hash_for_all_files_in_dirs" "files_to_hash_sorted: ${#files_to_hash_sorted[@]}" "warn"
|
|
#display_alert "calculate_hash_for_all_files_in_dirs" "files_to_hash_sorted: ${files_to_hash_sorted[*]}" "warn"
|
|
|
|
calculate_hash_for_files "${files_to_hash[@]}"
|
|
}
|
|
|
|
function calculate_hash_for_files() {
|
|
hash_files="undetermined" # outer scope
|
|
|
|
# relativize the files to SRC
|
|
declare -a files_to_hash=("$@")
|
|
declare -a files_to_hash_relativized=()
|
|
for file in "${files_to_hash[@]}"; do
|
|
# remove the SRC/ from the file name
|
|
file="${file#${SRC}/}"
|
|
files_to_hash_relativized+=("${file}")
|
|
done
|
|
|
|
# sort the array files_to_hash; use sort and readfile
|
|
declare -a files_to_hash_sorted
|
|
mapfile -t files_to_hash_sorted < <(for one in "${files_to_hash_relativized[@]}"; do echo "${one}"; done | LC_ALL=C sort -h) # "human" sorting
|
|
|
|
display_alert "calculate_hash_for_files:" "files_to_hash_sorted: ${files_to_hash_sorted[*]}" "debug"
|
|
declare full_hash
|
|
full_hash="$(cd "${SRC}" && sha256sum "${files_to_hash_sorted[@]}")"
|
|
hash_files="$(echo "${full_hash}" | sha256sum | cut -d' ' -f1)" # hash of hashes
|
|
hash_files="${hash_files:0:16}" # shorten it to 16 characters
|
|
display_alert "Hash for files:" "$hash_files" "warn"
|
|
display_alert "Full hash input for files:" "\n${full_hash}" "warn"
|
|
}
|