summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-09-20 17:19:25 +0200
committermakefu <github@syntax-fehler.de>2011-09-20 17:19:25 +0200
commit32ddd0b2dec60ac99e30e26819e4653ccc47690e (patch)
tree6745bd80ed8392f0165a026215268ca24d3ce5c5
parentdfadcd3b21d838c9d1bb8fc37304cec71e7517d8 (diff)
parentfcbb481cbd888d6ab66b09e649c754a012198e53 (diff)
Merge branch 'master' of github.com:krebscode/painload
-rw-r--r--cholerab/news/Candidate7
-rw-r--r--evan/satz-liste3
-rw-r--r--hyper/process/main.go92
-rwxr-xr-xhyper/process/spawn103
-rwxr-xr-xutil/bin/lgoinstall131
-rwxr-xr-xutil/bin/nextpath12
6 files changed, 302 insertions, 46 deletions
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
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
+
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())
+ }
}
diff --git a/hyper/process/spawn b/hyper/process/spawn
new file mode 100755
index 00000000..65e94d86
--- /dev/null
+++ b/hyper/process/spawn
@@ -0,0 +1,103 @@
+#! /bin/sh
+#
+# [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
+
+ # 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
+
+ # create named pipes for the child process's stdio
+ mkfifo 0 1 2
+ defer rm 0 1 2
+
+ # 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 "$@") &
+ pid=$!
+
+ # setup a trap to kill the child process if this (parent) process dies
+ defer kill $pid
+
+ # store misc. info.
+ ln -snf $cwd cwd
+ echo $id >id
+ echo $$ >ppid
+ echo $pid >pid
+ defer rm cwd id pid ppid
+
+ # 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}"
+}
+
+#
+# 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 "$*"`"
+}
+
+# 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 TERM
+spawn "$@"
diff --git a/util/bin/lgoinstall b/util/bin/lgoinstall
new file mode 100755
index 00000000..37ce6e16
--- /dev/null
+++ b/util/bin/lgoinstall
@@ -0,0 +1,131 @@
+#! /bin/sh
+#
+# usage: lgoinstall [path [OPTIONS...]]
+#
+# This script tries to goinstall ${OPTIONS...} local/$(basename $path)
+#
+# path defaults to $PWD
+#
+# target=local/$(basename $path)
+# ensure there's a symlink local/$target somewhere in $GOROOT or $GOPATH
+# goinstall $target
+#
+# TODO use the same argument order as goinstall
+#
+set -euf
+
+#fqtarget="$(readlink -f "$PWD")"
+fqtarget="$(cd "${1-$PWD}" && echo "$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 <<EOF
+# /bin/sh
+# /usr
+# EOF
+# # ====> /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 $fqtarget, then succeed
+#
+if x="`resolve "$path" src/$target | xargstest "$fqtarget" = %fqx`"
+then
+ echo "good $target: $x -> $fqtarget" >&2
+ shift # off $1 = $fqtarget
+ echo goinstall "$@" "$target" >&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 $fqtarget then die to prevent clobbering $GOPATH.
+#
+if ! ls | grep '\.go$'; then
+ echo "$1 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
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