#! /bin/bash -e

# = = = = = = = = = = = = = = = = = = = = = = =
# =     Copyright (C) 2015-2025 uib GmbH      =
# =           http://www.uib.de               =
# =          All rights reserved.             =
# = = = = = = = = = = = = = = = = = = = = = = =

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

VERBOSE=true


case "$1" in
	install|upgrade)
		TFTPROOT="/tftpboot/opsi/opsi-linux-bootimage"
		if [ -f "$TFTPROOT/cfg/grub.cfg" ]; then
			echo "saving grub configuratin file"
			cp $TFTPROOT/cfg/grub.cfg $TFTPROOT/cfg/grub.cfg.old
		fi
		if [ -f "$TFTPROOT/cfg/grub-menu.cfg" ]; then
			cp $TFTPROOT/cfg/grub-menu.cfg $TFTPROOT/cfg/grub-menu.cfg.old
		fi
		if [ -f "$TFTPROOT/cfg/grub-custom.cfg" ]; then
			cp $TFTPROOT/cfg/grub-custom.cfg $TFTPROOT/cfg/grub-custom.cfg.old
	        fi
        	if [ -f "$TFTPROOT/cfg/grub-settings.cfg" ]; then
			cp $TFTPROOT/cfg/grub-settings.cfg $TFTPROOT/cfg/grub-settings.cfg.old
		fi
		if [ -f "$TFTPROOT/cfg/install-grub-x64" ]; then
			echo "saving grub template file"
			cp $TFTPROOT/cfg/install-grub-x64 $TFTPROOT/cfg/install-grub-x64.old
		fi

	;;

	abort-upgrade)

	;;

	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 1
	;;
esac

exit 0
