#!/bin/sh

set -e

# XXX Note when updating to also update
# debian/flashplugin-installer.config and debian/post-download-hook
FLASH_VERSION=20161213.1
FILENAME=adobe-flashplugin_${FLASH_VERSION}.orig.tar.gz
SHA256SUM_TGZ="abf0dad1f238ef95a3404c49b3c1047d42e022b6402df36e438d18f475f711cf"

OLD_VARIANTS="iceape iceweasel mozilla firefox xulrunner midbrowser xulrunner-addons"

. /usr/share/debconf/confmodule

# previously : flashplayer10_install_linux_091508.tar.gz and install_flash_player_10_linux/
# currently  : install_flash_player_10_linux.tar.gz and install_flash_player_10_linux/

fp_exit_with_error() {
	echo $1
	echo "The Flash plugin is NOT installed."
	db_fset flashplugin-installer/local seen false
	exit 1
}


if dpkg --compare-versions "$2" lt-nl 11.1.102.55ubuntu3; then
	# We now install a native amd64 flash binary, so remove the old
	# nspluginwrapper alternatives
	for p in $OLD_VARIANTS; do
		update-alternatives --quiet --remove "$p-flashplugin" /var/lib/flashplugin-installer/npwrapper.libflashplayer.so
	done
	rm -f /var/lib/flashplugin-installer/npwrapper.libflashplayer.so
	rm -f /usr/share/ubufox/plugins/npwrapper.libflashplayer.so
fi

rm -f /var/lib/update-notifier/package-data-downloads/flashplugin-installer \
      /var/lib/update-notifier/package-data-downloads/flashplugin-installer.*

db_get flashplugin-installer/local
if [ -d "$RET" -a -f "$RET"/$FILENAME ]; then

	echo "Installing from local file $RET/$FILENAME"

	# verify SHA256 checksum of (copied or downloaded) tarball
	echo "$SHA256SUM_TGZ  $RET/$FILENAME" | sha256sum -c > /dev/null 2>&1 \
		|| fp_exit_with_error "sha256sum mismatch $RET/$FILENAME"

	/usr/lib/flashplugin-installer/install_plugin "$RET/$FILENAME"

	echo "Flash Plugin installed."

	touch /var/lib/update-notifier/package-data-downloads/flashplugin-installer
fi

# previous versions used update-alternatives --set to force a particular
# value here, which now needs to be cleaned up.  We should never use
# u-a --set in a maintainer script.
if dpkg --compare-versions "$2" lt-nl 10.3.183.10ubuntu5; then
	update-alternatives --quiet --auto "mozilla-flashplugin"
fi

db_fset flashplugin-installer/local seen false

#DEBHELPER#

exit 0

# vim: ts=2 sw=2
