r2 - in trunk: . logbuch-tools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Dec 14 13:26:01 CET 2006


Author: thomas
Date: 2006-12-14 13:26:00 +0100 (Thu, 14 Dec 2006)
New Revision: 2

Added:
   trunk/logbuch-tools/
   trunk/logbuch-tools/logbuch-installer
Log:
Initial checkin of logbuch-tools

Original commit on Tue Jul 11 13:19:02 2006 +0200 by Thomas Arendsen Hein


Added: trunk/logbuch-tools/logbuch-installer
===================================================================
--- trunk/logbuch-tools/logbuch-installer	2006-12-14 12:24:02 UTC (rev 1)
+++ trunk/logbuch-tools/logbuch-installer	2006-12-14 12:26:00 UTC (rev 2)
@@ -0,0 +1,237 @@
+#!/bin/bash
+#
+# Copyright (C) 2003-2006 by Intevation GmbH
+# Authors:
+# Thomas Arendsen Hein <thomas at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+# Das System-Logbuch /etc/logbuch.txt
+#
+#   In der Datei /etc/logbuch.txt sollten alle Änderungen am System
+#   eingetragen werden. Dabei werden zusammengehörige Änderungen in
+#   einem Block zusammengefasst, der mit Datum und ausführender Person
+#   beginnt. Innerhalb eines Blockes sind die Aktionen chronologisch
+#   sortiert, neuere Blöcke werden aber über älteren eingefügt.
+#
+# Tools zur Pflege des Logbuchs
+#
+#   Dieses Skript dient zur halbautomatischen Pflege des Logbuchs.
+#   Falls kein Logbuch existiert, wird automatisch ein neues angelegt.
+#
+#   log [Ein Text] -- erstellt einen neuen Eintrag im Logbuch.
+#   Optional kann ein Text angegeben werden, der eingetragen wird.
+#
+#   apt-install [Paketname ...] -- Installiert oder entfernt die
+#   angegebenen Debian-Pakete über apt-get. Die Paketliste muss ggf.
+#   über "apt-get update" aktualisiert werden. Beispiele:
+#
+#     apt-install wget           # installiert das Paket "wget"
+#     apt-install wget=1.8.1-6.1 # installiert "wget" Version 1.8.1-6.1
+#     apt-install wget-          # entfernt "wget"
+#     apt-install --purge wget-  # entfernt "wget" und seine Konfiguration
+#
+#   apt-upgrade -- Aktualisiert Debian-Pakete, von denen neuere
+#   Versionen existieren, z.B. Sicherheits-Updates.
+#
+# Installation des Skripts:
+#
+#   Dieses Skript muss unter dem Namen 'log' in das gewünschte
+#   Verzeichnis kopiert werden. Für die weiteren Funktionen müssen
+#   Links angelegt werden:
+#
+#     ln log apt-install && ln log apt-upgrade
+
+
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+
+LOGBUCH="/etc/logbuch.txt"
+TMPFILE=""
+
+init() {
+    if [ ! -f "$LOGBUCH" ]; then
+        need_root "$@"
+        {
+            echo "Logbuch fuer `hostname -f`"
+            echo
+            echo -e "`date +'%d.%m.%Y'`\t${LOGBUCH_USER:-${LOGNAME:-?}}"
+            echo "* $LOGBUCH angelegt"
+        } >> "$LOGBUCH" || exit $?
+    fi
+
+    VI="`type -p vim`"
+    test "$VI" || VI="`type -p vi`"
+    if [ -z "$VI" ]; then
+        echo "Bitte installieren Sie 'vim' oder einen anderen vi-Editor." >&2
+        exit 1
+    fi
+
+    test -w "$LOGBUCH" || need_root "$@"
+}
+
+need_root() {
+    if [ "`id -u`" -ne 0 ]; then
+        delete_tmpfile
+        echo "I need root access ..."
+        exec su -c $0 root -- "$@"
+        exit 0
+    fi
+}
+
+# apt_get_log logfile apt-command args
+apt_get_log() {
+    local TMPFILE="$1"; shift
+    local TMPFILE2=`mktemp /tmp/apt-log.XXXXXXXXXX` || break
+    apt-get -s "$@"|tee "$TMPFILE2"
+    {
+        echo -e "`date +'%d.%m.%Y'`\t${LOGBUCH_USER:-${LOGNAME:-?}}"
+        echo "* apt-get $@:"
+        egrep '^(Inst|Remv|Purg) ' "$TMPFILE2" | sed 's/^/  /' | grep '' || exit 1
+        echo
+    } > "$TMPFILE"
+    rm -f "$TMPFILE2"
+}
+
+# aptitude_log logfile aptitude-command args
+aptitude_log() {
+    local TMPFILE="$1"; shift
+    local TMPFILE2=`mktemp /tmp/apt-log.XXXXXXXXXX` || break
+    aptitude -v -y -s "$@"|tee "$TMPFILE2"
+    {
+        echo -e "`date +'%d.%m.%Y'`\t${LOGBUCH_USER:-${LOGNAME:-?}}"
+        echo "* aptitude $@:"
+        egrep '^(Inst|Remv|Purg) ' "$TMPFILE2" | sed 's/^/  /' | grep '' || exit 1
+        echo
+    } > "$TMPFILE"
+    rm -f "$TMPFILE2"
+}
+
+edit_logbuch() {
+    unset DISPLAY
+    $VI -c "/^[0-9]*\.[0-9]*\.[0-9]*/-1;r $1" "$LOGBUCH"
+}
+
+delete_tmpfile() {
+    if [ -n "$TMPFILE" ]; then
+        rm -f "$TMPFILE" && TMPFILE=""
+    fi
+}
+
+cleanup() {
+    echo "Abgebrochen."
+    delete_tmpfile
+    exit 0
+}
+
+init "$@"
+
+TMPFILE=`mktemp /tmp/logbuch.XXXXXXXXXX` && {
+    trap "cleanup" 1 2 3 7 10 13 15
+    case "`basename \"$0\"`" in
+        log)
+            {
+                echo -e "`date +'%d.%m.%Y'`\t${LOGBUCH_USER:-${LOGNAME:-?}}"
+                echo "* $@"
+                echo
+            } > "$TMPFILE"
+            edit_logbuch "$TMPFILE"
+            ;;
+        apt-install)
+            need_root "$@"
+            test /etc/apt/sources.list -nt /var/lib/apt/lists/lock && \
+                apt-get update
+            apt_get_log "$TMPFILE" install "$@"
+            edit_logbuch "$TMPFILE"
+            echo "Press <Enter> to start installation, <Ctrl-C> to abort."
+            read
+            apt-get install "$@"
+            ;;
+        apt-remove)
+            need_root "$@"
+            apt_get_log "$TMPFILE" remove "$@"
+            edit_logbuch "$TMPFILE"
+            echo "Press <Enter> to start removal, <Ctrl-C> to abort."
+            read
+            apt-get remove "$@"
+            ;;
+        apt-build-dep)
+            need_root "$@"
+            test /etc/apt/sources.list -nt /var/lib/apt/lists/lock && \
+                apt-get update
+            apt_get_log "$TMPFILE" build-dep "$@"
+            edit_logbuch "$TMPFILE"
+            apt-get build-dep "$@"
+            ;;
+        apt-upgrade)
+            need_root "$@"
+            apt-get update
+            apt_get_log "$TMPFILE" upgrade "$@"
+            edit_logbuch "$TMPFILE"
+            apt-get upgrade "$@"
+            ;;
+        apt-dist-upgrade)
+            need_root "$@"
+            apt-get update
+            apt_get_log "$TMPFILE" dist-upgrade "$@"
+            edit_logbuch "$TMPFILE"
+            apt-get dist-upgrade "$@"
+            ;;
+        aptitude-install)
+            need_root "$@"
+            aptitude update
+            aptitude_log "$TMPFILE" install "$@"
+            edit_logbuch "$TMPFILE"
+            aptitude install "$@"
+            ;;
+        aptitude-remove)
+            need_root "$@"
+            aptitude update
+            aptitude_log "$TMPFILE" remove "$@"
+            edit_logbuch "$TMPFILE"
+            aptitude remove "$@"
+            ;;
+        aptitude-upgrade)
+            need_root "$@"
+            aptitude update
+            aptitude_log "$TMPFILE" upgrade "$@"
+            edit_logbuch "$TMPFILE"
+            aptitude upgrade "$@"
+            ;;
+        aptitude-dist-upgrade)
+            need_root "$@"
+            aptitude update
+            aptitude_log "$TMPFILE" dist-upgrade "$@"
+            edit_logbuch "$TMPFILE"
+            aptitude dist-upgrade "$@"
+            ;;
+        logbuch-installer)
+            INSTALL_PATH="${1:-/usr/local/bin}"
+            REMOVE_PATH="/usr/local/sbin"
+            TOOLS="apt-install apt-remove apt-build-dep apt-upgrade\
+                   apt-dist-upgrade aptitude-install aptitude-remove\
+                   aptitude-upgrade aptitude-dist-upgrade"
+            echo "Installing logbuch tools to $INSTALL_PATH"
+            [ $# -eq 0 ] && need_root "$@"
+            cp "$0" "$INSTALL_PATH/log"
+            for tool in $TOOLS; do
+                [ $# -eq 0 -a -e "$REMOVE_PATH/$tool" ] && rm "$REMOVE_PATH/$tool"
+                ln -sf log "$INSTALL_PATH/$tool"
+            done
+            [ $# -eq 0 -a -e "$REMOVE_PATH/log" ] && rm "$REMOVE_PATH/log"
+            {
+                echo -e "`date +'%d.%m.%Y'`\t${LOGBUCH_USER:-${LOGNAME:-?}}"
+                echo "* Logbuch-Tools nach $INSTALL_PATH installiert"
+                echo
+            } > "$TMPFILE"
+            edit_logbuch "$TMPFILE"
+            ;;
+        *)
+            echo "Not implemented: $0" >&2
+            exit 1
+            ;;
+    esac
+    delete_tmpfile
+}
+
+exit 0


Property changes on: trunk/logbuch-tools/logbuch-installer
___________________________________________________________________
Name: svn:executable
   + *



More information about the Adminton-commits mailing list