Remove now obsolete precommit script for bzr.
[jelmer/etckeeper.git] / etckeeper
1 #!/bin/sh
2 set -e
3 conf=/etc/etckeeper/etckeeper.conf
4
5 usage() {
6         echo "usage: etckeeper command [-d directory]" >&2
7         exit 1
8 }
9
10 if [ -e $conf ]; then
11         . $conf
12 fi
13
14 if [ -z "$VCS" ]; then
15         echo "Please configure a VCS in $conf" >&2
16         exit 1
17 fi
18 export VCS
19
20 if [ ! -z "$GIT_COMMIT_OPTIONS" ]; then
21         export GIT_COMMIT_OPTIONS
22 fi
23 if [ ! -z "$HG_COMMIT_OPTIONS" ]; then
24         export HG_COMMIT_OPTIONS
25 fi
26 if [ ! -z "$BZR_COMMIT_OPTIONS" ]; then
27         export BZR_COMMIT_OPTIONS
28 fi
29
30 if [ ! -z "$HIGHLEVEL_PACKAGE_MANAGER" ]; then
31         export HIGHLEVEL_PACKAGE_MANAGER
32 fi
33 if [ ! -z "$LOWLEVEL_PACKAGE_MANAGER" ]; then
34         export LOWLEVEL_PACKAGE_MANAGER
35 fi
36
37 if [ -z "$1" ]; then
38         usage
39 fi
40 command="$1"
41 shift 1
42
43 # compatability code
44 if [ "$command" = "post-apt" ]; then
45         command=post-install
46 elif [ "$command" = "pre-apt" ]; then
47         command=pre-install
48 fi
49
50 if [ ! -d "/etc/etckeeper/$command.d" ]; then
51         echo "etckeeper: /etc/etckeeper/$command.d does not exist" >&2
52         exit 1
53 fi
54
55 if [ "x$1" = "x-d" ]; then
56         if [ -n "$2" ]; then
57                 cd "$2"
58                 shift 2
59         else
60                 usage
61         fi
62 else
63         cd /etc
64 fi
65
66 lsscripts() {
67         perl -e '
68                 $dir=shift;
69                 print join "\n", grep { ! -d $_ && -x $_ }
70                         grep /^\Q$dir\/\E[-a-zA-Z0-9]+$/,
71                         glob "$dir/*";
72         ' "$1"
73 }
74
75 for script in $(lsscripts "/etc/etckeeper/$command.d"); do
76         "$script" "$@"
77 done