From 6d052057793681d073b33d07ce007c8fcfb3b542 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Sep 2011 22:13:06 +0200 Subject: //util magic: initial extract --- util/bin/magic | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 util/bin/magic (limited to 'util/bin/magic') diff --git a/util/bin/magic b/util/bin/magic new file mode 100755 index 00000000..04a7017d --- /dev/null +++ b/util/bin/magic @@ -0,0 +1,41 @@ +#! /bin/sh +# +# magic $name $command $file < $content +# + +name="$1"; shift +command="$1"; shift +file="$1"; shift + +bs="# begin krebs magic${name+ <$name>}" +es="# end krebs magic${name+ <$name>}" + +case $1 in + (print) + echo "$bs" + cat + echo "$es" + ;; + (create) + $0 has || $0 print >> $file < /dev/null + $0 replace + ;; + (destroy) + if $0 has; then + cache"`cat $file`" + echo "$cache" | sed "/^$bs$/,/^$es$/d" > $file + fi + ;; + (has) + grep -q "^$bs\$" $file && grep -q "^$es\$" $file + ;; + (replace) + $0 destroy && $0 create + ;; + (clear) + $0 replace < /dev/null + ;; + (*) + echo 'Error 1: You are made of stupid!' >&2 + exit 23 +esac -- cgit v1.2.3