blob: ef3cf47d05fb123ea9c2357ba4e8e81286e9b38d (
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
41
42
43
44
45
|
#!/bin/bash
sep='<nofileevercontainsthis>'
resep='@'
safe_types=(
'.*text.*'
'(GIF|JPEG|PNG) image data.*'
)
safe_files=("$@")
unsafe_files="$(mktemp)"
safevar="$(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}")"
echo false > "$safevar"
if [[ "$file" =~ ".*/\.git/.*" ]]; then
echo true > "$safevar"
fi
for filename in "${safe_files[@]}"; do
if [[ "$file" = "$filename" ]]; then
echo true > "$safevar"
fi
done
for filetype in "${safe_types[@]}"; do
if [[ "$type" =~ "$filetype" ]]; then
echo true > "$safevar"
fi
done
if [[ "$(cat "$safevar")" = 'true' ]]; then
printf "%s\n" "$file"
fi
done > "$unsafe_files"
rm -f "$safevar"
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
|