File: etckeeper

package info (click to toggle)
etckeeper 1.18.16-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,232 kB
  • sloc: sh: 1,208; python: 111; makefile: 107; ansic: 81
file content (153 lines) | stat: -rwxr-xr-x 2,948 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
set -e

if [ -z "$ETCKEEPER_CONF_DIR" ]; then
	ETCKEEPER_CONF_DIR=/etc/etckeeper
fi

conf="$ETCKEEPER_CONF_DIR/etckeeper.conf"

usage() {
	echo "usage: etckeeper command [-d directory]" >&2
	exit 1
}

if [ -e $conf ]; then
	. $conf
fi

if [ -n "$GIT_WORK_TREE" ]; then
	unset GIT_WORK_TREE
fi
if [ -n "$GIT_DIR" ]; then
	unset GIT_DIR
fi

program_directory="${0%/*}"
if [ -n "$program_directory" ]; then
	PATH="$PATH:$program_directory"
	export PATH
fi

if [ ! -z "$GIT_COMMIT_OPTIONS" ]; then
	export GIT_COMMIT_OPTIONS
fi
if [ ! -z "$HG_COMMIT_OPTIONS" ]; then
	export HG_COMMIT_OPTIONS
fi
if [ ! -z "$BZR_COMMIT_OPTIONS" ]; then
	export BZR_COMMIT_OPTIONS
fi
if [ ! -z "$DARCS_COMMIT_OPTIONS" ]; then
	export DARCS_COMMIT_OPTIONS
fi

if [ ! -z "$HIGHLEVEL_PACKAGE_MANAGER" ]; then
	export HIGHLEVEL_PACKAGE_MANAGER
fi
if [ ! -z "$LOWLEVEL_PACKAGE_MANAGER" ]; then
	export LOWLEVEL_PACKAGE_MANAGER
fi
if [ ! -z "$AVOID_COMMIT_BEFORE_INSTALL" ]; then
	export AVOID_COMMIT_BEFORE_INSTALL
fi
if [ ! -z "$AVOID_SPECIAL_FILE_WARNING" ]; then
	export AVOID_SPECIAL_FILE_WARNING
fi
if [ -z "$LANG" ]; then
	# Default to UTF8 encoding, if unset
	export LANG=C.UTF-8
fi

if [ ! -z "$PUSH_REMOTE" ]; then
	export PUSH_REMOTE
fi

if [ -z "$HOME" ]; then
	HOME=~root
	export HOME
fi

if [ -z "$1" ]; then
	usage
elif [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ]; then
	man etckeeper || echo "Usage: etckeeper command [-d directory]" >&2
	exit 0
elif [ "x$1" = "x-v" ] || [ "x$1" = "x--version" ]; then
	# This is automatically updated by the Makefile.
	echo "Version: 1.18.16"
	exit 0
fi
command="$1"
shift 1

# compatability code
if [ "$command" = "post-apt" ]; then
	command=post-install
elif [ "$command" = "pre-apt" ]; then
	command=pre-install
fi

if echo "$command" | LANG=C egrep -q '[^-a-z_]'; then
	echo "etckeeper: invalid command $command" >&2
	exit 1
fi

if [ ! -d "$ETCKEEPER_CONF_DIR/$command.d" ]; then
	echo "etckeeper: $ETCKEEPER_CONF_DIR/$command.d does not exist" >&2
	exit 1
fi

if [ "x$1" = "x-d" ]; then
	if [ -n "$2" ]; then
		ETCKEEPER_DIR="$2"
		shift 2
	else
		usage
	fi
fi

if [ -z "$ETCKEEPER_DIR" ]; then
	ETCKEEPER_DIR=/etc
fi
cd "$ETCKEEPER_DIR"
export ETCKEEPER_DIR

if [ -d ".git" ]; then
	VCS=git
elif [ -d ".hg" ]; then
	VCS=hg
elif [ -d "_darcs" ]; then
	VCS=darcs
elif [ -d ".bzr" ]; then
	VCS=bzr
fi

if [ -z "$VCS" ]; then
	echo "Please configure a VCS in $conf" >&2
	exit 1
fi
export VCS

if command -v perl >/dev/null; then
	lsscripts() {
		LANG=C perl -e '
			$dir=shift;
			print join "\n", grep { ! -d $_ && -x $_ }
				grep /^\Q$dir\/\E[-a-zA-Z0-9]+$/,
				glob "$dir/*";
		' "$1"
	}

	for script in $(lsscripts "$ETCKEEPER_CONF_DIR/$command.d"); do
		"$script" "$@"
	done
else
	# fallback if perl isn't present
	for script in $ETCKEEPER_CONF_DIR/$command.d/*; do
		if [ ! -d "$script" -a -x "$script" ]; then
			echo "$script" | egrep -q "/[-a-zA-Z0-9]+$"
			[ $? -eq 0 ] && "$script" "$@"
		fi
	done
fi