682c60c594d9d9bd47a800a7500e6d1847a4c46e
[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 ################################################################################
8 # Basic instructions:
9 # -------------------
10 # cd /etc
11 # hg init
12 # chmod og-rwx .hg
13 #
14 # cat > .hgignore << EOF
15 # syntax: regexp
16 # (^)*.dpkg-new
17 # (^)*.dpkg-old
18 # (^)blkid.tab(|.old)
19 # (^)mtab
20 # (^)adjtime
21 # \..*.swp
22 # # add other files if necessary, depends on your setup...
23 # EOF
24 #
25 # cat >> /etc/apt/apt.conf << EOF
26 # DPkg {
27 #   Pre-Invoke  {"cd /etc ; ./apt/hg-snapshot-script pre";};
28 #   Post-Invoke {"cd /etc ; ./apt/hg-snapshot-script post";};
29 # }
30 # EOF
31 #
32 # hg add
33 # hg ci -m "initial checkin"
34 #
35 # See http://michael-prokop.at/blog/2007/03/14/maintain-etc-with-mercurial-on-debian/
36 # for more details....
37 ################################################################################
38
39 set -e
40
41 caller=$(ps axww | mawk '/aptitude|apt-get/ {for (i=5; i<=NF ; i++) printf ("%s ",$i); printf ("\n") }' | head -1)
42
43 hg addremove 1>/dev/null
44 STATUS="$(hg st)"
45
46 if [ -z "$STATUS" ] ; then
47    echo "hg-snapshot-script: nothing to be done"
48 else
49    case "$1" in
50         pre)
51            echo "hg-snapshot-script: found changed files:"
52            hg st
53            hg ci -m "snapshot from $LOGNAME before: $caller"
54           ;;
55         post)
56            echo "hg-snapshot-script: found changed files:"
57            hg st
58            hg ci -m "snapshot from $LOGNAME after: $caller"
59           ;;
60         *)
61            echo "hg-snapshot-script: found changed files:"
62            hg st
63            hg ci -m "snapshot from $LOGNAME on $(date '+%Y-%m-%d - %H:%M:%S')"
64           ;;
65    esac
66 fi
67
68 ## END OF FILE #################################################################