blob: b416427bf5f1963a6f5a1f94e36c9b524d1bf10c (
plain)
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
|
#!/bin/bash
sep='<nofileevercontainsthis>'
resep='@'
safe_patterns=(
'.*text.*'
'(GIF|JPEG|PNG) image data.*'
)
safe_files=("$@")
unsafe_files="$(mktemp)"
find . -type f -exec file -F"$sep" {} + | while read line; do
file="$(echo "$line"|sed "s${resep}${sep}.*${resep}${resep}")"
type="$(echo "$line"|sed "s${resep}.*${sep}\s*${resep}${resep}")"
safe=false
for filename in "${safe_files[@]}"; do
if [[ $file = "$filename" ]]; then
safe=true;
fi
done
for pattern in "${safe_patterns[@]}"; do
if [[ $type ~= "$pattern" ]]; then
safe=true;
fi
done
if ! $safe; then
printf "%s\n" "$file"
fi
done > "$unsafe_files"
if [[ -n "$(cat "$unsafe_files")" ]]; then
echo " ==> The source directory `pwd` contains binary files:"
sed 's/./ ->/' "$unsafe_files"
rm -f "$unsafe_files"
exit 1
else
rm -f "$unsafe_files"
fi
|