Restore original behaviour of screen config, add some more header information
[grml-etc-core.git] / etc / apt / hg-snapshot-script
1 #!/bin/sh
2 # Filename:      hg-snapshot-script
3 # Purpose:       automatically track changed files using mercurial
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 # Latest change: Sam Sep 29 00:14:00 CEST 2007 [mika]
8 ################################################################################
9 # Basic instructions:
10 # -------------------
11 # cd /etc
12 # hg init
13 # chmod og-rwx .hg
14 #
15 # cat > .hgignore << EOF
16 # syntax: regexp
17 # (^)*.dpkg-new
18 # (^)*.dpkg-old
19 # (^)blkid.tab(|.old)
20 # (^)mtab
21 # (^)adjtime
22 # \..*.swp
23 # # add other files if necessary, depends on your setup...
24 # EOF
25 #
26 # cat >> /etc/apt/apt.conf << EOF
27 # DPkg {
28 #   Pre-Invoke  {"cd /etc ; ./apt/hg-snapshot-script pre";};
29 #   Post-Invoke {"cd /etc ; ./apt/hg-snapshot-script post";};
30 # }
31 # EOF
32 #
33 # hg add
34 # hg ci -m "initial checkin"
35 #
36 # See http://michael-prokop.at/blog/2007/03/14/maintain-etc-with-mercurial-on-debian/
37 # for more details....
38 ################################################################################
39
40 set -e
41
42 caller=$(ps axww | mawk '/aptitude|apt-get/ {for (i=5; i<=NF ; i++) printf ("%s ",$i); printf ("\n") }' | head -1)
43
44 hg addremove 1>/dev/null
45 STATUS="$(hg st)"
46
47 if [ -z "$STATUS" ] ; then
48    echo "hg-snapshot-script: nothing to be done"
49 else
50    case "$1" in
51         pre)
52            echo "hg-snapshot-script: found changed files:"
53            hg st
54            hg ci -m "snapshot from $LOGNAME before: $caller"
55           ;;
56         post)
57            echo "hg-snapshot-script: found changed files:"
58            hg st
59            hg ci -m "snapshot from $LOGNAME after: $caller"
60           ;;
61         *)
62            echo "hg-snapshot-script: found changed files:"
63            hg st
64            hg ci -m "snapshot from $LOGNAME on $(date '+%Y-%m-%d - %H:%M:%S')"
65           ;;
66    esac
67 fi
68
69 ## END OF FILE #################################################################