"
		COLOR_INFO="$COLOR_GREEN"
		COLOR_NOTICE="$COLOR_YELLOW"
		COLOR_WARN="$COLOR_BOLD_YELLOW"
		COLOR_ERROR="$COLOR_BOLD_RED"
	else
		COLOR_RESET=""
	fi
	FMT_PROG="$COLOR_PROG$PROGNAME$COLOR_RESET"
}

debug() {
	if [ -n "$DPKG_DEBUG" ]; then
		echo "DEBUG: $FMT_PROG: $*" >&2
	fi
}

error() {
	echo "$FMT_PROG: ${COLOR_ERROR}error${COLOR_RESET}: $*" >&2
	exit 1
}

warning() {
	echo "$FMT_PROG: ${COLOR_WARN}warning${COLOR_RESET}: $*" >&2
}

usage() {
	cat <<END
Usage: $PROGNAME <command> <parameter>... -- <maintainer-script-parameter>...

Commands:
  supports <command>
	Returns 0 (success) if the given command is supported, 1 otherwise.
  rm_conffile <conffile> [<last-version> [<package>]]
	Remove obsolete conffile. Must be called in preinst, postinst and
	postrm.
  mv_conffile <old-conf> <new-conf> [<last-version> [<package>]]
	Rename a conffile. Must be called in preinst, postinst and postrm.
  symlink_to_dir <pathname> <old-symlink-target> [<last-version> [<package>]]
	Replace a symlink with a directory. Must be called in preinst,
	postinst and postrm.
  dir_to_symlink <pathname> <new-symlink-target> [<last-version> [<package>]]
	Replace a directory with a symlink. Must be called in preinst,
	postinst and postrm.
  help
	Display this usage information.
END
}

badusage() {
	echo "$FMT_PROG: ${COLOR_ERROR}error${COLOR_RESET}: $1" >&2
	echo >&2
	echo "Use '$PROGNAME help' for program usage information." >&2
	exit 1
}

# Main code
set -e

PROGNAME=$(basename "$0")
version="1.19.7"

setup_colors

command="$1"
[ $# -gt 0 ] || badusage "missing command"
shift

case "$command" in
supports)
	case "$1" in
	rm_conffile|mv_conffile|symlink_to_dir|dir_to_symlink)
		code=0
		;;
	*)
		code=1
		;;
	esac
	if [ -z "$DPKG_MAINTSCRIPT_NAME" ]; then
		warning "environment variable DPKG_MAINTSCRIPT_NAME missing"
		code=1
	fi
	if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
		warning "environment variable DPKG_MAINTSCRIPT_PACKAGE missing"
		code=1
	fi
	exit $code
	;;
rm_conffile)
	rm_conffile "$@"
	;;
mv_conffile)
	mv_conffile "$@"
	;;
symlink_to_dir)
	symlink_to_dir "$@"
	;;
dir_to_symlink)
	dir_to_symlink "$@"
	;;
_internal_pkg_must_own_file)
	# This is an internal command, must not be used outside this program.
	internal_pkg_must_own_file "$@"
	;;
--help|help|-?)
	usage
	;;
--version)
	cat <<-END
	Debian $PROGNAME version $version.

	This is free software; see the GNU General Public License version 2 or
	later for copying conditions. There is NO warranty.
	END
	;;
*)
	badusage "command $command is unknown
Hint: upgrading dpkg to a newer version might help."
esac

exit 0
