summaryrefslogtreecommitdiff
path: root/pre-install.d/50uncommitted-changes
blob: bc33ff9385d76b97c7968417561c08e941e26211 (plain)
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
#!/bin/sh
set -e

unclean() {
	if [ "$VCS" = git ]; then
		[ -d .git ] && ! LANG=C git-status 2>&1 | grep -q "working directory clean"
	elif [ "$VCS" = hg ]; then
		[ -d .hg ] && ! hg status 2>&1 | wc -l | grep -q "^0$"
	fi
}

status() {
	if [ "$VCS" = git ]; then
		git status
	elif [ "$VCS" = hg ]; then
		hg status
	fi
}

commit() {
	message="$1"

	if [ "$VCS" = git ]; then
		git add .
		for file in $(git ls-files --deleted); do
			if [ ! -d "$file" ]; then
				git rm --quiet "$file"
			fi
		done
		git commit $GIT_COMMIT_OPTIONS -m "$message"
	elif [ "$VCS" = hg ]; then
		hg addremove .
		hg commit $HG_COMMIT_OPTIONS -m "$message"
	fi
}

if [ "$1" = "ask-debconf" ]; then
	. /usr/share/debconf/confmodule
	db_capb escape
	db_title etckeeper

	db_reset etckeeper/unclean || true
	db_subst etckeeper/unclean VCS "$VCS"
	db_subst etckeeper/unclean STATUS $(status | debconf-escape -e) || true
	db_input critical etckeeper/unclean || true
	db_go || true
	db_get etckeeper/unclean
	val="$RET"
	db_reset etckeeper/unclean || true
	if [ "$val" = true ]; then
		exit 0
	else
		exit 1
	fi
elif [ "$1" = "fail-debconf" ]; then
	. /usr/share/debconf/confmodule
	db_subst etckeeper/commit_failed VCS "$VCS"
	db_input critical etckeeper/commit_failed || true
	db_go || true
	db_reset etckeeper/commit_failed || true
fi

if unclean; then
	docommit="true"
	if [ -e /usr/share/debconf/confmodule ]; then
		if $0 ask-debconf; then
			docommit=true
		else
			docommit=false
		fi
	fi
	if [ "$docommit" = true ]; then
		if ! commit "saving uncommitted changes in /etc prior to $HIGHLEVEL_PACKAGE_MANAGER run"; then
			if [ -e /usr/share/debconf/confmodule ]; then
				$0 fail-debconf
			else
				echo "error: etckeeper failed to commit changes in /etc using $VCS"
				exit 1
			fi
		fi
	fi
fi