]> git.draconx.ca Git - dxcommon.git/blob - t/md5.sh
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[dxcommon.git] / t / md5.sh
1 #!/bin/sh
2 #
3 # Copyright © 2021 Nick Bowler
4 #
5 # Fake md5sum-like program for testing the md5 detection macro.
6 #
7 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
8 # This is free software: you are free to do what the fuck you want to.
9 # There is NO WARRANTY, to the extent permitted by law.
10
11 : "${MD5_NO_R=}"
12 : "${MD5_HASH=d41d8cd98f00b204e9800998ecf8427e}"
13 : "${MD5_DIRECTION=forward}"
14
15 stdin=true
16
17 print_hash () {
18   case $MD5_DIRECTION in
19   forward) printf '%s  %s\n' "$MD5_HASH" "$1" ;;
20   reverse) printf '%s = %s\n' "$1" "$MD5_HASH" ;;
21   *) printf 'invalid direction %s\n' "$MD5_DIRECTION" 1>&2; exit 1 ;;
22   esac
23 }
24
25 for arg
26 do
27   case $arg in
28   -r)
29     test x"$MD5_NO_R" = x"" || exit
30     MD5_DIRECTION=forward
31     continue ;;
32   md5)
33     continue ;;
34   esac
35
36   stdin=false
37   print_hash $arg
38 done
39
40 if $stdin; then
41   cat >/dev/null
42   print_hash stdin
43 fi