From a13929a1e9b88d13fd5cc43f699cfb9c3dd71499 Mon Sep 17 00:00:00 2001 From: momo Date: Sat, 17 Sep 2011 16:59:54 +0200 Subject: //evan/satz-liste add 2 new sentences --- evan/satz-liste | 3 +++ 1 file changed, 3 insertions(+) diff --git a/evan/satz-liste b/evan/satz-liste index e14aaf78..44f84c13 100644 --- a/evan/satz-liste +++ b/evan/satz-liste @@ -12,3 +12,6 @@ bewässere die Pflanzen Öffne ein Fenster wische die tische Weniger Licht ist mehr +sammle pfandflaschen ein +zahle deinen mitgliedsbeitrag + -- cgit v1.2.3 From 5ac37243d06e87ee81bc8e51fa10bf5082fe2212 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 18 Sep 2011 15:36:46 +0200 Subject: //hyper/process/main.go: gofmtized --- hyper/process/main.go | 92 +++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/hyper/process/main.go b/hyper/process/main.go index 5420f681..214dade9 100644 --- a/hyper/process/main.go +++ b/hyper/process/main.go @@ -10,68 +10,68 @@ import "bytes" import "hyper/process" -var proc = map[string] *hyper.Process{} +var proc = map[string]*hyper.Process{} // TODO Retrieve Process, Write, Kill [autokill], get exit code func RespondJSON(res http.ResponseWriter, v interface{}) os.Error { - content, err := json.Marshal(v) - if err == nil { - log.Printf("< %s", content) - res.Header().Set("Content-Type", "application/json; charset=\"utf-8\"") - res.WriteHeader(http.StatusOK) - res.Write(content) - } else { - log.Printf("%s while json.Marshal(%s)", err, v) - } - return err + content, err := json.Marshal(v) + if err == nil { + log.Printf("< %s", content) + res.Header().Set("Content-Type", "application/json; charset=\"utf-8\"") + res.WriteHeader(http.StatusOK) + res.Write(content) + } else { + log.Printf("%s while json.Marshal(%s)", err, v) + } + return err } func CreateProcessHandler(res http.ResponseWriter, req *http.Request) { - if p, err := hyper.NewProcess(req); err == nil { - id := p.Id() - proc[id] = p - RespondJSON(res, &map[string]string{ - "path": fmt.Sprintf("/proc/%s", id), - }) - } else { - log.Printf("%s", err) - res.WriteHeader(http.StatusInternalServerError) - } + if p, err := hyper.NewProcess(req); err == nil { + id := p.Id() + proc[id] = p + RespondJSON(res, &map[string]string{ + "path": fmt.Sprintf("/proc/%s", id), + }) + } else { + log.Printf("%s", err) + res.WriteHeader(http.StatusInternalServerError) + } } func RetrieveProcess(res http.ResponseWriter, req *http.Request) { - if p := proc[mux.Vars(req)["id"]]; p != nil { - RespondJSON(res, p) - } else { - res.WriteHeader(http.StatusNotFound) - } + if p := proc[mux.Vars(req)["id"]]; p != nil { + RespondJSON(res, p) + } else { + res.WriteHeader(http.StatusNotFound) + } } func FeedProcess(res http.ResponseWriter, req *http.Request) { - if p := proc[mux.Vars(req)["id"]]; p != nil { - body := make([]byte, 4096) - if _, err := req.Body.Read(body); err == nil { - body = bytes.TrimRight(body, string([]byte{0})) - p.Write(body) - //if err := p.Write(body); err == nil { - RespondJSON(res, true) - //} - } - } else { - res.WriteHeader(http.StatusNotFound) - } + if p := proc[mux.Vars(req)["id"]]; p != nil { + body := make([]byte, 4096) + if _, err := req.Body.Read(body); err == nil { + body = bytes.TrimRight(body, string([]byte{0})) + p.Write(body) + //if err := p.Write(body); err == nil { + RespondJSON(res, true) + //} + } + } else { + res.WriteHeader(http.StatusNotFound) + } } func main() { - // Gorilla - mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST") - mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET") - mux.HandleFunc("/proc/{id}", FeedProcess).Methods("POST") + // Gorilla + mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST") + mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET") + mux.HandleFunc("/proc/{id}", FeedProcess).Methods("POST") - err := http.ListenAndServe("0.0.0.0:8888", mux.DefaultRouter) - if err != nil { - log.Fatal("ListenAndServe: ", err.String()) - } + err := http.ListenAndServe("0.0.0.0:8888", mux.DefaultRouter) + if err != nil { + log.Fatal("ListenAndServe: ", err.String()) + } } -- cgit v1.2.3 From dae3147e1bad4c57f7e492ab7df7a1679b4b2273 Mon Sep 17 00:00:00 2001 From: momo Date: Sun, 18 Sep 2011 19:51:53 +0200 Subject: //cholerab/news/Candidate: Add Information about the "Kommandozentrale" --- cholerab/news/Candidate | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cholerab/news/Candidate b/cholerab/news/Candidate index 1b52abe4..4d25b6c0 100644 --- a/cholerab/news/Candidate +++ b/cholerab/news/Candidate @@ -57,3 +57,10 @@ Ein Webinterface ist noch nicht geplant. Die Musiksammlung kann in incoming/Musik auf der Filebitch erweitert werden. ## 3. KNUT - Die Krebs Notification Utility Toolchain + + +## 4. Krebs Kommandozentrale + +Der 17" Monitor am Krebs sowie die auf dem Drucker liegende Tastatur wurden so modifiziert dass auf der ersten shell ein ncmpc Interface zu sehen ist, womit sich der MPD und somit auch die Loungebeschallung steuern lässt. Auf der 2. Shell (änderbar duch ctrl+alt+F2) befindet sich ein direktzugriff auf //noise, welcher es u.a. ermöglicht streams zu wechseln oder das licht ein/auszuschalten. + +Credits gehen an KM momo und KM tv -- cgit v1.2.3 From 820e9babae95ad58b26f25983a4fd3aaebd4ac65 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 18 Sep 2011 22:50:48 +0200 Subject: //util lgoinstall: initial commit This script tries to goinstall local/$(basename $PWD) --- util/bin/lgoinstall | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 util/bin/lgoinstall diff --git a/util/bin/lgoinstall b/util/bin/lgoinstall new file mode 100755 index 00000000..4cd0e852 --- /dev/null +++ b/util/bin/lgoinstall @@ -0,0 +1,125 @@ +#! /bin/sh +# +# usage: lgoinstall +# +# This script tries to goinstall $PWD +# +# target=local/$(basename $PWD) +# ensure there's a symlink local/$target somewhere in $GOROOT or $GOPATH +# goinstall local/$(dirname $PWD) +# +set -euf + +#fqtarget="$(readlink -f "$PWD")" +fqtarget="$PWD" +target="local/$(basename "$fqtarget")" + +# +# resolve PATH [relpath [FS]] # ====> abspath... +# +# Resolve relpath to abspath for each component x separated by FS in PATH +# where x/relpath is an existing file. +# +# relpath defaults to "" +# FS defaults to ":" +# +# Example: +# +# resolve "/bin:/usr/bin" sh # ====> /bin/sh +# +resolve() { + set -- "$1" "${2+/$2}" "${3-:}" "$IFS" + IFS="$3" + for i in $1; do + ! test -x "$i$2" || echo "$i$2" + done + unset i + IFS="$3" +} + +# +# xargstest TEST_ARGS... +# +# Read filenames from stdin and +# write each filename that satisfies test # $TEST_ARGS to stdout. +# +# Each %x in TEST_ARGS gets replaced by the readlink -f of the filename. +# +# Example: +# +# xargstest -d %x < /usr +# +xargstest() { + while read x; do + fqx="$(readlink -f "$x")" + if sub %x "$x" sub %fqx "$fqx" test "$@"; then + #if test "${@//%x/$fqx}"; then + echo "$x" + fi + done | grep . +} + +sub() { + sub1="$1" + sub2="$2" + shift 2 + set -- "${@//$sub1/$sub2}" + unset sub1 sub2 + "$@" +} + +path="${GOROOT-}${GOPATH+:$GOPATH}" + +# +# if there's a src/$target that points to $PWD, then succeed +# +if x="`resolve "$path" src/$target | xargstest "$fqtarget" = %fqx`" +then + echo "good $target: $x -> $PWD" >&2 + exec goinstall "$target" +fi + +# +# if there's some other src/$target then die +# +if x="`resolve "$path" src/$target | xargstest ! -x %x -o "$fqtarget" != %fqx`" +then + echo bad $target: $x >&2 + echo check your GOROOT and/or GOPATH or eliminate that $target >&2 + exit 23 +fi + +# +# if we've no Go-source in $PWD then die to prevent clobbering $GOPATH & co. +# +if ! ls | grep '\.go$'; then + echo "Your \$PWD seems to contain no Go-source... abort." >&2 + exit 23 +fi + +# +# if we can write to some src/local then symlink $PWD and retry +# +if x="`resolve "$path" src/local | xargstest -w %x`" +then + #echo writable src/local: $x + ln -vsnf $fqtarget $x + exec "$0" "$@" +fi + +# +# if we can write to some src then mkdir src/local and retry +# +if x="`resolve "$path" src | xargstest -w %x`" +then + #echo writable src: $x + mkdir "$x/local" + exec "$0" "$@" +fi + +echo "This script failed: good luck, you're on your own!" >&2 +exit 23 -- cgit v1.2.3 From bea490c675a6f6b5d40c4d6be86161dfc13a5f78 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 18 Sep 2011 23:02:15 +0200 Subject: //util lgoinstall: allow arbitrary directories --- util/bin/lgoinstall | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/util/bin/lgoinstall b/util/bin/lgoinstall index 4cd0e852..37ce6e16 100755 --- a/util/bin/lgoinstall +++ b/util/bin/lgoinstall @@ -1,17 +1,21 @@ #! /bin/sh # -# usage: lgoinstall +# usage: lgoinstall [path [OPTIONS...]] # -# This script tries to goinstall $PWD +# This script tries to goinstall ${OPTIONS...} local/$(basename $path) # -# target=local/$(basename $PWD) +# path defaults to $PWD +# +# target=local/$(basename $path) # ensure there's a symlink local/$target somewhere in $GOROOT or $GOPATH -# goinstall local/$(dirname $PWD) +# goinstall $target +# +# TODO use the same argument order as goinstall # set -euf #fqtarget="$(readlink -f "$PWD")" -fqtarget="$PWD" +fqtarget="$(cd "${1-$PWD}" && echo "$PWD")" target="local/$(basename "$fqtarget")" # @@ -75,12 +79,14 @@ sub() { path="${GOROOT-}${GOPATH+:$GOPATH}" # -# if there's a src/$target that points to $PWD, then succeed +# if there's a src/$target that points to $fqtarget, then succeed # if x="`resolve "$path" src/$target | xargstest "$fqtarget" = %fqx`" then - echo "good $target: $x -> $PWD" >&2 - exec goinstall "$target" + echo "good $target: $x -> $fqtarget" >&2 + shift # off $1 = $fqtarget + echo goinstall "$@" "$target" >&2 + exec goinstall "$@" "$target" fi # @@ -94,10 +100,10 @@ then fi # -# if we've no Go-source in $PWD then die to prevent clobbering $GOPATH & co. +# if we've no Go-source in $fqtarget then die to prevent clobbering $GOPATH. # if ! ls | grep '\.go$'; then - echo "Your \$PWD seems to contain no Go-source... abort." >&2 + echo "$1 seems to contain no Go-source... abort." >&2 exit 23 fi -- cgit v1.2.3 From 0a5e023f09d53a4bc784865005003768bf21b877 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 19 Sep 2011 00:20:53 +0200 Subject: //util nextpath: initial commit --- util/bin/nextpath | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 util/bin/nextpath diff --git a/util/bin/nextpath b/util/bin/nextpath new file mode 100755 index 00000000..fbffa894 --- /dev/null +++ b/util/bin/nextpath @@ -0,0 +1,12 @@ +#! /bin/sh +# +# nextpath [component...] +# +# echo $PATH with the components stripped +# +set -euf + +pattern="^\\(${1-}$(shift;for i; do echo -n "\\|$i"; done)\\)$" + +echo -n "$(echo -n "$PATH" | tr : '\n' | grep -v "$pattern")" | tr '\n' : +echo -- cgit v1.2.3 From e1089de23a7e3b316e0c06b4e60c7f6e05d8d5dd Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 02:17:23 +0200 Subject: //hyper/process/spawn: initial commit --- hyper/process/spawn | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 hyper/process/spawn diff --git a/hyper/process/spawn b/hyper/process/spawn new file mode 100755 index 00000000..a0043ec7 --- /dev/null +++ b/hyper/process/spawn @@ -0,0 +1,70 @@ +#! /bin/sh +# +# spawn [command [argument ...]] +# +spawn() { + set -euf + + # create and change working directory + wd=`mktemp -d` + defer rmdir $wd + cd $wd + + # create named pipes for the child process's stdio + mkfifo 0 1 2 + defer rm 0 1 2 + + # spawn child process + (exec 0>&- 1>&- 2>&- 0<>0 1<>1 2<>2 "$@") & + pid=$! + + # setup a trap to kill the child process if this (parent) process dies + defer kill $pid + + # write child process's pid + echo $pid >pid + defer rm pid + + # create dummy directory for easier debugging + mkdir -vp /tmp/dummy + ln -vsnf $wd/0 $wd/1 $wd/2 $wd/pid /tmp/dummy/ + defer rm -v /tmp/dummy/0 /tmp/dummy/1 /tmp/dummy/2 /tmp/dummy/pid + + # wait for the child process's + set +e + wait $pid + code=$? + set -e + + # the child is already dead + cancel kill $pid + + # return the same way wait did + (exit $code) +} + +# +# defer [command [argument ...]] +# +# Defer execution of a command. Deferred commands are executed in LIFO +# order immediately before the script terminates. See (golang's defer +# statement for more information how this should work). +# +defer() { + defer="$*${defer+ +$defer}" + trap "$defer" EXIT +} + +# +# cancel [command [argument ...]] +# +# Cancel a deferred command. The arguments have to match exactly a +# prior defer call or else chaos and mayhem shall haunt thee and shi- +# +cancel() { + defer="`echo "$defer" | grep -Fxv "$*"`" + trap "$defer" EXIT +} + +spawn "$@" -- cgit v1.2.3 From 08a6dc70d957912c864516ad705c7c724f363b73 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 03:05:14 +0200 Subject: //hyper/process/spawn: defer w/ dash-compat trap --- hyper/process/spawn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyper/process/spawn b/hyper/process/spawn index a0043ec7..c2b829ca 100755 --- a/hyper/process/spawn +++ b/hyper/process/spawn @@ -53,7 +53,6 @@ spawn() { defer() { defer="$*${defer+ $defer}" - trap "$defer" EXIT } # @@ -64,7 +63,8 @@ $defer}" # cancel() { defer="`echo "$defer" | grep -Fxv "$*"`" - trap "$defer" EXIT } +# setup deferred execution and spawn command +trap 'eval "${defer-}"; defer=' EXIT INT spawn "$@" -- cgit v1.2.3 From b3a318886407c98b3e91df9173c2d9c2cf195de3 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 15:09:19 +0200 Subject: //hyper spawn: use well known //proc dir this commit also spawns the command in the current $PWD so spawn ls & co. are viable commands. this commit also sets up a trap for TERM, so dash behaves nicely, again. also we now've got more documentation and debug output [if called with sh -x]. --- hyper/process/spawn | 58 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/hyper/process/spawn b/hyper/process/spawn index c2b829ca..95854c7d 100755 --- a/hyper/process/spawn +++ b/hyper/process/spawn @@ -1,34 +1,61 @@ #! /bin/sh # -# spawn [command [argument ...]] +# [sh -x] spawn [command [argument ...]] +# +# export id to create&destroy or reuse the working directory //proc/$id/. +# this feature is for debug only and marked as deprecated, so don't rely +# on it too hard. # spawn() { set -euf - # create and change working directory - wd=`mktemp -d` - defer rmdir $wd + # establish working subdirectory in //proc. we're mking only + # transient dirs, i.e. if we mkdir, then we also defer rmdir. + if test -n "${id-}"; then + : "using id=$id from env" + wd=$pd/$id + if ! test -d $wd; then + : "make transient $wd/" + mkdir $wd + defer rmdir $wd + elif ! test `ls $wd | wc -l` = 0; then + : "$wd/ is not empty!" + exit 23 + else + : "reuse existing $wd/" + fi + else + id=`cd $pd && mktemp -d XXXXXXXXXXXXXXXX` + wd=$pd/$id + defer rmdir $wd + : "made transient $wd/" + fi + + # change to //proc working directory + cwd="$PWD" cd $wd + #defer cd $cwd # no need for this, b/c at that time we're aldeady dead # create named pipes for the child process's stdio mkfifo 0 1 2 defer rm 0 1 2 # spawn child process - (exec 0>&- 1>&- 2>&- 0<>0 1<>1 2<>2 "$@") & + ( : "in $PWD/ spawn ${*-"nothing"}" + exec 0>&- 1>&- 2>&- 0<>0 1<>1 2<>2 + cd "$cwd" + exec "$@") & pid=$! # setup a trap to kill the child process if this (parent) process dies defer kill $pid - # write child process's pid + # store misc. info. + ln -snf $cwd cwd + echo $id >id + echo $$ >ppid echo $pid >pid - defer rm pid - - # create dummy directory for easier debugging - mkdir -vp /tmp/dummy - ln -vsnf $wd/0 $wd/1 $wd/2 $wd/pid /tmp/dummy/ - defer rm -v /tmp/dummy/0 /tmp/dummy/1 /tmp/dummy/2 /tmp/dummy/pid + defer rm cwd id pid ppid # wait for the child process's set +e @@ -65,6 +92,11 @@ cancel() { defer="`echo "$defer" | grep -Fxv "$*"`" } +# setup //proc directory +pd=/tmp/krebs/proc +mkdir -p $pd +test -w $pd + # setup deferred execution and spawn command -trap 'eval "${defer-}"; defer=' EXIT INT +trap 'eval "${defer-}"; defer=' EXIT INT TERM spawn "$@" -- cgit v1.2.3 From 549515312ac5442bb7b8984665e7a79aba862a3c Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 15:13:22 +0200 Subject: //hyper spawn: fix spawn-debug-output for dash --- hyper/process/spawn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyper/process/spawn b/hyper/process/spawn index 95854c7d..f800a1bb 100755 --- a/hyper/process/spawn +++ b/hyper/process/spawn @@ -41,7 +41,7 @@ spawn() { defer rm 0 1 2 # spawn child process - ( : "in $PWD/ spawn ${*-"nothing"}" + ( : "in $PWD/ spawn ${*:-"nothing"}" exec 0>&- 1>&- 2>&- 0<>0 1<>1 2<>2 cd "$cwd" exec "$@") & -- cgit v1.2.3 From fa1e71f1376a4983251821c6b74275dd4b726b4e Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 15:33:00 +0200 Subject: //process spawn: rm crufty "s --- hyper/process/spawn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyper/process/spawn b/hyper/process/spawn index f800a1bb..01ca2a04 100755 --- a/hyper/process/spawn +++ b/hyper/process/spawn @@ -41,7 +41,7 @@ spawn() { defer rm 0 1 2 # spawn child process - ( : "in $PWD/ spawn ${*:-"nothing"}" + ( : "in $PWD/ spawn ${*:-nothing}" exec 0>&- 1>&- 2>&- 0<>0 1<>1 2<>2 cd "$cwd" exec "$@") & -- cgit v1.2.3 From 8e30185619d6cdc8ec2cd5dd0f341ffabef2d563 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 15:37:26 +0200 Subject: //hyper spawn: defer cd, so Solaris's sh can rmdir --- hyper/process/spawn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyper/process/spawn b/hyper/process/spawn index 01ca2a04..cf93eb6b 100755 --- a/hyper/process/spawn +++ b/hyper/process/spawn @@ -34,7 +34,7 @@ spawn() { # change to //proc working directory cwd="$PWD" cd $wd - #defer cd $cwd # no need for this, b/c at that time we're aldeady dead + defer cd $cwd # create named pipes for the child process's stdio mkfifo 0 1 2 -- cgit v1.2.3 From fcbb481cbd888d6ab66b09e649c754a012198e53 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Sep 2011 15:45:30 +0200 Subject: //hyper spawn: set +x before rediring popes --- hyper/process/spawn | 1 + 1 file changed, 1 insertion(+) diff --git a/hyper/process/spawn b/hyper/process/spawn index cf93eb6b..65e94d86 100755 --- a/hyper/process/spawn +++ b/hyper/process/spawn @@ -42,6 +42,7 @@ spawn() { # spawn child process ( : "in $PWD/ spawn ${*:-nothing}" + set +x # disable debug output so we don't clobber 2 exec 0>&- 1>&- 2>&- 0<>0 1<>1 2<>2 cd "$cwd" exec "$@") & -- cgit v1.2.3