diff options
author | tv <tv@iiso> | 2011-09-24 22:13:06 +0200 |
---|---|---|
committer | tv <tv@iiso> | 2011-09-24 22:13:06 +0200 |
commit | 6d052057793681d073b33d07ce007c8fcfb3b542 (patch) | |
tree | 3314041446bde3b5ba1f01e6522e3c03c289ad1d /util/bin | |
parent | e692ab13d032df6e8c96bf1ec840f366122dca1f (diff) |
//util magic: initial extract
Diffstat (limited to 'util/bin')
-rwxr-xr-x | util/bin/magic | 41 |
1 files changed, 41 insertions, 0 deletions
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 |