#!/bin/sh

set -e

rename_conffile_rollback () {
# syntax: rename_conffile_rollback old_name new_name
#
# Roll back the renaming of a conffile from "old_name" to "new_name".
#
# Call this function from a postrm script in the event $1 is "abort-upgrade"
# or "abort-install" is  after having used rename_conffile_prepare() in the
# preinst.

	# local conffile

	# Validate arguments.
	if [ $# -ne 1 ]; then
	echo "$0: usage error: rename_conffile_rollback() called with wrong number of arguments (expected 1, got $#)."
		exit 2
	fi

	_old_conffile="$1"
	_new_conffile="$2"

	# If the temporary file created by rename_conffile_prepare() exists,
	# rename _new_conffile to _old_conffile.
	if [ -e "$_old_conffile.python-moinmoin.moved" ]; then
		echo "Rolling back renaming of conffile $_old_conffile to $_new_conffile." >&2
		mv "$_new_conffile" "$_old_conffile"
		rm "$_old_conffile.python-moinmoin.moved"
	fi
}

#DEBHELPER#

if [ "$1" = "abort-install" ] || [ "$1" = "abort-upgrade" ]; then
	rename_conffile_rollback /etc/moin/moinmaster.py /etc/moin/mywiki.py
fi
