equal
deleted
inserted
replaced
1 #! /bin/sh |
|
2 # |
|
3 # automaticly update logbuch |
|
4 # if using apt-get or aptitude command |
|
5 # |
|
6 # (C) 2012 by Christian Arnold - Schlittermann internet & unix support |
|
7 |
|
8 set -e |
|
9 |
|
10 unset LC_ALL |
|
11 export LANG=C |
|
12 export LC_CTYPE=en_US.UTF-8 |
|
13 |
|
14 APT_LOG="/var/log/apt/history.log" |
|
15 LINES_COUNT="/tmp/lines_count.dat" |
|
16 LOGBUCH_OPT="" |
|
17 |
|
18 if test -f /etc/default/ius.upgrade.conf; then |
|
19 . /etc/default/ius.upgrade.conf |
|
20 fi |
|
21 |
|
22 if ! test -f "$LINES_COUNT"; then |
|
23 echo "$0: $LINES_COUNT is missing" >&2 |
|
24 exit 0 |
|
25 fi |
|
26 |
|
27 if ! test -s "$LINES_COUNT"; then |
|
28 echo "$0: $LINES_COUNT is empty" >&2 |
|
29 exit 0 |
|
30 fi |
|
31 |
|
32 APT_CMD=$(ps -p $1 -o args=) |
|
33 |
|
34 # skip download-only from logbuch |
|
35 if echo $APT_CMD | grep -q "[[:space:]]\+-d\|-dy\|-yd\|--download-only"; then |
|
36 exit 0 |
|
37 fi |
|
38 |
|
39 APT_TMP="/tmp/$$.tmp" |
|
40 APT_OUT="/tmp/$$.out" |
|
41 |
|
42 if [ $APT_LOG -nt $LINES_COUNT ]; then |
|
43 BEFOR=$(cat $LINES_COUNT) |
|
44 AFTER=$(wc -l < $APT_LOG) |
|
45 LINES=$(($AFTER - $BEFOR - 1)) |
|
46 echo APT: $APT_CMD > $APT_OUT |
|
47 tail -n $LINES $APT_LOG | sed -e '/^Start-Date:/d;/^Commandline:/d;/^End-Date:/d' >> $APT_TMP |
|
48 perl -ne 'chomp; ($action, $packages) = split " ", $_, 2; print map { "- $action $_\n" } $packages =~ /\S+\s\(.*?\)/g' $APT_TMP >> $APT_OUT |
|
49 logbuch $LOGBUCH_OPT --message=@$APT_OUT |
|
50 # cleanup |
|
51 rm -f $APT_TMP $LINES_COUNT $APT_OUT |
|
52 fi |
|