summaryrefslogtreecommitdiff
path: root/jh-checksource.sh
diff options
context:
space:
mode:
Diffstat (limited to 'jh-checksource.sh')
-rw-r--r--jh-checksource.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/jh-checksource.sh b/jh-checksource.sh
new file mode 100644
index 0000000..b416427
--- /dev/null
+++ b/jh-checksource.sh
@@ -0,0 +1,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