From 17ffe40523144a60d4297cfb18c3b5fdaffa84af Mon Sep 17 00:00:00 2001 From: euer Date: Thu, 20 Dec 2012 15:53:41 +0100 Subject: //{hyper,json} -> //sandbox //{icecrab,kachelmann,meinsack} -> //god //host -> //punani/host --- god/icecrab/Makefile | 6 + god/icecrab/icecast.xml | 174 +++++++++++++++++++++ god/icecrab/icecast2.conf | 19 +++ god/kachelmann/.gitignore | 2 + god/kachelmann/Makefile | 7 + god/kachelmann/wetter | 6 + god/meinsack/index | 85 ++++++++++ host/dist/arch/getsize | 17 -- hyper/README.md | 36 ----- hyper/influx/http/index.js | 57 ------- hyper/process/Makefile | 19 --- hyper/process/main.go | 77 --------- hyper/process/spawn | 103 ------------ hyper/process/src/hyper/process/Makefile | 11 -- hyper/process/src/hyper/process/process.go | 132 ---------------- hyper/process/test/bc.json | 11 -- hyper/sink/index.js | 13 -- icecrab/Makefile | 6 - icecrab/icecast.xml | 174 --------------------- icecrab/icecast2.conf | 19 --- json/sh/json.sh | 116 -------------- json/sh/test.json | 7 - kachelmann/.gitignore | 2 - kachelmann/Makefile | 7 - kachelmann/wetter | 6 - meinsack/index | 85 ---------- punani/host/dist/arch/getsize | 17 ++ sandbox/hyper/README.md | 36 +++++ sandbox/hyper/influx/http/index.js | 57 +++++++ sandbox/hyper/process/Makefile | 19 +++ sandbox/hyper/process/main.go | 77 +++++++++ sandbox/hyper/process/spawn | 103 ++++++++++++ sandbox/hyper/process/src/hyper/process/Makefile | 11 ++ sandbox/hyper/process/src/hyper/process/process.go | 132 ++++++++++++++++ sandbox/hyper/process/test/bc.json | 11 ++ sandbox/hyper/sink/index.js | 13 ++ sandbox/json/sh/json.sh | 116 ++++++++++++++ sandbox/json/sh/test.json | 7 + 38 files changed, 898 insertions(+), 898 deletions(-) create mode 100644 god/icecrab/Makefile create mode 100644 god/icecrab/icecast.xml create mode 100644 god/icecrab/icecast2.conf create mode 100644 god/kachelmann/.gitignore create mode 100644 god/kachelmann/Makefile create mode 100755 god/kachelmann/wetter create mode 100755 god/meinsack/index delete mode 100755 host/dist/arch/getsize delete mode 100644 hyper/README.md delete mode 100755 hyper/influx/http/index.js delete mode 100644 hyper/process/Makefile delete mode 100644 hyper/process/main.go delete mode 100755 hyper/process/spawn delete mode 100644 hyper/process/src/hyper/process/Makefile delete mode 100644 hyper/process/src/hyper/process/process.go delete mode 100644 hyper/process/test/bc.json delete mode 100644 hyper/sink/index.js delete mode 100644 icecrab/Makefile delete mode 100644 icecrab/icecast.xml delete mode 100644 icecrab/icecast2.conf delete mode 100755 json/sh/json.sh delete mode 100644 json/sh/test.json delete mode 100644 kachelmann/.gitignore delete mode 100644 kachelmann/Makefile delete mode 100755 kachelmann/wetter delete mode 100755 meinsack/index create mode 100755 punani/host/dist/arch/getsize create mode 100644 sandbox/hyper/README.md create mode 100755 sandbox/hyper/influx/http/index.js create mode 100644 sandbox/hyper/process/Makefile create mode 100644 sandbox/hyper/process/main.go create mode 100755 sandbox/hyper/process/spawn create mode 100644 sandbox/hyper/process/src/hyper/process/Makefile create mode 100644 sandbox/hyper/process/src/hyper/process/process.go create mode 100644 sandbox/hyper/process/test/bc.json create mode 100644 sandbox/hyper/sink/index.js create mode 100755 sandbox/json/sh/json.sh create mode 100644 sandbox/json/sh/test.json diff --git a/god/icecrab/Makefile b/god/icecrab/Makefile new file mode 100644 index 00000000..36e91b76 --- /dev/null +++ b/god/icecrab/Makefile @@ -0,0 +1,6 @@ +.phony: debian + +debian: + [ -e /usr/bin/icecast2 ] || apt-get install --yes icecast2 + cp icecast2 /etc/default/icecast2 + cp icecast.xml /etc/icecast2/icecast.xml diff --git a/god/icecrab/icecast.xml b/god/icecrab/icecast.xml new file mode 100644 index 00000000..7776dc36 --- /dev/null +++ b/god/icecrab/icecast.xml @@ -0,0 +1,174 @@ + + + 100 + 2 + 5 + 524288 + 30 + 15 + 10 + + 1 + + 65535 + + + + + shackit + + shackit + + + admin + aidsballs + + + + + + + + + krebs.shack + + + + 8000 + + + + + + + + + + + + + + + + + + 1 + + + + /usr/share/icecast2 + + + /var/log/icecast2 + /usr/share/icecast2/web + /usr/share/icecast2/admin + + + + + + + + + + access.log + error.log + + 3 + 10000 + + + + + + 0 + + + diff --git a/god/icecrab/icecast2.conf b/god/icecrab/icecast2.conf new file mode 100644 index 00000000..3a2521ff --- /dev/null +++ b/god/icecrab/icecast2.conf @@ -0,0 +1,19 @@ +# Defaults for icecast2 initscript +# sourced by /etc/init.d/icecast2 +# installed at /etc/default/icecast2 by the maintainer scripts + +# +# This is a POSIX shell fragment +# + +# Full path to the server configuration file +CONFIGFILE="/etc/icecast2/icecast.xml" + +# Name or ID of the user and group the daemon should run under +USERID=icecast2 +GROUPID=icecast + +# Edit /etc/icecast2/icecast.xml and change at least the passwords. +# Change this to true when done to enable the init.d script +ENABLE=true + diff --git a/god/kachelmann/.gitignore b/god/kachelmann/.gitignore new file mode 100644 index 00000000..050dfb2e --- /dev/null +++ b/god/kachelmann/.gitignore @@ -0,0 +1,2 @@ +conditions.pl +.*.swp diff --git a/god/kachelmann/Makefile b/god/kachelmann/Makefile new file mode 100644 index 00000000..3343d941 --- /dev/null +++ b/god/kachelmann/Makefile @@ -0,0 +1,7 @@ +.PHONY: infect +install: + # punani -Ei w3m php php-xml-simple + ln -s $$PWD/conditions ../bin/conditions + ln -s $$PWD/wetter ../bin/wetter + ln -s ${INSTALL_DIR}conditions ${INSTALL_DIR}kachelmann + diff --git a/god/kachelmann/wetter b/god/kachelmann/wetter new file mode 100755 index 00000000..957e13e2 --- /dev/null +++ b/god/kachelmann/wetter @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use XML::Simple; +my $result = `w3m -dump "http://www.google.com/ig/api?weather=70327-stuttgart&hl=de"`; +my $xml = new XML::Simple; +my $data = $xml->XMLin($result); +print ("$data->{weather}->{current_conditions}->{condition}->{data} bei $data->{weather}->{current_conditions}->{temp_c}->{data} Grad Zelsius\n"); diff --git a/god/meinsack/index b/god/meinsack/index new file mode 100755 index 00000000..7046d78c --- /dev/null +++ b/god/meinsack/index @@ -0,0 +1,85 @@ +#! /bin/sh +# +# //meinsack +# +# export plz +# export str +# export anr +# export ort +# +set -euf +cd $(dirname $(readlink -f $0))/.. # cd // + +plz=${plz+"&plz=$plz"} +str=${str+"&str=$str"} +anr=${anr+"&anr=$anr"} + +url="http://www.sita-deutschland.de/sita/ywbase_Abfallkalender_Stuttgart.nsf/frmSelect?ReadForm$plz$str$anr" + +# echo $url + +html="$(curl -fsS "$url" | iconv -f latin1 -t utf8)" + +if echo "$html" | fgrep -q 'Ihre Eingabe war nicht eindeutig'; then + { + echo "Error: multiple locations found" + echo "$html" | + query/jquery/index 'table.tab:nth-child(2n) .bordertop > .text' | + sed ' + s/[[:space:]]\+/ /g + s/'"`printf '\xc2\xa0'`"'//g;# kill unicode non-breaking space + ' | + while read plz && + read str && + read ort && + read bes1 && + read bes2 && + read anr; do + str=$(echo "$str"|sed 's/<[^>]*>//g') + echo "export anr=$anr if you meant \"$ort\"" + done | sort | uniq + } >&2 + exit 2 +elif test $(echo "$html" | grep -c 'Abfallkalender für') -gt 1 && + test -z "${ort-}"; then + { + echo "Error: multiple locations found" + echo "$html" | + query/jquery/index '.tab span.text,.subheadline' | + sed -n ' + s/[[:space:]]\+/ /g + s/'"`printf '\xc2\xa0'`"'//g;# kill unicode non-breaking space + s/^Abfallkalender.*[^0-9]\([0-9]\+\)[^(]*(\(.*\))/export ort=\2/p + ' | sort | uniq + } >&2 + exit 3 +else + result="$(echo "$html" | + query/jquery/index '.tab span.text,.subheadline' | { + if test -n "${ort-}"; then + sed -n " + /($ort)/,/^Abfallkalender/{p;b} + /($ort)/,\${p;b} + " + else + cat + fi + } | { + grep -v Abfallkalender | + sed ' + s/'"`printf '\xc2\xa0'`"'//g;# kill unicode non-breaking space + s/^[A-Z][a-z]\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\3-\2-\1/ + s/^[0-9].*/ "&T00:00:00.000Z"/ + $!s/$/,/ + 1s/^/[\n/ + $s/$/\n]/ + ' + })" + if ! echo "$result" | grep .; then + { + echo "Error: your query had no effect" + echo "url=\"$url\"" + } >&2 + exit 4 + fi +fi diff --git a/host/dist/arch/getsize b/host/dist/arch/getsize deleted file mode 100755 index a2ef8f95..00000000 --- a/host/dist/arch/getsize +++ /dev/null @@ -1,17 +0,0 @@ -#! /bin/sh -set -euf -sed -n ' - /^Name/{ - s/^Name *: *\(.*\)$/\1/ - T - h - } - /^Installed Size/{ - s/^Installed Size *: *\(.*\)$/ \1/ - T - H - x - s/\n//g - p - } -' | awk '{print$2$3" "$1}' | sort -n diff --git a/hyper/README.md b/hyper/README.md deleted file mode 100644 index d8fe9d67..00000000 --- a/hyper/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Overview - -## start conductor on port 8888 and sink on 1337 - - //hyper/process/main - //bin/node //hyper/sink - -## create bc process and retrieve it's process id (AKA {path}) - - url=http://localhost:8888 - curl -fvsS --data-binary @//hyper/process/test/bc.json $url/proc - -## send data for calculation - - echo 9000+2^42 | curl -fvsS --data-binary @- $url/{path} - -## spawn process with http influx and local efflux - -hint: maybe run each command in some separate terminal. - - id=dummy sh -x //hyper/process/spawn stdbuf -o 0 sed 's/[^0-9 ]//g' - port=3 node //hyper/influx/http //proc/dummy/0 - cat //proc/dummy/1 - cat //proc/dummy/2 - date | curl -fvsS --data-binary @- http://localhost:3 - -## calculate the square of the current year in a little local hyper sewer system - -hint: maybe run each command in some separate terminal. - - id=sqr sh -x //hyper/process/spawn stdbuf -o 0 sed 's/[^0-9]//g;s/.*/(&)^2/' - id=bc sh -x //hyper/process/spawn bc - port=42 node //hyper/influx/http //proc/sqr/0 - cat //proc/sqr/1 > //proc/bc/0 - cat //proc/bc/1 - date +%Y | curl -fvsS --data-binary @- http://localhost:42 diff --git a/hyper/influx/http/index.js b/hyper/influx/http/index.js deleted file mode 100755 index 346dde3b..00000000 --- a/hyper/influx/http/index.js +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env node - -name = '//hyper/influx/http' -port = process.env.port || 1337 -host = process.env.host || '127.0.0.1' - - -console.info(name); - -fs = require('fs'); -path = require('path'); -http = require('http'); - -fifo_path = path.resolve(process.argv[2] || path.join(process.cwd(), '0')); - -// check configuration -try { - (function (stat) { - if ((stat.mode & 0010000) === 0) { - throw { code: 'E_not_fifo', path: fifo_path }; - }; - })(fs.statSync(fifo_path)); -} catch (exn) { - console.error(exn); - process.exit(23); -}; - -process.stdin.destroy(); -fifo = fs.createWriteStream(fifo_path); -fifo.on('open', function (fd) { - console.info('fifo open as fd', fd); - - http.createServer(function (req, res) { - var rhost = req.connection.remoteAddress; - var rport = req.connection.remotePort; - var id = rhost + ':' + rport; - - console.info(id, 'request', req.method, req.url); - - req.on('data', function (data) { - console.info(id, 'data', data.length); - }); - - req.on('end', function (data) { - console.info(id, 'end'); - res.writeHead(202, { - 'Content-Length': 0, - 'Connection': 'close' - }); - res.end(); - }); - - req.pipe(fifo, { end: false }); - }).listen(port, host, function () { - console.info('server running at http://' + host + ':' + port + '/'); - }); -}); diff --git a/hyper/process/Makefile b/hyper/process/Makefile deleted file mode 100644 index bbc1c2fb..00000000 --- a/hyper/process/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include $(GOROOT)/src/Make.inc - -GCIMPORTS = -I pkg/$(GOOS)_$(GOARCH) -LDIMPORTS = -L pkg/$(GOOS)_$(GOARCH) - -TARG=main -GOFILES=\ - main.go\ - -include $(GOROOT)/src/Make.cmd - -export GOPATH := $(PWD) -.PHONY: prepare -prepare: - #goinstall -v github.com/garyburd/twister/server - goinstall -v gorilla.googlecode.com/hg/gorilla/mux - goinstall -v $(PWD)/src/hyper/process - -_go_.$O: prepare diff --git a/hyper/process/main.go b/hyper/process/main.go deleted file mode 100644 index 214dade9..00000000 --- a/hyper/process/main.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import "json" -import "log" -import "http" -import "gorilla.googlecode.com/hg/gorilla/mux" -import "os" -import "fmt" -import "bytes" - -import "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 -} - -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) - } -} - -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) - } -} - -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) - } -} - -func main() { - - // 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()) - } -} diff --git a/hyper/process/spawn b/hyper/process/spawn deleted file mode 100755 index 65e94d86..00000000 --- a/hyper/process/spawn +++ /dev/null @@ -1,103 +0,0 @@ -#! /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/hyper/process/src/hyper/process/Makefile b/hyper/process/src/hyper/process/Makefile deleted file mode 100644 index 7ecda716..00000000 --- a/hyper/process/src/hyper/process/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ${GOROOT}/src/Make.inc - -TARG=hyper/process - -GOFILES=\ - process.go\ - -#DEPS=\ -# gorilla.googlecode.com/hg/gorilla/context\ - -include ${GOROOT}/src/Make.pkg diff --git a/hyper/process/src/hyper/process/process.go b/hyper/process/src/hyper/process/process.go deleted file mode 100644 index 18cf55fb..00000000 --- a/hyper/process/src/hyper/process/process.go +++ /dev/null @@ -1,132 +0,0 @@ -package hyper - -import "fmt" -import "http" -import "bytes" -import "json" -import "os" - -type Process struct { - Path string `json:"path"` - Argv []string `json:"argv"` - Envp map[string]string `json:"envp"` - //Stdin string `json:"stdin"` - Stdout string `json:"stdout"` - Stderr string `json:"stderr"` - process *os.Process - process_stdin *os.File - process_stdout *os.File - process_stderr *os.File - id string - client http.Client -} - -func (p *Process) Id() string { - return p.id -} - -func NewProcess(req *http.Request) (*Process, os.Error) { - body := make([]byte, 4096) - _, err := req.Body.Read(body) - if err != nil { - return nil, err - } - - body = bytes.TrimRight(body, string([]byte{0})) - - var p Process - - if err := json.Unmarshal(body, &p); err != nil { - return nil, err - } - - p.id = gensym() - - if err := p.Start(); err != nil { - return nil, err - } - - return &p, nil -} - -func (hp *Process) Write(b []byte) { - n, err := hp.process_stdin.Write(b) - if err != nil { - fmt.Printf("Write: %s\n", err) - } else { - fmt.Printf("Wrote: %d bytes\n", n) - } -} - -func (hp *Process) Start() os.Error { - var name = hp.Path //os.Args[1] //"/usr/b" - var argv = hp.Argv //os.Args[1:] //[]string{ "bc" } - //var chroot = false - //var dir = "/var/empty" - var files [3][2]*os.File - var err os.Error - - for i, _ := range files { - files[i][0], files[i][1], err = os.Pipe() - if err != nil { - return err - } - } - - var env []string - for k, v := range hp.Envp { - env = append(env, fmt.Sprintf("%s=%s", k, v)) - } - - var attr = &os.ProcAttr{ - //Dir: dir, - Env: env, //os.Environ(), - Files: []*os.File{ files[0][0], files[1][1], files[2][1]}, - } - - //var foo, _ = json.Marshal(attr) - //fmt.Printf("%s\n", foo) - - hp.process, err = os.StartProcess(name, argv, attr) - if err != nil { - return err - } - - hp.process_stdin = files[0][1] - hp.process_stdout = files[1][0] - hp.process_stderr = files[2][0] - - for _, file := range attr.Files { - file.Close() - } - - go hp.reader(hp.process_stdout, hp.Stdout) - go hp.reader(hp.process_stderr, hp.Stderr) - return nil -} - -func (p *Process) reader(file *os.File, url string) { - var b []byte = make([]byte, 1024) - var err os.Error = nil - for err == nil { - var n int - n, err = file.Read(b) - fmt.Printf("data: %d, %s\n", n, b) - - res, err := p.client.Post(url, "application/octet-stream", bytes.NewBuffer(b)) - res = res - if err != nil { - fmt.Printf("EE: %s: %s\n", url, err) - } - } -} - -func gensym() string { - f, _ := os.Open("/dev/urandom") - b := make([]byte, 16) - f.Read(b) - f.Close() - uuid := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) - return uuid -} - diff --git a/hyper/process/test/bc.json b/hyper/process/test/bc.json deleted file mode 100644 index 5b3b0721..00000000 --- a/hyper/process/test/bc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "path": "/usr/bin/bc", - "argv": [ - "bc" - ], - "envp": { - "was": "geht" - }, - "stdout": "http://127.0.0.1:1337/", - "stderr": "http://127.0.0.1:1337/" -} diff --git a/hyper/sink/index.js b/hyper/sink/index.js deleted file mode 100644 index b556b88d..00000000 --- a/hyper/sink/index.js +++ /dev/null @@ -1,13 +0,0 @@ -require('http').createServer(function (req, res) { - - req.on('data', function (data) { - require('util').puts(data); - }); - - req.on('end', function () { - res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': 0}); - res.end(); - }); -}).listen(1337, '127.0.0.1', function () { - console.log('Running HyperSink at http://127.0.0.1:1337/'); -}); diff --git a/icecrab/Makefile b/icecrab/Makefile deleted file mode 100644 index 36e91b76..00000000 --- a/icecrab/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -.phony: debian - -debian: - [ -e /usr/bin/icecast2 ] || apt-get install --yes icecast2 - cp icecast2 /etc/default/icecast2 - cp icecast.xml /etc/icecast2/icecast.xml diff --git a/icecrab/icecast.xml b/icecrab/icecast.xml deleted file mode 100644 index 7776dc36..00000000 --- a/icecrab/icecast.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - 100 - 2 - 5 - 524288 - 30 - 15 - 10 - - 1 - - 65535 - - - - - shackit - - shackit - - - admin - aidsballs - - - - - - - - - krebs.shack - - - - 8000 - - - - - - - - - - - - - - - - - - 1 - - - - /usr/share/icecast2 - - - /var/log/icecast2 - /usr/share/icecast2/web - /usr/share/icecast2/admin - - - - - - - - - - access.log - error.log - - 3 - 10000 - - - - - - 0 - - - diff --git a/icecrab/icecast2.conf b/icecrab/icecast2.conf deleted file mode 100644 index 3a2521ff..00000000 --- a/icecrab/icecast2.conf +++ /dev/null @@ -1,19 +0,0 @@ -# Defaults for icecast2 initscript -# sourced by /etc/init.d/icecast2 -# installed at /etc/default/icecast2 by the maintainer scripts - -# -# This is a POSIX shell fragment -# - -# Full path to the server configuration file -CONFIGFILE="/etc/icecast2/icecast.xml" - -# Name or ID of the user and group the daemon should run under -USERID=icecast2 -GROUPID=icecast - -# Edit /etc/icecast2/icecast.xml and change at least the passwords. -# Change this to true when done to enable the init.d script -ENABLE=true - diff --git a/json/sh/json.sh b/json/sh/json.sh deleted file mode 100755 index 79f8529a..00000000 --- a/json/sh/json.sh +++ /dev/null @@ -1,116 +0,0 @@ -#! /bin/sh -set -euf - -# TODO check json first - -# XXX json_key is something like PWD^^ - -normalize_json() { - sed -n ' - 1s/^/cat<&2 - pop_key # TODO check if is %%%MAKEJSONOBJ%%% - #echo obj: $1 `set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"` >&2 - #json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" - json_set object "`set | sed -n "s/^\(${json_key}_[a-zA-Z]\+\)=\(.*\)/\1/p"`" -} -begin_json_array() { :; } -end_json_array() { :; } -json_push_key() { - push_key "`echo -n "$1" | base64 -d`" -} -json_set_key() { - pop_key - json_push_key "$1" -} -json_set() { - ##echo "typeof_$json_key=$1" >&2 - ##echo "${json_key}_VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 - #eval "${json_key}_TYPE=$1" - #eval "${json_key}_VALUE=\"$2\"" - eval "typeof_${json_key}=$1" - eval "${json_key}=\"$2\"" -} - -push_key() { - json_key="${json_key+${json_key}_}$1" -} -pop_key() { - json_key="`echo $json_key | sed 's/_[^_]\+$//'`" -} - -json() { - #eval echo "\"\$`echo -n "$json_key" "$@" | tr "$IFS" _`\" | base64 -d" - NAME="`echo -n "$json_key" "$@" | tr "$IFS" _`" - #eval "TYPE=\"\$${NAME}_TYPE\"" - eval "TYPE=\"\$typeof_$NAME\"" - - echo -n "$TYPE $NAME: " - case "$TYPE" in - (object) - #eval echo -n \$${NAME}_VALUE - eval echo -n \$$NAME - ;; - #set | sed -rn "s/^(${NAME})_([a-zA-Z]+)[a-zA-Z_]*_VALUE=(.*)/\1_\2/p" | - # sort | uniq | tr \\n \ ;; - (*) #echo -n "$VALUE";; - #eval "VALUE=\"\$(echo -n \"\$${NAME}_VALUE\" | base64 -d)\"" - #eval echo -n \"\$${NAME}_VALUE\" | base64 -d - eval echo -n \$${NAME} | base64 -d - esac - echo -} - -read_json() { - json_key="${1-JSON}" - #meh="`cat`" - #echo "$meh" - ##echo "$meh" | normalize_json | json_to_sh; exit - #eval "`echo "$meh" | normalize_json | json_to_sh`" - eval "`normalize_json | json_to_sh`" -} - -# TODO print_json x, print_json x ca ... to print as json - -read_json "$1" -echo ==== -set | egrep "^(typeof_)?$json_key[A-Za-z_]*=" -echo ==== -json -json a -json b -json c -json c ca -json c cb -json d -#echo ==== -#echo $JSON_VALUE -#echo $JSON_c_cb_VALUE | base64 -d; echo - -echo READY. -#### End of file. diff --git a/json/sh/test.json b/json/sh/test.json deleted file mode 100644 index 9b4c6312..00000000 --- a/json/sh/test.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "a": "1", - "b": 2, - "c": { "ca": 11, "cb": [1, 2, 3, "42"] }, - "d": {}, - "float": 4.23 -} diff --git a/kachelmann/.gitignore b/kachelmann/.gitignore deleted file mode 100644 index 050dfb2e..00000000 --- a/kachelmann/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -conditions.pl -.*.swp diff --git a/kachelmann/Makefile b/kachelmann/Makefile deleted file mode 100644 index 3343d941..00000000 --- a/kachelmann/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -.PHONY: infect -install: - # punani -Ei w3m php php-xml-simple - ln -s $$PWD/conditions ../bin/conditions - ln -s $$PWD/wetter ../bin/wetter - ln -s ${INSTALL_DIR}conditions ${INSTALL_DIR}kachelmann - diff --git a/kachelmann/wetter b/kachelmann/wetter deleted file mode 100755 index 957e13e2..00000000 --- a/kachelmann/wetter +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl -use XML::Simple; -my $result = `w3m -dump "http://www.google.com/ig/api?weather=70327-stuttgart&hl=de"`; -my $xml = new XML::Simple; -my $data = $xml->XMLin($result); -print ("$data->{weather}->{current_conditions}->{condition}->{data} bei $data->{weather}->{current_conditions}->{temp_c}->{data} Grad Zelsius\n"); diff --git a/meinsack/index b/meinsack/index deleted file mode 100755 index 7046d78c..00000000 --- a/meinsack/index +++ /dev/null @@ -1,85 +0,0 @@ -#! /bin/sh -# -# //meinsack -# -# export plz -# export str -# export anr -# export ort -# -set -euf -cd $(dirname $(readlink -f $0))/.. # cd // - -plz=${plz+"&plz=$plz"} -str=${str+"&str=$str"} -anr=${anr+"&anr=$anr"} - -url="http://www.sita-deutschland.de/sita/ywbase_Abfallkalender_Stuttgart.nsf/frmSelect?ReadForm$plz$str$anr" - -# echo $url - -html="$(curl -fsS "$url" | iconv -f latin1 -t utf8)" - -if echo "$html" | fgrep -q 'Ihre Eingabe war nicht eindeutig'; then - { - echo "Error: multiple locations found" - echo "$html" | - query/jquery/index 'table.tab:nth-child(2n) .bordertop > .text' | - sed ' - s/[[:space:]]\+/ /g - s/'"`printf '\xc2\xa0'`"'//g;# kill unicode non-breaking space - ' | - while read plz && - read str && - read ort && - read bes1 && - read bes2 && - read anr; do - str=$(echo "$str"|sed 's/<[^>]*>//g') - echo "export anr=$anr if you meant \"$ort\"" - done | sort | uniq - } >&2 - exit 2 -elif test $(echo "$html" | grep -c 'Abfallkalender für') -gt 1 && - test -z "${ort-}"; then - { - echo "Error: multiple locations found" - echo "$html" | - query/jquery/index '.tab span.text,.subheadline' | - sed -n ' - s/[[:space:]]\+/ /g - s/'"`printf '\xc2\xa0'`"'//g;# kill unicode non-breaking space - s/^Abfallkalender.*[^0-9]\([0-9]\+\)[^(]*(\(.*\))/export ort=\2/p - ' | sort | uniq - } >&2 - exit 3 -else - result="$(echo "$html" | - query/jquery/index '.tab span.text,.subheadline' | { - if test -n "${ort-}"; then - sed -n " - /($ort)/,/^Abfallkalender/{p;b} - /($ort)/,\${p;b} - " - else - cat - fi - } | { - grep -v Abfallkalender | - sed ' - s/'"`printf '\xc2\xa0'`"'//g;# kill unicode non-breaking space - s/^[A-Z][a-z]\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\3-\2-\1/ - s/^[0-9].*/ "&T00:00:00.000Z"/ - $!s/$/,/ - 1s/^/[\n/ - $s/$/\n]/ - ' - })" - if ! echo "$result" | grep .; then - { - echo "Error: your query had no effect" - echo "url=\"$url\"" - } >&2 - exit 4 - fi -fi diff --git a/punani/host/dist/arch/getsize b/punani/host/dist/arch/getsize new file mode 100755 index 00000000..a2ef8f95 --- /dev/null +++ b/punani/host/dist/arch/getsize @@ -0,0 +1,17 @@ +#! /bin/sh +set -euf +sed -n ' + /^Name/{ + s/^Name *: *\(.*\)$/\1/ + T + h + } + /^Installed Size/{ + s/^Installed Size *: *\(.*\)$/ \1/ + T + H + x + s/\n//g + p + } +' | awk '{print$2$3" "$1}' | sort -n diff --git a/sandbox/hyper/README.md b/sandbox/hyper/README.md new file mode 100644 index 00000000..d8fe9d67 --- /dev/null +++ b/sandbox/hyper/README.md @@ -0,0 +1,36 @@ +# Overview + +## start conductor on port 8888 and sink on 1337 + + //hyper/process/main + //bin/node //hyper/sink + +## create bc process and retrieve it's process id (AKA {path}) + + url=http://localhost:8888 + curl -fvsS --data-binary @//hyper/process/test/bc.json $url/proc + +## send data for calculation + + echo 9000+2^42 | curl -fvsS --data-binary @- $url/{path} + +## spawn process with http influx and local efflux + +hint: maybe run each command in some separate terminal. + + id=dummy sh -x //hyper/process/spawn stdbuf -o 0 sed 's/[^0-9 ]//g' + port=3 node //hyper/influx/http //proc/dummy/0 + cat //proc/dummy/1 + cat //proc/dummy/2 + date | curl -fvsS --data-binary @- http://localhost:3 + +## calculate the square of the current year in a little local hyper sewer system + +hint: maybe run each command in some separate terminal. + + id=sqr sh -x //hyper/process/spawn stdbuf -o 0 sed 's/[^0-9]//g;s/.*/(&)^2/' + id=bc sh -x //hyper/process/spawn bc + port=42 node //hyper/influx/http //proc/sqr/0 + cat //proc/sqr/1 > //proc/bc/0 + cat //proc/bc/1 + date +%Y | curl -fvsS --data-binary @- http://localhost:42 diff --git a/sandbox/hyper/influx/http/index.js b/sandbox/hyper/influx/http/index.js new file mode 100755 index 00000000..346dde3b --- /dev/null +++ b/sandbox/hyper/influx/http/index.js @@ -0,0 +1,57 @@ +#! /usr/bin/env node + +name = '//hyper/influx/http' +port = process.env.port || 1337 +host = process.env.host || '127.0.0.1' + + +console.info(name); + +fs = require('fs'); +path = require('path'); +http = require('http'); + +fifo_path = path.resolve(process.argv[2] || path.join(process.cwd(), '0')); + +// check configuration +try { + (function (stat) { + if ((stat.mode & 0010000) === 0) { + throw { code: 'E_not_fifo', path: fifo_path }; + }; + })(fs.statSync(fifo_path)); +} catch (exn) { + console.error(exn); + process.exit(23); +}; + +process.stdin.destroy(); +fifo = fs.createWriteStream(fifo_path); +fifo.on('open', function (fd) { + console.info('fifo open as fd', fd); + + http.createServer(function (req, res) { + var rhost = req.connection.remoteAddress; + var rport = req.connection.remotePort; + var id = rhost + ':' + rport; + + console.info(id, 'request', req.method, req.url); + + req.on('data', function (data) { + console.info(id, 'data', data.length); + }); + + req.on('end', function (data) { + console.info(id, 'end'); + res.writeHead(202, { + 'Content-Length': 0, + 'Connection': 'close' + }); + res.end(); + }); + + req.pipe(fifo, { end: false }); + }).listen(port, host, function () { + console.info('server running at http://' + host + ':' + port + '/'); + }); +}); diff --git a/sandbox/hyper/process/Makefile b/sandbox/hyper/process/Makefile new file mode 100644 index 00000000..bbc1c2fb --- /dev/null +++ b/sandbox/hyper/process/Makefile @@ -0,0 +1,19 @@ +include $(GOROOT)/src/Make.inc + +GCIMPORTS = -I pkg/$(GOOS)_$(GOARCH) +LDIMPORTS = -L pkg/$(GOOS)_$(GOARCH) + +TARG=main +GOFILES=\ + main.go\ + +include $(GOROOT)/src/Make.cmd + +export GOPATH := $(PWD) +.PHONY: prepare +prepare: + #goinstall -v github.com/garyburd/twister/server + goinstall -v gorilla.googlecode.com/hg/gorilla/mux + goinstall -v $(PWD)/src/hyper/process + +_go_.$O: prepare diff --git a/sandbox/hyper/process/main.go b/sandbox/hyper/process/main.go new file mode 100644 index 00000000..214dade9 --- /dev/null +++ b/sandbox/hyper/process/main.go @@ -0,0 +1,77 @@ +package main + +import "json" +import "log" +import "http" +import "gorilla.googlecode.com/hg/gorilla/mux" +import "os" +import "fmt" +import "bytes" + +import "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 +} + +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) + } +} + +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) + } +} + +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) + } +} + +func main() { + + // 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()) + } +} diff --git a/sandbox/hyper/process/spawn b/sandbox/hyper/process/spawn new file mode 100755 index 00000000..65e94d86 --- /dev/null +++ b/sandbox/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/sandbox/hyper/process/src/hyper/process/Makefile b/sandbox/hyper/process/src/hyper/process/Makefile new file mode 100644 index 00000000..7ecda716 --- /dev/null +++ b/sandbox/hyper/process/src/hyper/process/Makefile @@ -0,0 +1,11 @@ +include ${GOROOT}/src/Make.inc + +TARG=hyper/process + +GOFILES=\ + process.go\ + +#DEPS=\ +# gorilla.googlecode.com/hg/gorilla/context\ + +include ${GOROOT}/src/Make.pkg diff --git a/sandbox/hyper/process/src/hyper/process/process.go b/sandbox/hyper/process/src/hyper/process/process.go new file mode 100644 index 00000000..18cf55fb --- /dev/null +++ b/sandbox/hyper/process/src/hyper/process/process.go @@ -0,0 +1,132 @@ +package hyper + +import "fmt" +import "http" +import "bytes" +import "json" +import "os" + +type Process struct { + Path string `json:"path"` + Argv []string `json:"argv"` + Envp map[string]string `json:"envp"` + //Stdin string `json:"stdin"` + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` + process *os.Process + process_stdin *os.File + process_stdout *os.File + process_stderr *os.File + id string + client http.Client +} + +func (p *Process) Id() string { + return p.id +} + +func NewProcess(req *http.Request) (*Process, os.Error) { + body := make([]byte, 4096) + _, err := req.Body.Read(body) + if err != nil { + return nil, err + } + + body = bytes.TrimRight(body, string([]byte{0})) + + var p Process + + if err := json.Unmarshal(body, &p); err != nil { + return nil, err + } + + p.id = gensym() + + if err := p.Start(); err != nil { + return nil, err + } + + return &p, nil +} + +func (hp *Process) Write(b []byte) { + n, err := hp.process_stdin.Write(b) + if err != nil { + fmt.Printf("Write: %s\n", err) + } else { + fmt.Printf("Wrote: %d bytes\n", n) + } +} + +func (hp *Process) Start() os.Error { + var name = hp.Path //os.Args[1] //"/usr/b" + var argv = hp.Argv //os.Args[1:] //[]string{ "bc" } + //var chroot = false + //var dir = "/var/empty" + var files [3][2]*os.File + var err os.Error + + for i, _ := range files { + files[i][0], files[i][1], err = os.Pipe() + if err != nil { + return err + } + } + + var env []string + for k, v := range hp.Envp { + env = append(env, fmt.Sprintf("%s=%s", k, v)) + } + + var attr = &os.ProcAttr{ + //Dir: dir, + Env: env, //os.Environ(), + Files: []*os.File{ files[0][0], files[1][1], files[2][1]}, + } + + //var foo, _ = json.Marshal(attr) + //fmt.Printf("%s\n", foo) + + hp.process, err = os.StartProcess(name, argv, attr) + if err != nil { + return err + } + + hp.process_stdin = files[0][1] + hp.process_stdout = files[1][0] + hp.process_stderr = files[2][0] + + for _, file := range attr.Files { + file.Close() + } + + go hp.reader(hp.process_stdout, hp.Stdout) + go hp.reader(hp.process_stderr, hp.Stderr) + return nil +} + +func (p *Process) reader(file *os.File, url string) { + var b []byte = make([]byte, 1024) + var err os.Error = nil + for err == nil { + var n int + n, err = file.Read(b) + fmt.Printf("data: %d, %s\n", n, b) + + res, err := p.client.Post(url, "application/octet-stream", bytes.NewBuffer(b)) + res = res + if err != nil { + fmt.Printf("EE: %s: %s\n", url, err) + } + } +} + +func gensym() string { + f, _ := os.Open("/dev/urandom") + b := make([]byte, 16) + f.Read(b) + f.Close() + uuid := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) + return uuid +} + diff --git a/sandbox/hyper/process/test/bc.json b/sandbox/hyper/process/test/bc.json new file mode 100644 index 00000000..5b3b0721 --- /dev/null +++ b/sandbox/hyper/process/test/bc.json @@ -0,0 +1,11 @@ +{ + "path": "/usr/bin/bc", + "argv": [ + "bc" + ], + "envp": { + "was": "geht" + }, + "stdout": "http://127.0.0.1:1337/", + "stderr": "http://127.0.0.1:1337/" +} diff --git a/sandbox/hyper/sink/index.js b/sandbox/hyper/sink/index.js new file mode 100644 index 00000000..b556b88d --- /dev/null +++ b/sandbox/hyper/sink/index.js @@ -0,0 +1,13 @@ +require('http').createServer(function (req, res) { + + req.on('data', function (data) { + require('util').puts(data); + }); + + req.on('end', function () { + res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': 0}); + res.end(); + }); +}).listen(1337, '127.0.0.1', function () { + console.log('Running HyperSink at http://127.0.0.1:1337/'); +}); diff --git a/sandbox/json/sh/json.sh b/sandbox/json/sh/json.sh new file mode 100755 index 00000000..79f8529a --- /dev/null +++ b/sandbox/json/sh/json.sh @@ -0,0 +1,116 @@ +#! /bin/sh +set -euf + +# TODO check json first + +# XXX json_key is something like PWD^^ + +normalize_json() { + sed -n ' + 1s/^/cat<&2 + pop_key # TODO check if is %%%MAKEJSONOBJ%%% + #echo obj: $1 `set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"` >&2 + #json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" + json_set object "`set | sed -n "s/^\(${json_key}_[a-zA-Z]\+\)=\(.*\)/\1/p"`" +} +begin_json_array() { :; } +end_json_array() { :; } +json_push_key() { + push_key "`echo -n "$1" | base64 -d`" +} +json_set_key() { + pop_key + json_push_key "$1" +} +json_set() { + ##echo "typeof_$json_key=$1" >&2 + ##echo "${json_key}_VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 + #eval "${json_key}_TYPE=$1" + #eval "${json_key}_VALUE=\"$2\"" + eval "typeof_${json_key}=$1" + eval "${json_key}=\"$2\"" +} + +push_key() { + json_key="${json_key+${json_key}_}$1" +} +pop_key() { + json_key="`echo $json_key | sed 's/_[^_]\+$//'`" +} + +json() { + #eval echo "\"\$`echo -n "$json_key" "$@" | tr "$IFS" _`\" | base64 -d" + NAME="`echo -n "$json_key" "$@" | tr "$IFS" _`" + #eval "TYPE=\"\$${NAME}_TYPE\"" + eval "TYPE=\"\$typeof_$NAME\"" + + echo -n "$TYPE $NAME: " + case "$TYPE" in + (object) + #eval echo -n \$${NAME}_VALUE + eval echo -n \$$NAME + ;; + #set | sed -rn "s/^(${NAME})_([a-zA-Z]+)[a-zA-Z_]*_VALUE=(.*)/\1_\2/p" | + # sort | uniq | tr \\n \ ;; + (*) #echo -n "$VALUE";; + #eval "VALUE=\"\$(echo -n \"\$${NAME}_VALUE\" | base64 -d)\"" + #eval echo -n \"\$${NAME}_VALUE\" | base64 -d + eval echo -n \$${NAME} | base64 -d + esac + echo +} + +read_json() { + json_key="${1-JSON}" + #meh="`cat`" + #echo "$meh" + ##echo "$meh" | normalize_json | json_to_sh; exit + #eval "`echo "$meh" | normalize_json | json_to_sh`" + eval "`normalize_json | json_to_sh`" +} + +# TODO print_json x, print_json x ca ... to print as json + +read_json "$1" +echo ==== +set | egrep "^(typeof_)?$json_key[A-Za-z_]*=" +echo ==== +json +json a +json b +json c +json c ca +json c cb +json d +#echo ==== +#echo $JSON_VALUE +#echo $JSON_c_cb_VALUE | base64 -d; echo + +echo READY. +#### End of file. diff --git a/sandbox/json/sh/test.json b/sandbox/json/sh/test.json new file mode 100644 index 00000000..9b4c6312 --- /dev/null +++ b/sandbox/json/sh/test.json @@ -0,0 +1,7 @@ +{ + "a": "1", + "b": 2, + "c": { "ca": 11, "cb": [1, 2, 3, "42"] }, + "d": {}, + "float": 4.23 +} -- cgit v1.2.3