diff options
-rwxr-xr-x | modules/date | 6 | ||||
-rwxr-xr-x | modules/echo | 6 | ||||
-rwxr-xr-x | modules/espeak | 24 | ||||
-rwxr-xr-x | modules/help | 24 | ||||
-rwxr-xr-x | modules/lang | 22 | ||||
-rwxr-xr-x | modules/play | 32 | ||||
-rwxr-xr-x | modules/sleep | 10 | ||||
-rwxr-xr-x | modules/wall | 8 | ||||
-rwxr-xr-x | modules/zeit | 19 | ||||
-rwxr-xr-x | noise | 137 | ||||
-rwxr-xr-x | noise-as-shack | 4 | ||||
-rwxr-xr-x | noise-server | 4 |
12 files changed, 296 insertions, 0 deletions
diff --git a/modules/date b/modules/date new file mode 100755 index 00000000..8cd1b0c1 --- /dev/null +++ b/modules/date @@ -0,0 +1,6 @@ +#! /bin/sh +case "$1" in + (--help) : ;; + (*) + date --rfc-3339=s +esac diff --git a/modules/echo b/modules/echo new file mode 100755 index 00000000..344dd963 --- /dev/null +++ b/modules/echo @@ -0,0 +1,6 @@ +#! /bin/sh +case "$1" in + (--help) : ;; + (*) + echo "$*" +esac diff --git a/modules/espeak b/modules/espeak new file mode 100755 index 00000000..1f5c901d --- /dev/null +++ b/modules/espeak @@ -0,0 +1,24 @@ +#! /bin/sh + +print_var() { + echo "[35;4m$1[;35m = [32m$2[m" +} + +case "$1" in + (--help) echo say something with espeak ;; + (*) + p="${noise_pitch-100}" + v="${noise_lang-de}" + k="${noise_capital-0}" + a="${noise_amplitude-100}" + g="${noise_gap-1}" + print_var pitch $p + print_var lang $v + print_var capital $k + print_var amplitude $a + print_var gap $g + #echo "[31mespeak -p \"$pitch\" -v \"$lang\" \"$*\"[m" >&2 + espeak -a $a -k $k -p $p -v $v -g $g<<EOF +$* +EOF +esac diff --git a/modules/help b/modules/help new file mode 100755 index 00000000..48c06686 --- /dev/null +++ b/modules/help @@ -0,0 +1,24 @@ +#! /bin/sh +case "$1" in + (-*) : ;; # ignore all options + ('') { for directory in `echo "$NOISE_PATH" | tr : \ ` ; do + for module in "$directory"/* ; do + echo `basename "$module"` `$module --help` + done + done + ## print all documented built-in commands + sed -rn 's:^noise_([a-z]+)\(\) \{ # (.+)?$:\1 \2:p' "$NOISE" + } | sort | sed -rn ' + $s/$/[m/ + s:^([a-z]+) (.+):[35mtype [32m/\1[35m to \2:p' ;; + (*) + ## call + for directory in `echo "$NOISE_PATH" | tr : \ ` ; do + for module in "$directory/$1" ; do + if test -e $module ; then + shift + exec $module --help --verbose "$@" 2>&1 + fi + done + done +esac diff --git a/modules/lang b/modules/lang new file mode 100755 index 00000000..07b6802e --- /dev/null +++ b/modules/lang @@ -0,0 +1,22 @@ +#! /bin/sh + +case "$1" in + (--help) + echo "set language or list available languages" ;; + (list) + espeak --voices | sed -n '1!p' | awk '{\ + printf"[32m/lang %s [0;35mset [4mlang[0;35m to %s[m\n",$2,$4 + }' ;; + ('') + echo /set lang >$NOISE_linefeed ;; + (*) + if test -z "$2" ; then + echo /set lang "$1" + else + echo /set lang "$1" + shift + echo "$*" + echo /set lang "${noise_lang-de}" + fi >$NOISE_linefeed +esac + diff --git a/modules/play b/modules/play new file mode 100755 index 00000000..dcb8749f --- /dev/null +++ b/modules/play @@ -0,0 +1,32 @@ +#! /bin/sh +case "$1" in + (--help) + echo "play an audio file" ;; + (*) + exec 2>&1 + ffs='wav mp3 ogg asf flac' + + if test -z "$*" ; then + ls $HOME/noise/samples | sed -r ' + s:\.('"`echo "$ffs" | tr \ \|`"')$: [30m\1[m: + s:^:/play : + s:.*:[32m&[m: + ' + else + for i in $ffs ; do + f=$HOME/noise/samples/$1.$i + test -f "$f" && + case "$i" in + wav) aplay "$f" & ;; + *) mplayer "$f" & ;; + esac && break + done || cat<<EOF +[33m\ +Keine Audiodatei mit dem Namen [4m$1[;33m.EXT gefunden... \ +am besten gleich uploaden: +$ scp NAME $LOGNAME@shack:noise/samples/ + +folgende Dateiendungen werden erkannt: $ffs[m +EOF + fi +esac diff --git a/modules/sleep b/modules/sleep new file mode 100755 index 00000000..b8d350f7 --- /dev/null +++ b/modules/sleep @@ -0,0 +1,10 @@ +#! /bin/sh +case "$1" in + (--help) echo "pause for NUMBER seconds" ;; + (*) + if ! echo "$1" | grep -Eq '^([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)$' ; then + echo '[31;1mFAIL: $1 is not a number[m' + else + sleep "$1" + fi +esac diff --git a/modules/wall b/modules/wall new file mode 100755 index 00000000..7c32d01d --- /dev/null +++ b/modules/wall @@ -0,0 +1,8 @@ +#! /bin/sh +case "$1" in + (--help) : ;; + (?*) + for linefeed in /tmp/noise/*/linefeed ; do + echo /msg "$*" >$linefeed + done +esac diff --git a/modules/zeit b/modules/zeit new file mode 100755 index 00000000..4c41fa10 --- /dev/null +++ b/modules/zeit @@ -0,0 +1,19 @@ +#! /bin/sh + +case "$1" in + (--help) + echo "say current time" ;; + (*) + exec >>$NOISE_linefeed + k=`date +%k` + M=`date +%M|sed 's/0*//'` + echo /set pitch 10 + case "$lang" in + (de|'') echo "/espeak Es ist $k Uhr $M" ;; + (en|*-en) + test -z "$M" || M="and $M minutes" + echo "/espeak It is $k o clock $M" ;; + (*) echo "[31mError: unsupported [4mlang[0;31m = $lang[m" >&2 + esac + echo /set pitch ${noise_pitch-100} +esac 2>&1 @@ -0,0 +1,137 @@ +#! /bin/sh + +noise_set() { # set a variable + case "$1" in + (-q|--quiet) echo=: ; shift ;; + (*) echo=echo ;; + esac + case $# in + (0) ## print all noise variables + env | sed -rn ' + s/^noise_([[:alnum:]_]+)=(.*)$/[35;4m\1[;35m = [32m\2[m/p + ' | sort + ;; + (1) ## print value the specified variable + eval "echo \"[35;4m$1[0;35m = [0;32m\$noise_$1[m\"" + ;; + (*) ## set the specified variable + if echo "$1" | grep -q '[^[:alnum:]_]' ; then + fail invalid variable name "[4m$1" + return 23 + fi + eval "old=\"\$noise_$1\"" + if test "x$old" = "x$2" ; then + eval "$echo \"[35;4m$1[0;35m is already [0;32m$2[m\"" + elif test -z "$old" ; then + eval "export noise_$1='$2' ; $echo \ +\"[35;4m$1[0;35m set to [0;32m$2[m\"" + else + eval "export noise_$1='$2' ; $echo \ +\"[35;4m$1[0;35m changed from $old to [0;32m$2[m\"" + fi + ## write variable to $env + if grep -q "^$1=" "$env" ; then + sed -ri "s'^($1)=(.*)\$'\1=\'$2\''" $env + else + echo "$1='$2'" >>$env + fi + ;; + esac +} + +noise_quit() { # exit + echo "[35mGood bye![m" + exit +} + +fail() { + echo "[31mFAIL: $*[m" + return 23 +} + +cleanup() { + kill $jobs + rm -f $linefeed $env + rmdir /tmp/noise/$$ 2>/dev/null + rmdir /tmp/noise 2>/dev/null +} + + +qname="`readlink -f "$0"`" +dirname="`dirname "$qname"`" +export HOME='/home/shack' +if test -d "$dirname/modules" ; then + export NOISE_PATH="${NOISE_PATH+$NOISE_PATH:}$dirname/modules" + export NOISE_PATH="${NOISE_PATH+$NOISE_PATH:}$HOME/noise/modules" +fi +mkdir -vp /tmp/noise/$$ +linefeed="/tmp/noise/$$/linefeed" +env="/tmp/noise/$$/environment" +trap cleanup EXIT +mkfifo $linefeed +touch $env +## +## +## +readline() { + { read && echo "$REPLY" ; } | sed -rn " + s/[']//g + s/~%/\n/g + s/([^\\])([#<>])/\1\\\\\2/g + s:^/([a-z_]+)([[:space:]]+(.*))?$:command=\1; args='\3';:p;t + s@^([[:alnum:]_/+-]+):[[:space:]]*(.*)@command=lang; args='\1 \2';@p;t + s@^\![[:space:]]*(.*)@command=play; args='\1';@p;t + s:.*:command='$noise_default_command'; args='&';:p;t + " +} +## +## +## +while echo -n "$noise_prompt" && eval "`readline`" ; do + ## modcall + for dir in `echo "$NOISE_PATH" | tr : \ ` ; do + module="$dir/$command" + if test -x "$module" ; then + shift + eval 'NOISE="$0" NOISE_pid="$$" NOISE_linefeed="$linefeed" "$module"' "$args" + continue 2 + fi + done + ## funcall + if type noise_$command &>/dev/null ; then + eval 'noise_$command' "$args" + continue + fi + ## + fail unknown command "[4m$command[m" +done <$linefeed & +jobs="${jobs+$jobs }`jobs -p`" +## +## +## +cat<<EOF +[35mwelcome to [4mSHACK UTTERANCE[;35m version 0.9 beta 3 +get help with [32m/help[m +[33mTIP: benutze [4mrlwrap[;33m für eine elitäre Kommandozeile.[m +EOF +## +## +## +exec >>$linefeed +## +## +## +echo '/set prompt "[30mREADY.[m~%"' +echo '/set default_command espeak' +## +## +## +while read ; do + case $REPLY in + (/quit) echo /quit ; exit ;; + (*) tr \; \\n | grep . ;; + esac<<EOF +$REPLY +EOF +done +#### end of file. diff --git a/noise-as-shack b/noise-as-shack new file mode 100755 index 00000000..10ae3c1c --- /dev/null +++ b/noise-as-shack @@ -0,0 +1,4 @@ +#! /bin/sh +qname="`readlink -f "$0"`" +dirname="`dirname "$qname"`" +exec su - shack -c "env -i TCPREMOTEIP=\"$TCPREMOTEIP\" \"$dirname/noise\"" diff --git a/noise-server b/noise-server new file mode 100755 index 00000000..2012bbb5 --- /dev/null +++ b/noise-server @@ -0,0 +1,4 @@ +#! /bin/sh +qname="`readlink -f "$0"`" +dirname="`dirname "$qname"`" +exec tcpserver -c 423 -t 2 -D 0.0.0.0 23 "$dirname/noise-as-shack" |