-
Notifications
You must be signed in to change notification settings - Fork 192
/
identify
executable file
·53 lines (46 loc) · 889 Bytes
/
identify
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
#!/bin/bash
set -o pipefail
help() {
echo >&2 "Usage: $0 path/to/libc.so"
echo >&2 " OR $0 bid=<BUILD_ID>"
echo >&2 " OR $0 md5=<MD5>"
echo >&2 " OR $0 sha1=<SHA1>"
echo >&2 " OR $0 sha256=<SHA256>"
exit 2
}
if [[ $# != 1 ]]; then
help
fi
arg="$1"
if [ -f "$arg" ]; then
libc="$(readlink -f "$arg")"
fi
cd "$(dirname "$0")"
if [[ -f "$libc" ]]; then
arg="sha1=$(sha1sum "$libc" | awk '{print $1}')"
fi
case "$arg" in
bid=*)
hash="${arg#"bid="}"
tool="file"
regex="=$hash,"
;;
md5=*)
hash="${arg#"md5="}"
tool="md5sum"
regex="$hash "
;;
sha1=*)
hash="${arg#"sha1="}"
tool="sha1sum"
regex="$hash "
;;
sha256=*)
hash="${arg#"sha256="}"
tool="sha256sum"
regex="$hash "
;;
*)
help
esac
ls -1 db/*.so | xargs $tool | grep -- "$regex" | perl -n -e '/([^\/: ]+)\.so/&&print "$1\n"'