Avoid use of etckeeper pre-commit on Trees not on the filesystem.
[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 if [ ! -z "$AVOID_COMMIT_BEFORE_INSTALL" ]; then
37         export AVOID_COMMIT_BEFORE_INSTALL
38 fi
39
40 if [ -z "$1" ]; then
41         usage
42 fi
43 command="$1"
44 shift 1
45
46 # compatability code
47 if [ "$command" = "post-apt" ]; then
48         command=post-install
49 elif [ "$command" = "pre-apt" ]; then
50         command=pre-install
51 fi
52
53 if [ ! -d "/etc/etckeeper/$command.d" ]; then
54         echo "etckeeper: /etc/etckeeper/$command.d does not exist" >&2
55         exit 1
56 fi
57
58 if [ "x$1" = "x-d" ]; then
59         if [ -n "$2" ]; then
60                 cd "$2"
61                 shift 2
62         else
63                 usage
64         fi
65 else
66         cd /etc
67 fi
68
69 lsscripts() {
70         perl -e '
71                 $dir=shift;
72                 print join "\n", grep { ! -d $_ && -x $_ }
73                         grep /^\Q$dir\/\E[-a-zA-Z0-9]+$/,
74                         glob "$dir/*";
75         ' "$1"
76 }
77
78 for script in $(lsscripts "/etc/etckeeper/$command.d"); do
79         "$script" "$@"
80 done