diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-10-10 16:07:12 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-10-10 16:07:12 -0400 |
commit | 614f6cd4bf972b82ace294b8133122fdff5dc3a1 (patch) | |
tree | 779668e5dcdf7056be7d6acc392cf1163b90c27c /jh-checksource.sh | |
parent | 06d9a96e5b252d86418595dd1195a6f5ef69d462 (diff) |
add 'checksource' and 'mksource'
Diffstat (limited to 'jh-checksource.sh')
-rw-r--r-- | jh-checksource.sh | 40 |
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 |