aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-07 20:02:24 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-07 20:02:24 +0300
commit0c7657bf0bd41f741802ae8e8dedbaac867b671e (patch)
tree09042b99f8847fc724fe83592be3b24c1f32202c /%HOME%/.bash_utils
parentREADME update (diff)
downloadlinux-home-0c7657bf0bd41f741802ae8e8dedbaac867b671e.tar.gz
linux-home-0c7657bf0bd41f741802ae8e8dedbaac867b671e.zip
update_checksums: don't recalculate existing
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/distr.sh35
1 files changed, 31 insertions, 4 deletions
diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh
index 06d342a..58e088a 100644
--- a/%HOME%/.bash_utils/distr.sh
+++ b/%HOME%/.bash_utils/distr.sh
@@ -7,9 +7,36 @@
checksums_path='sha1sums.txt'
-update_checksums() {
- sha1sum -- "$@" > "$checksums_path"
-}
+list_checksums_paths() (
+ set -o errexit -o nounset -o pipefail
+
+ if [ -f "$checksums_path" ]; then
+ local path
+ while IFS= read -r path; do
+ printf "$path"'\0'
+ done < <( sed --binary 's/^\\\?[[:alnum:]]\+ [ *]//' "$checksums_path" )
+ fi
+)
+
+update_checksums() (
+ set -o errexit -o nounset -o pipefail
+
+ local path
+
+ local -A existing
+ while IFS= read -d '' -r path; do
+ existing[$path]=1
+ done < <( list_checksums_paths )
+
+ local -a missing
+ for path in "$@"; do
+ if [ -z "${existing[$path]+x}" ]; then
+ missing+=("$path")
+ fi
+ done
+
+ sha1sum -- "${missing[@]+"${missing[@]}"}" >> "$checksums_path"
+)
update_checksums_distr() (
set -o errexit -o nounset -o pipefail
@@ -19,7 +46,7 @@ update_checksums_distr() (
while IFS= read -d '' -r path; do
paths+=("$path")
- done < <( find . -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -print0 )
+ done < <( find . -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -printf '%P\0' )
update_checksums "${paths[@]+"${paths[@]}"}"
)