diff options
Diffstat (limited to '')
-rw-r--r-- | %HOME%/.bash_utils/distr.sh | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh index ba92031..799f52f 100644 --- a/%HOME%/.bash_utils/distr.sh +++ b/%HOME%/.bash_utils/distr.sh @@ -20,11 +20,9 @@ sums_list_paths() ( echo "usage: ${FUNCNAME[0]} [-h|--help] [-0|-z]" return 0 ;; - -0|-z) fmt='%s\0' ;; - *) echo "${FUNCNAME[0]}: unrecognized parameter: $key" >&2 return 1 @@ -34,29 +32,38 @@ sums_list_paths() ( [ -f "$sums_path" ] || return 0 + local -a paths=() + local path while IFS= read -r path; do - printf "$fmt" "$path" - done < <( sed --binary 's/^\\\?[[:alnum:]]\+ [ *]//' "$sums_path" ) + paths+=("$path") + done < <( sed --binary -- 's/^\\\?[[:alnum:]]\+ [ *]//' "$sums_path" ) + + [ "${#paths[@]}" -eq 0 ] && return 0 + + printf -- "$fmt" ${paths[@]+"${paths[@]}"} ) sums_update() ( set -o errexit -o nounset -o pipefail + local -A existing + local -a missing=() + local path - local -A existing while IFS= read -d '' -r path; do existing[$path]=1 done < <( sums_list_paths -z ) - local -a missing for path in "$@"; do if [ -z "${existing[$path]+x}" ]; then missing+=("$path") fi done + [ "${#missing[@]}" -eq 0 ] && return 0 + sha1sum -- ${missing[@]+"${missing[@]}"} >> "$sums_path" ) |