]> arthur.barton.de Git - bup.git/commitdiff
dev/checksum: paper over platform differences
authorRob Browning <rlb@defaultvalue.org>
Sun, 16 May 2021 02:14:24 +0000 (21:14 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 16 May 2021 16:43:08 +0000 (11:43 -0500)
Replace use of sha1sum with dev/checksum in order to accommodate
platform differences, i.e. coreutils sha1sum vs freebsd sha1.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
dev/checksum [new file with mode: 0755]
dev/prep-for-freebsd-build
test/ext/test-misc
test/ext/test-save-smaller

diff --git a/dev/checksum b/dev/checksum
new file mode 100755 (executable)
index 0000000..dc6fbee
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/env bash
+
+set -ueo pipefail
+
+usage() { echo "Usage: checksum -t <sha1|sha256> [--] [PATH]"; }
+
+misuse() { usage 1>&2; exit 2; }
+
+kind=''
+while test $# -gt 0; do
+    case "$1" in
+        --)
+            shift
+            break
+            ;;
+        -t)
+            shift
+            test $# -gt 0 || misuse
+            kind="$1"
+            case "$kind" in
+                sha1|sha256) ;;
+                *) misuse ;;
+            esac
+            shift
+            ;;
+        -*)
+            misuse ;;
+        *)
+            break ;;
+    esac
+done
+
+test "$kind" || misuse
+
+src=/dev/stdin
+case $# in
+    0) ;;
+    1) src="$1" ;;
+    *) misuse ;;
+esac
+
+# Use KINDsum if available, else KIND (e.g. sha1sum or sha1).  Assumes
+# the former is compatible with the coreutils version, and the latter
+# is compatible with the FreeBSD version.
+
+if command -v "$kind"sum > /dev/null; then
+    result=$("$kind"sum "$src")
+    echo "${result%% *}"
+elif command -v "$kind" > /dev/null; then
+    "$kind" -q "$src"
+else
+    echo "Can't find sha1sum or sha1" 1>&2
+    exit 2
+fi
index d9449074a945e0703ec7e20d1c8c9fbd11bd3b2b..9631b412cf2d284027f17db4cc2322881899769f 100755 (executable)
@@ -16,7 +16,7 @@ pkg update
 # https://reviews.freebsd.org/D24816
 pkg install rdiff-backup || true
 
-pkgs='gmake git bash coreutils rsync curl par2cmdline readline duplicity'
+pkgs='gmake git bash rsync curl par2cmdline readline duplicity'
 pkgs="$pkgs rsnapshot"
 
 case "$pyver" in
index 7a7e4ce4f32eb7b8ece0badc4b573f1afe928407..34d65eb5d657658bf90bf150719a169cbb1c5f33 100755 (executable)
@@ -10,6 +10,7 @@ tmpdir="$(WVPASS wvmktempdir)" || exit $?
 export BUP_DIR="$tmpdir/bup"
 
 bup() { "$top/bup" "$@"; }
+sha1sum() { "$top/dev/checksum" -t sha1 "$@"; }
 
 WVPASS cd "$tmpdir"
 
index 1f497b706c04a7b8ca929f9c7e1c4600a30c9d09..d7ebfc6a3641ac6e9f8cc929704fae76e70f49ba 100755 (executable)
@@ -10,6 +10,7 @@ tmpdir="$(WVPASS wvmktempdir)" || exit $?
 export BUP_DIR="$tmpdir/bup"
 
 bup() { "$top/bup" "$@"; }
+sha1sum() { "$top/dev/checksum" -t sha1 "$@"; }
 
 WVPASS cd "$tmpdir"