#!/bin/sh
# learned from upstream debian/postinst
set -e

case "$1" in
configure)
	if [ "$2" = "" ] && [ -e "/etc/etckeeper/etckeeper.conf" ]; then
		# Fresh install.
		. /etc/etckeeper/etckeeper.conf || true
		if [ -n "$VCS" ] && [ -x "`which $VCS 2>/dev/null`" ]; then
			if etckeeper init; then
				if ! etckeeper commit "Initial commit"; then
					echo "etckeeper commit failed; run it by hand" >&2
				fi
			else
				echo "etckeeper init failed; run it by hand" >&2
			fi
		else
			echo "etckeeper init not ran as $VCS is not installed" >&2
		fi
	fi

	# prints error and exits nonzero if the ignore file cannot be updated
	etckeeper update-ignore || true
esac
