apt-feed-logbuch.sh
changeset 0 117aabc28c6c
child 2 bc049aafe824
child 5 34214775a77a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apt-feed-logbuch.sh	Thu Apr 28 13:06:25 2011 +0200
@@ -0,0 +1,36 @@
+#! /bin/sh
+#
+# automaticly update logbuch
+# if using apt-get or aptitude command
+#
+# (C) 2011 by Christian Arnold - Schlittermann internet & unix support
+
+set -e
+
+unset  LC_ALL
+export LANG=C
+export LC_CTYPE=en_US.UTF-8
+
+APT_LOG="/var/log/apt/history.log"
+LINES_COUNT="/tmp/lines_count.dat"
+LOGBUCH_OPT=""
+
+if test -f /etc/default/ius.upgrade.conf; then
+    . /etc/default/ius.upgrade.conf
+fi
+
+APT_CMD=$(ps -p $1 -o args=)
+APT_TMP="/tmp/$$.tmp"
+APT_OUT="/tmp/$$.out"
+
+if [ $APT_LOG -nt $LINES_COUNT ]; then
+  BEFOR=$(cat $LINES_COUNT)
+  AFTER=$(wc -l < $APT_LOG)
+  LINES=$(($AFTER - $BEFOR - 1))
+  echo APT: $APT_CMD > $APT_OUT
+  tail -n $LINES $APT_LOG | sed -e '/^Start-Date:/d;/^Commandline:/d;/^End-Date:/d' >> $APT_TMP
+  perl -ne 'chomp; ($action, $packages) = split " ", $_, 2; print map { "- $action $_\n" } $packages =~ /\S+\s\(.*?\)/g' $APT_TMP >> $APT_OUT
+  logbuch $LOGBUCH_OPT --message=@$APT_OUT
+  # cleanup
+  rm -f $APT_TMP $LINES_COUNT $APT_OUT
+fi