summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-10-10 16:07:12 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-10-10 16:07:12 -0400
commit614f6cd4bf972b82ace294b8133122fdff5dc3a1 (patch)
tree779668e5dcdf7056be7d6acc392cf1163b90c27c
parent06d9a96e5b252d86418595dd1195a6f5ef69d462 (diff)
add 'checksource' and 'mksource'
-rw-r--r--Makefile2
-rw-r--r--jh-checksource.help.txt4
-rw-r--r--jh-checksource.sh40
-rw-r--r--jh-mksource.help.txt2
-rw-r--r--jh-mksource.sh10
5 files changed, 57 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 7499ef0..e1de0a3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-subcommands = help list-commands mvn-basename mvn-install mvn-localrepo
+subcommands = help list-commands mvn-basename mvn-install mvn-localrepo mksource checksource
dirs = $(DESTDIR)/usr/share/jh $(DESTDIR)/usr/bin
####
diff --git a/jh-checksource.help.txt b/jh-checksource.help.txt
new file mode 100644
index 0000000..cf718dc
--- /dev/null
+++ b/jh-checksource.help.txt
@@ -0,0 +1,4 @@
+Usage @cmd@ checksource [ignore-file-list...]
+Checks the current (source) folder for binary files.
+
+Ignores any filename matching an argument.
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
diff --git a/jh-mksource.help.txt b/jh-mksource.help.txt
new file mode 100644
index 0000000..dba0cc1
--- /dev/null
+++ b/jh-mksource.help.txt
@@ -0,0 +1,2 @@
+Usage: eval `@cmd@ mksource [ignore-file-list...]`
+Prints shell code that 1) runs mksource() 2) runs `@cmd@ checksource`
diff --git a/jh-mksource.sh b/jh-mksource.sh
new file mode 100644
index 0000000..c40a739
--- /dev/null
+++ b/jh-mksource.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+quote_args() {
+ for arg in "$@"; do
+ quote "$arg"
+ printf ' '
+ done
+}
+
+echo "type mksource &>/dev/null && mksource; jh checksource $(quote_args "$@")"