/
md5
executable file
·64 lines (54 loc) · 1.24 KB
/
md5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
variable_is_nonempty()
{
typeset _variable
_variable="${1:-}"
if [[ -n "${_variable}" ]]
then
eval "[[ -n \"\${${_variable}:-}\" ]]" || return $?
else
fail "Cannot check if variable is nonempty; no variable was given."
fi
}
command_exists()
{
typeset _name
_name="${1:-}"
if variable_is_nonempty _name
then
builtin command -v "${_name}" > /dev/null 2>&1 || return 1
else
fail "Cannot test if command exists; no command name was given."
fi
}
if (( ${rvm_trace_flag:=0} == 2 ))
then
set -x
export rvm_trace_flag
fi
_archive="${1}"
shift || fail "archive name not given in first param"
md5="${1}"
shift || fail "md5 value not given in second param"
# Swiped from BDSM
if command_exists md5
then
archive_md5=$(md5 -q "${_archive}")
elif command_exists md5sum
then
archive_md5="$(md5sum "${_archive}")"
archive_md5="${archive_md5%% *}"
else
for _path in /usr/gnu/bin /sbin /bin /usr/bin /usr/sbin
do
if [[ -x "${_path}/md5" ]]
then
archive_md5=$(${_path}/md5 -q "${_archive}")
elif [[ -x "${_path}/md5sum" ]]
then
archive_md5="$(${_path}/md5sum "${_archive}")"
archive_md5="${archive_md5%% *}"
fi
done
fi
[[ "${archive_md5}" == "${md5}" ]] || exit $?