1 |
commit: 9b2496f2a230e8f29feda04e141ccd574858cb24 |
2 |
Author: Ulrich Müller <ulm <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Feb 8 16:35:15 2014 +0000 |
4 |
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Feb 8 16:35:15 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/qa-scripts.git;a=commit;h=9b2496f2 |
7 |
|
8 |
New script to find binary files based on file -i magic. |
9 |
|
10 |
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org> |
11 |
|
12 |
--- |
13 |
find-binary-files.sh | 37 +++++++++++++++++++++++++++++++++++++ |
14 |
1 file changed, 37 insertions(+) |
15 |
|
16 |
diff --git a/find-binary-files.sh b/find-binary-files.sh |
17 |
new file mode 100755 |
18 |
index 0000000..17bdc0a |
19 |
--- /dev/null |
20 |
+++ b/find-binary-files.sh |
21 |
@@ -0,0 +1,37 @@ |
22 |
+#!/bin/bash |
23 |
+# Copyright 2014 Gentoo Foundation |
24 |
+# Distributed under the terms of the GNU GPL version 2 or later |
25 |
+# Author: Ulrich Müller <ulm@g.o> |
26 |
+ |
27 |
+shopt -s extglob |
28 |
+ |
29 |
+portdir=$(portageq get_repo_path / gentoo) |
30 |
+cd "${portdir}" || exit 1 |
31 |
+ |
32 |
+find . \( -path ./distfiles -o -path ./local -o -path ./metadata \) -prune \ |
33 |
+ -o ! -type d -exec file -ih '{}' + \ |
34 |
+| while read line; do |
35 |
+ path=${line%:*} |
36 |
+ type=${line##*:*( )} |
37 |
+ case ${type} in |
38 |
+ "application/octet-stream; charset=unknown" \ |
39 |
+ | "binary; charset=binary") |
40 |
+ # GNU Info files (or patches to them) can contain the following |
41 |
+ # control characters that produce false positives: |
42 |
+ # - 0x1f, followed by LF or FF |
43 |
+ # - 0x7f (DEL), preceded by "Node:" in the same line |
44 |
+ # Filter such characters and reiterate |
45 |
+ line=$(sed -e 's/\x1f\f\?$//;/Node:/s/\x7f//' "${path}" | file -i -) |
46 |
+ type=${line##*:*( )} |
47 |
+ ;; |
48 |
+ esac |
49 |
+ case ${type} in |
50 |
+ text/*) ;; # text file |
51 |
+ application/*"; charset=us-ascii") ;; |
52 |
+ application/*"; charset=utf-8") ;; |
53 |
+ "image/svg+xml; charset=us-ascii") ;; # SVG image |
54 |
+ "image/x-xpmi; charset=us-ascii") ;; # XPM image |
55 |
+ *) echo "${path#./}: ${type}" ;; |
56 |
+ esac |
57 |
+done \ |
58 |
+| sort |