summaryrefslogtreecommitdiffstats
path: root/Cancer/assets
diff options
context:
space:
mode:
Diffstat (limited to 'Cancer/assets')
-rw-r--r--Cancer/assets/Makefile11
-rw-r--r--Cancer/assets/README44
-rwxr-xr-xCancer/assets/bin/asq2
-rwxr-xr-xCancer/assets/bin/ass24
-rwxr-xr-xCancer/assets/bin/check-truth11
-rwxr-xr-xCancer/assets/bin/fast20
-rwxr-xr-xCancer/assets/bin/truth2json37
-rw-r--r--Cancer/assets/doc/ass.txt9
-rw-r--r--Cancer/assets/doc/lexikon.txt12
-rw-r--r--Cancer/assets/doc/structs.nojson43
-rw-r--r--Cancer/assets/doc/usecases.txt71
-rwxr-xr-xCancer/assets/hooks/pre-commit8
12 files changed, 292 insertions, 0 deletions
diff --git a/Cancer/assets/Makefile b/Cancer/assets/Makefile
new file mode 100644
index 00000000..07efde82
--- /dev/null
+++ b/Cancer/assets/Makefile
@@ -0,0 +1,11 @@
+
+hooks := pre-commit
+binaries := $(shell ls bin/)
+.PHONY: all
+
+all: $(addprefix ../db/.git/hooks/,$(hooks)) $(addprefix ../bin/,$(binaries))
+
+../bin/%: bin/%
+ cp $< $@
+../db/.git/hooks/%: hooks/%
+ cp $< $@
diff --git a/Cancer/assets/README b/Cancer/assets/README
new file mode 100644
index 00000000..7f90bfbf
--- /dev/null
+++ b/Cancer/assets/README
@@ -0,0 +1,44 @@
+# Asset tools for krebs
+
+## Prereqs
+Check out the current krebs-asset repo into //db
+
+ git checkout root@db-host:/krebs.db.git db
+
+in //db/ is an append-only file known as 'truth'. it contains the assets and the history of these.
+Every commit is atomic, every line needs to be committed after being produced.
+
+## Usage
+### ass
+bin/ass has the power to add entries to the //db/truth file in the correct manner. It has two modes, create mode and set mode.
+Create mode produces new keys in the database, these database entries are unique.
+Set mode can set attributes to an entry in the database
+
+Example:
+ ass create bob
+ ass set bob type
+ ass create bob-pc
+ ass set bob-pc owner bob
+ ass set bob-pc location bob\'s-home
+
+### asq
+asq is a tool to query the truth for facts. This is currently only a placeholder
+
+### FAST
+fast is a wrapper around the core ass. It should be used for adding lots and lots of new entries to the truth. It evaluates Variables from your environment.
+
+Example:
+ export ASS_LOCATION=bob\'s-home
+ export ASS_OWNER=bob
+ fast c logitech-sidewinder-gamepad
+ fast c arduino-uno
+ fast s amount 3
+
+fast will then actually generate the following:
+ ass create logitech-sidewinder-gamepad
+ ass set logitech-sidewinder-gamepad owner bob
+ ass set logitech-sidewinder-gamepad location bob\'s-home
+ ass create arduino-uno
+ ass set arduino-uno owner bob
+ ass set arduino-uno location bob\'s-home
+ ass set arduino-uno amount 3
diff --git a/Cancer/assets/bin/asq b/Cancer/assets/bin/asq
new file mode 100755
index 00000000..0204e05b
--- /dev/null
+++ b/Cancer/assets/bin/asq
@@ -0,0 +1,2 @@
+#!/bin/something
+# placeholder to asq the truth for facts
diff --git a/Cancer/assets/bin/ass b/Cancer/assets/bin/ass
new file mode 100755
index 00000000..5a4dade4
--- /dev/null
+++ b/Cancer/assets/bin/ass
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -euf
+
+HERE=$(dirname $(readlink -f $0))
+DB="$HERE/../../db"
+JOURNAL="$DB/truth"
+(cd $DB && git pull >/dev/null && echo "pulled new version")
+
+METHOD="$1"; shift
+
+case $METHOD in
+"create")
+ echo "`date --utc --rfc-3339=ns` create $1" | $HERE/check-truth | tee -a $JOURNAL
+;;
+"set")
+ echo "`date --utc --rfc-3339=ns` set $1 $2 $3" | $HERE/check-truth | tee -a $JOURNAL
+;;
+*)
+ echo "you are made of stupid!"
+ exit 23
+;;
+esac
+(cd $DB && git commit -a -m bump >/dev/null && git push 1>&2 2>/dev/null && echo "updates pushed")&
diff --git a/Cancer/assets/bin/check-truth b/Cancer/assets/bin/check-truth
new file mode 100755
index 00000000..064a7d97
--- /dev/null
+++ b/Cancer/assets/bin/check-truth
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -euf
+HERE=$(dirname $(readlink -f $0))
+DB="$HERE/../../db/truth"
+read LINE
+if (cat $DB;echo $LINE) | $HERE/truth2json - 1>/dev/null ;then
+ echo "success" 1>&2
+ echo "$LINE"
+else
+ echo "you fail" 1>&2
+fi
diff --git a/Cancer/assets/bin/fast b/Cancer/assets/bin/fast
new file mode 100755
index 00000000..41725d0b
--- /dev/null
+++ b/Cancer/assets/bin/fast
@@ -0,0 +1,20 @@
+#!/bin/bash
+set -xeuf
+cd $(dirname $(readlink -f $0))
+
+if [ "$1" == "c" ];then
+ ./ass create "$2" && export ASS_CREATED="$2"
+ for i in `env | grep -v '^ASS_CREATED=' | grep "^ASS" | cut -d '=' -f 1`;do
+ e=`echo $i | cut -d '_' -f 2 | tr '[A-Z]' '[a-z]'`
+ eval con=\$$i
+ $0 s "$e" "$con"
+ done
+else if [ "$1" == "s" ]
+then
+ ./ass set "${ASS_CREATED}" "${2}" "${3}"
+ else
+ echo "you are made of stupid!"
+ cat $0
+ exit 23
+ fi
+fi
diff --git a/Cancer/assets/bin/truth2json b/Cancer/assets/bin/truth2json
new file mode 100755
index 00000000..f85445b4
--- /dev/null
+++ b/Cancer/assets/bin/truth2json
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import sys
+
+try:
+ db=sys.argv[1]
+except:
+ db="../../db/truth"
+
+ret = {}
+
+
+if db is "-":
+ sys.stderr.write("Using stdin\n")
+ f = sys.stdin
+else:
+ sys.stderr.write("Using journal '%s'\n" % db)
+ f = open(db)
+
+for line in f:
+ lsplit = line.split()
+ date = ' '.join(lsplit[0:2])
+ cmd = lsplit[2]
+ target = lsplit[3]
+ if cmd == "create":
+ assert target not in ret, "Target '%s' already created!" %target
+ ret[target] = {}
+ elif cmd == "set":
+ key = lsplit[4]
+ value = ' '.join(lsplit[5:])
+ assert target in ret, "target '%s' not set yet!" % target
+ ret[target][key] = value
+ else:
+ raise AssertionError,"unknown command '%s'!"
+
+import json
+print json.dumps(ret,sort_keys=True,indent=4)
diff --git a/Cancer/assets/doc/ass.txt b/Cancer/assets/doc/ass.txt
new file mode 100644
index 00000000..f10d2ba1
--- /dev/null
+++ b/Cancer/assets/doc/ass.txt
@@ -0,0 +1,9 @@
+ass usages:
+
+$0 create name
+ if not "create name" in history and name is not retarded:
+ echo "timestamp: create name" >> history
+
+$0 set name property value
+ if "create name" in history and property is not retarded:
+ echo "timestamp: set name property value" >> history
diff --git a/Cancer/assets/doc/lexikon.txt b/Cancer/assets/doc/lexikon.txt
new file mode 100644
index 00000000..0d362100
--- /dev/null
+++ b/Cancer/assets/doc/lexikon.txt
@@ -0,0 +1,12 @@
+
+asset / N assets
+
+platz / plaetze
+
+root-server
+
+shared root-server
+
+recht / rechte
+
+datenbank
diff --git a/Cancer/assets/doc/structs.nojson b/Cancer/assets/doc/structs.nojson
new file mode 100644
index 00000000..4c084862
--- /dev/null
+++ b/Cancer/assets/doc/structs.nojson
@@ -0,0 +1,43 @@
+"name": // default: random (gensym)
+ "type": "grafikkarte"
+ "location": "kremium"
+ "amount": 23 // default: 1
+ "owner": "shack" // default: krebs
+
+"nebula":
+ "type": "location"
+ "owner": "tv"
+
+"tv":
+ "type": "owner"
+
+"grafikkarte":
+ "type": "type"
+
+"amount":
+ "type": "natural"
+
+"root-server":
+ "type": "irgend ein owner ist root"
+
+"shared":
+ "type": "alle owner sind root"
+
+"oxberg":
+ "type": "root-server"
+ "location": "de"
+ "ipv4-address": "84.23.80.172"
+ "isp": "euserv"
+ "ram": "512MiB"
+
+"ram":
+ "must-match": /[0-9]+[MGk]iB/
+
+"kremium":
+ "location": "nebula"
+ "type": "root-server"
+ "shared": true
+
+"euserv":
+ "type": "ISP"
+
diff --git a/Cancer/assets/doc/usecases.txt b/Cancer/assets/doc/usecases.txt
new file mode 100644
index 00000000..a3e2a4fa
--- /dev/null
+++ b/Cancer/assets/doc/usecases.txt
@@ -0,0 +1,71 @@
+# use case #1: asset einsetzen
+ Hat Krebs ein Grafikkarte, die gute genug ist.
+ Wenn ja, dann will ich die in mein Computer einbauen.
+
+# use case #2: asset soll in der Ursprungszustand versetzt werden.
+ Urkrebs Mainboard-Batterie is leer und braucht Ersatz.
+ Haben wir so eine Batterie und falls ja, dann soll sie
+ fuer immer in Urkrebs rein.
+
+# use case #3: asset einlagern
+ Grafikkarte aus use case #1 (#2) soll wieder zurueck.
+
+# use case #4: asset ausschlachten
+ Urkrebs ist bis auf das Netzteil zerstoert worden,
+ das Netzteil soll eingelagert werden.
+
+# use case #5: asset hinzufuegen
+ Krebs erhaelt einen neuen Computer.
+
+# use case #6: asset finden
+ Wo oder bei wem ist das USB-Thermometer?
+
+# use case #7: asset details finden
+ Wie viele 4-Port-USB-Hubs hat krebs und wo sind die?
+
+# use case #8: verlust eines assets
+ Urkrebs ist physikalisch verschwunden, aber noch in der datenbank
+ eingetragen.
+ Welt der Dinge und der Daten muessen wieder synchron sein.
+
+# use case #9: asset anzahl erniedrigen; assets mergen
+ Eines von hundert 4-Port-USB-Hubs soll von platz X entnommen werden
+ und an ein asset gestoepselt werden.
+
+# use case #A: asset entfernen
+ Urkrebs wir vom Besitzer ausserhalb von krebs benoetigt und dem Bestand
+ entnommen.
+
+# use case #B: verlust eines platzes
+ platz ist explodiert und ein Teil der eingelagerten assets wurde vernichtet,
+ der andere Teil muss migriert werden.
+
+# use case #C: assets eines platzes erfragen
+ Was in an platz X eingelagert?
+
+# use case #D:
+ X war noch nie KM, hat aber unberechtigter weise assets, plaetze, rechte.
+ assets muessen an andere plaetze migriert werden.
+ dinge, die wie assets waren, aber nie wirklich assets waren, muessen aus der
+ datenbank entfernt werden.
+ plaetze muessen aus datenbank entfernt werden.
+ X muss entrechtet werden.
+
+# use case #E: assets in assets
+ Batterien liegen im Bankschliesfach X an platz Y.
+
+# use case #F:
+ ein root-server ist verschwunden.
+
+# use case #G:
+ welche shared root-server hat krebs in uk?
+
+# use case #H:
+ ein asset soll umbenannt werden, da der alte name nicht passend war.
+
+# use case #I:
+ welchen namen hat der Rechner, auf dem ich gerade bin?
+
+# use case #I.2:
+ welchen namen hat das asset in meiner Hand?
+
diff --git a/Cancer/assets/hooks/pre-commit b/Cancer/assets/hooks/pre-commit
new file mode 100755
index 00000000..6ad1ca2a
--- /dev/null
+++ b/Cancer/assets/hooks/pre-commit
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -euf
+if which truth2json;then
+ truth2json >/dev/null && echo "db verified"
+else
+ echo "cannot verify as truth2json is not installed"
+fi
+