summaryrefslogtreecommitdiffstats
path: root/.graveyard
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2013-11-05 13:07:46 +0100
committertv <tv@nomic.retiolum>2013-11-05 13:07:46 +0100
commitae627d2aa73ea6862af3985f1c07e95c6d493275 (patch)
treedea1eb74dccd7a14eff03e03baf2eed239a5ac72 /.graveyard
parentbf87133ae8e2ce6eb7923dc22c29b8f162c8756a (diff)
//punani: RIP
Diffstat (limited to '.graveyard')
-rw-r--r--.graveyard/punani/Makefile9
-rw-r--r--.graveyard/punani/README.md30
-rwxr-xr-x.graveyard/punani/autostart/punani-debian102
-rwxr-xr-x.graveyard/punani/bin/punani70
-rwxr-xr-x.graveyard/punani/bot/__init__.py105
-rw-r--r--.graveyard/punani/db/punani76
-rw-r--r--.graveyard/punani/doc/releases38
-rwxr-xr-x.graveyard/punani/host/dist/arch/getsize17
-rwxr-xr-x.graveyard/punani/index.py97
9 files changed, 544 insertions, 0 deletions
diff --git a/.graveyard/punani/Makefile b/.graveyard/punani/Makefile
new file mode 100644
index 00000000..f444b1fc
--- /dev/null
+++ b/.graveyard/punani/Makefile
@@ -0,0 +1,9 @@
+
+install: ../bin/punani
+
+../bin/punani:
+ ln -snvf ../punani/bin/punani ../bin/punani
+debian:
+ useradd punani||:
+ cp autostart/punani-debian /etc/init.d/punani
+ update-rc.d punani defaults
diff --git a/.graveyard/punani/README.md b/.graveyard/punani/README.md
new file mode 100644
index 00000000..1b70eab7
--- /dev/null
+++ b/.graveyard/punani/README.md
@@ -0,0 +1,30 @@
+Overview
+=======
+Punani is a meta packagemanager comprising a server which resolves package
+requests and a client containing the logic to find the best suitable packer
+on the host system. Packagenames in Punani are binaries in the PATH. All
+library packages are named in the Principle of Least Surprise[1]. Different
+package names can resolve into the same package.
+
+If you want to install the `hostname` tool, the query is
+ punani install hostname
+on an archlinux this will result in the call :
+ pacman --noconfirm -Sy --needed inetutils
+
+[1] http://de.wikipedia.org/wiki/Principle_of_Least_Surprise
+
+Punani Client
+============
+The punani client will determine which packer are available on the system
+and then send a request to the punani server to find out how the given
+package is called with the given packer. In addition to that, the client
+will add flags to the packers call in order to install packages only when
+needed and disable user interaction.
+
+Punani Server
+============
+
+The punani server is a web-service which resolves request in the following
+manner:
+ localhost/$packer/$package
+The result is the package-name with the given packer or 404 if not found.
diff --git a/.graveyard/punani/autostart/punani-debian b/.graveyard/punani/autostart/punani-debian
new file mode 100755
index 00000000..53db0336
--- /dev/null
+++ b/.graveyard/punani/autostart/punani-debian
@@ -0,0 +1,102 @@
+#!/bin/sh
+# uses template from /etc/init.d/skeleton
+### BEGIN INIT INFO
+# Provides: punani
+# Required-Start:
+# Required-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: punani
+# Description: starts punani daemon
+#
+### END INIT INFO
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+NAME=punani
+USER=punani
+DESC="$NAME daemon"
+DAEMON=/usr/bin/python
+DAEMON_DIR="/krebs/punani"
+DAEMON_ARGS="${DAEMON_DIR}/index.py"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+[ -x "$DAEMON" ] || exit 0
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+. /lib/init/vars.sh
+. /lib/lsb/init-functions
+
+do_start()
+{
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ start-stop-daemon -b -d $DAEMON_DIR -c $USER --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+ || return 1
+ start-stop-daemon -b -d $DAEMON_DIR -c $USER --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
+ $DAEMON_ARGS \
+ || return 2
+}
+
+do_stop()
+{
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile $PIDFILE
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ rm -f $PIDFILE
+ return "$RETVAL"
+}
+
+do_reload() {
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
+ return 0
+}
+
+case "$1" in
+ start)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
+ restart|force-reload)
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;;
+ *) log_end_msg 1 ;;
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
+:
diff --git a/.graveyard/punani/bin/punani b/.graveyard/punani/bin/punani
new file mode 100755
index 00000000..23ba5e00
--- /dev/null
+++ b/.graveyard/punani/bin/punani
@@ -0,0 +1,70 @@
+#! /bin/sh
+set -euf
+
+PUNANI_HOST="${PUNANI_HOST-http://euer.krebsco.de:9111}"
+ACTION="$1"; shift
+PKGS="$*"
+
+## find package manager
+if ! :; then : # dummy case, so the rest has a common format
+
+elif for PACKER_CMD in aptitude apt-get
+ do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then
+ INSTALL_PARAM='-y install'
+ REMOVE_PARAM='-y remove'
+
+elif for PACKER_CMD in bauerbill packer yaourt pacman
+ do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then
+ INSTALL_PARAM='--noconfirm -S --needed'
+ REMOVE_PARAM='-Rcs'
+
+elif for PACKER_CMD in yum
+ do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then
+ INSTALL_PARAM='-y install'
+ REMOVE_PARAM='-y remove'
+
+elif for PACKER_CMD in brew
+ do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then
+ INSTALL_PARAM='install'
+ REMOVE_PARAM='remove'
+
+
+
+else
+ echo "Error 2: no known package manager found; no punani for you!" >&2
+ exit 23
+fi
+
+## find package name
+if test -n "$PKGS"; then
+ for PKG in $PKGS; do
+ RES="`wget -O- $PUNANI_HOST/$PACKER_CMD/$PKG 2>/dev/null || :`"
+ if [ ! "$RES" ]; then
+ echo "Error 2: could not resolve '$PKG'; no punani for you!" >&2
+ exit 23
+ fi
+ RESOLVED="${RESOLVED+$RESOLVED }$RES"
+ done
+else
+ echo "Error 1: no PACKAGE specified." >&2
+ ACTION="usage"
+fi
+
+## dispatch
+case "$ACTION" in
+ install)
+ set -x
+ for PKG in $RESOLVED; do
+ sudo $PACKER_CMD $INSTALL_PARAM $PKG || echo "Cannot install $PKG!"
+ done
+ ;;
+ remove)
+ set -x
+ for PKG in $RESOLVED; do
+ sudo $PACKER_CMD $REMOVE_PARAM $PKG || echo "Cannot remove $PKG!"
+ done
+ ;;
+ *)
+ echo "usage: `basename $0` (install|remove) PACKAGE..."
+ exit 23
+esac
diff --git a/.graveyard/punani/bot/__init__.py b/.graveyard/punani/bot/__init__.py
new file mode 100755
index 00000000..4944bba0
--- /dev/null
+++ b/.graveyard/punani/bot/__init__.py
@@ -0,0 +1,105 @@
+#!/usr/bin/python
+from Queue import Queue
+from SocketServer import BaseRequestHandler, ThreadingTCPServer
+from threading import Thread
+from time import sleep, strftime, strptime
+
+from ircbot import SingleServerIRCBot
+from irclib import nm_to_n
+
+
+class PunaniRequestHandler(BaseRequestHandler):
+ """Handler for Punani messages."""
+
+ def handle(self):
+ try:
+ msg = self.request.recv(1024).strip()
+ except ValueError:
+ msg = 'Invalid message.'
+ else:
+ self.server.queue.put((self.client_address, msg))
+ print ('%s:%d' % self.client_address), str(msg)
+
+
+class PunaniReceiveServer(ThreadingTCPServer):
+ """UDP server that waits for Punani messages."""
+
+ def __init__(self):
+ ThreadingTCPServer.__init__(self,
+ ('127.0.0.1', 5555),
+ PunaniRequestHandler)
+ self.queue = Queue()
+
+
+class PunaniBot(SingleServerIRCBot):
+
+ def __init__(self, server_list, channel_list, nickname='punani-ircbot',
+ realname='Bob Ross'):
+ self.reconnection_interval = 30
+ SingleServerIRCBot.__init__(self, server_list, nickname, realname)
+ self.channel_list = channel_list
+
+ def on_welcome(self, conn, event):
+ """Join channels after connect."""
+ print 'Connected to %s:%d.' % conn.socket.getsockname()
+ for channel, key in self.channel_list:
+ conn.join(channel, key)
+
+ def on_nicknameinuse(self, conn, event):
+ """Choose another nickname if conflicting."""
+ self._nickname += '_'
+ conn.nick(self._nickname)
+
+ def on_ctcp(self, conn, event):
+ """Answer CTCP PING and VERSION queries."""
+ whonick = nm_to_n(event.source())
+ message = event.arguments()[0].lower()
+ if message == 'version':
+ conn.notice(whonick, 'Punani2irc')
+ elif message == 'ping':
+ conn.pong(whonick)
+
+ def on_privmsg(self, conn, event):
+ """React on private messages.
+
+ Die, for example.
+ """
+ whonick = nm_to_n(event.source())
+ message = event.arguments()[0]
+ if message == 'die!':
+ print 'Shutting down as requested by %s...' % whonick
+ self.die('Shutting down.')
+
+ def say(self, msg):
+ """Say message to channels."""
+ for channel, key in self.channel_list:
+ self.connection.privmsg(channel, msg)
+
+
+def process_queue(announce_callback, queue, delay=2):
+ """Process received messages in queue."""
+ while True:
+ sleep(delay)
+ try:
+ addr, msg = queue.get()
+ except Empty:
+ continue
+ #do something with the addr?
+ announce_callback(str(msg))
+if __name__ == '__main__':
+ # Set IRC connection parameters.
+ irc_servers = [('supernode', 6667)]
+ irc_channels = [('#retiolum', '')]
+
+ # Prepare and start IRC bot.
+ bot = PunaniBot(irc_servers, irc_channels)
+ t = Thread(target=bot.start)
+ t.daemon = True
+ t.start()
+ announce = bot.say
+
+ receiver = PunaniReceiveServer()
+ t = Thread(target=process_queue, args=(announce, receiver.queue))
+ t.daemon = True
+ t.start()
+ receiver.serve_forever()
diff --git a/.graveyard/punani/db/punani b/.graveyard/punani/db/punani
new file mode 100644
index 00000000..e5d1f383
--- /dev/null
+++ b/.graveyard/punani/db/punani
@@ -0,0 +1,76 @@
+{
+ "packer-symlinks" : {
+ "packer" : "yaourt",
+ "aptitude" : "apt-get",
+ "bauerbill" : "yaourt"
+ },
+ "super-packer" : {
+ "yaourt" : "pacman"
+ },
+ "nano" : {
+ "apt-get" : "nano",
+ "pacman" : "nano"
+ },
+ "vim" : {
+ "apt-get" : "vim",
+ "pacman" : "vim",
+ "brew" : "vim",
+ "yum" : "vim"
+ },
+ "zsh" : {
+ "pacman" : "zsh",
+ "apt-get" : "zsh"
+ },
+ "git" : {
+ "pacman" : "git",
+ "apt-get" : "git-core"
+ },
+ "unison" : {
+ "apt-get" : "unison",
+ "pacman" : "unison"
+ },
+ "python" : {
+ "apt-get" : "python",
+ "pacman" : "python2"
+ },
+ "python2" : {
+ "apt-get" : "python",
+ "pacman" : "python2"
+ },
+ "python3" : {
+ "apt-get" : "python3",
+ "pacman" : "python"
+ },
+ "tinc" : {
+ "apt-get" : "tinc",
+ "pacman" : "tinc"
+ },
+ "python-notify" : {
+ "pacman" : "python-notify",
+ "apt-get" : "python-notify"
+ },
+ "python-dbus" : {
+ "pacman" : "dbus-python",
+ "apt-get" : "python-dbus"
+ },
+ "w3m" : {
+ "pacman" : "w3m",
+ "apt-get" : "w3m"
+ },
+ "make" : {
+ "pacman" : "make",
+ "apt-get" : "make"
+ },
+ "perl-xml-simple" : {
+ "apt-get" : "libxml-simple-perl",
+ "pacman" : "perl-xml-simple"
+ },
+ "hostname" : {
+ "pacman" : "inetutils",
+ "apt-get" : "hostname"
+ },
+ "pip" : {
+ "pacman" : "python-pip",
+ "apt-get" : "python-pip"
+ }
+}
diff --git a/.graveyard/punani/doc/releases b/.graveyard/punani/doc/releases
new file mode 100644
index 00000000..98c4ea82
--- /dev/null
+++ b/.graveyard/punani/doc/releases
@@ -0,0 +1,38 @@
+# release files (guess the os distribution)
+# from http://linuxmafia.com/faq/Admin/release-files.html
+Annvix: /etc/annvix-release
+Arch Linux: /etc/arch-release
+Arklinux: /etc/arklinux-release
+Aurox Linux: /etc/aurox-release
+BlackCat: /etc/blackcat-release
+Cobalt: /etc/cobalt-release
+Conectiva: /etc/conectiva-release
+Debian: /etc/debian_version, /etc/debian_release (rare)
+Fedora Core: /etc/fedora-release
+Gentoo Linux: /etc/gentoo-release
+Immunix: /etc/immunix-release
+Knoppix: knoppix_version
+Linux-From-Scratch: /etc/lfs-release
+Linux-PPC: /etc/linuxppc-release
+Mandrake: /etc/mandrake-release
+Mandriva/Mandrake Linux: /etc/mandriva-release, /etc/mandrake-release, /etc/mandakelinux-release
+MkLinux: /etc/mklinux-release
+Novell Linux Desktop: /etc/nld-release
+PLD Linux: /etc/pld-release
+Red Hat: /etc/redhat-release, /etc/redhat_version (rare)
+Slackware: /etc/slackware-version, /etc/slackware-release (rare)
+SME Server (Formerly E-Smith): /etc/e-smith-release
+Solaris SPARC: /etc/release
+Sun JDS: /etc/sun-release
+SUSE Linux: /etc/SuSE-release, /etc/novell-release
+SUSE Linux ES9: /etc/sles-release
+Tiny Sofa: /etc/tinysofa-release
+TurboLinux: /etc/turbolinux-release
+Ubuntu Linux: /etc/lsb-release
+UltraPenguin: /etc/ultrapenguin-release
+UnitedLinux: /etc/UnitedLinux-release (covers SUSE SLES8)
+VA-Linux/RH-VALE: /etc/va-release
+Yellow Dog: /etc/yellowdog-release
+
+# own collection
+Angstrom: /etc/angstrom-version
diff --git a/.graveyard/punani/host/dist/arch/getsize b/.graveyard/punani/host/dist/arch/getsize
new file mode 100755
index 00000000..a2ef8f95
--- /dev/null
+++ b/.graveyard/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/.graveyard/punani/index.py b/.graveyard/punani/index.py
new file mode 100755
index 00000000..ff483d37
--- /dev/null
+++ b/.graveyard/punani/index.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+
+import web
+import json
+import os
+import sys
+from bot import *
+urls = (
+ '/', 'Index',
+ '/dump','Dump',
+# '/reload','Reload',
+ '/(.+)/(.+)', 'ArchFinder',
+)
+
+
+PDB_FILE=os.path.dirname(os.path.abspath(sys.argv[0])) + "/db/punani"
+PORT="9111"
+CHANNEL="#retiolum"
+f = open(PDB_FILE)
+pdb = json.load(f)
+f.close()
+polite = os.environ.get("polite",False)
+from socket import *
+
+def local_announce(msg):
+ s = socket(AF_INET,SOCK_STREAM)
+ s.connect(('localhost',5555))
+ s.send(msg)
+ s.close()
+class Index:
+ def GET(self):
+ ret = """Welcome to the Tightnani API<br/>
+Retrieve a package name for your distribution with: /PACKER/PKG"""
+ return ret
+
+class Reload:
+ def GET(self):
+ f = open(PDB_FILE)
+ pdb= json.load(f)
+ f.close()
+ return "DB reloaded"
+
+
+class Dump:
+ def GET(self):
+ return json.dumps(pdb,sort_keys=True,indent=4)
+
+class ArchFinder:
+ def GET(self,request_packer,package):
+ if not request_packer or not package: web.BadRequest()
+ else:
+ packer = pdb['packer-symlinks'].get(request_packer,request_packer) #try to resolve similar packers
+ super_packer = pdb['super-packer'].get(packer,'')
+ ret = pdb.get(package,{}).get(packer,False)
+ ret = ret if ret else pdb.get(package,{}).get(super_packer,False)
+
+ if not ret:
+ try:
+ if polite:
+ local_announce("Client `%s` asked for the tool `%s` in packer `%s` but i do not have it in my Database. Please update me!" %(web.ctx.ip, package,packer))
+ else:
+ local_announce("404: no %s/%s for %s" % (request_packer,package,gethostbyaddr(web.ctx.ip)[0]))
+ except Exception,e:
+ print ("Got Exception %s: %s" % (str(Exception),(e)))
+ web.NotFound()
+ return "not found. i'm so sorry :("
+ else: return ret
+
+
+
+if __name__ == "__main__":
+ import sys
+ # Set IRC connection parameters.
+ irc_servers = [('supernode.retiolum', 6667)]
+ irc_channels = [('#retiolum','')]
+
+ # Prepare and start IRC bot.
+ bot = PunaniBot(irc_servers, irc_channels)
+ t = Thread(target=bot.start)
+ t.daemon = True
+ t.start()
+ announce = bot.say
+
+ receiver = PunaniReceiveServer()
+ t = Thread(target=receiver.serve_forever)
+ t.daemon = True
+ t.start()
+
+ t = Thread(target=process_queue,args=(announce,receiver.queue))
+ t.daemon = True
+ t.start()
+
+
+ sys.argv.append(PORT)
+ app = web.application(urls,globals())
+ app.internalerror = web.debugerror
+ app.run()