mingw_prefix_path () {
	test -n "$MINGW_PREFIX" || die "No MINGW_PREFIX set"
	echo $MINGW_PREFIX
}

bin_path () {
	echo "$(cygpath -am / | sed 's/^\([A-Z]\):/\/\1/')/bin"
}

copy_files () {
	mkdir -p "$2" &&
	cp "$1"/share/git/compat-bash.exe "$2"/bash.exe &&
	cp "$1"/share/git/compat-bash.exe "$2"/sh.exe &&
	cp /cmd/git.exe "$2"/
}

post_install () {
	# Install git, bash and sh redirectors into the bin/ directory
	# This needs to use the absolute path because /bin/ is overlayed by
	# /usr/bin/.
	copy_files $(mingw_prefix_path) "$(bin_path)"
}

post_upgrade () {
	post_install
}

remove_files () {
	rm "$1"/git.exe "$1"/bash.exe "$1"/sh.exe &&
	{ test -n "$(ls -A "$1")" || rm -r "$1"; }
}

post_remove () {
	remove_files "$(bin_path)"
}
