#!/bin/sh

set -e

FLASH_VERSION=10.1.82.76
FILENAME=adobe-flashplugin_${FLASH_VERSION}.orig.tar.gz
SHA256SUM_TGZ="e74571c8850e98c1f8af3556d7a0be212b2e45d7ea4836d7175d754f8b3d1747"

. /usr/share/debconf/confmodule

# previously : install_flash_player_10_linux.tar.gz
# currently  : adobe-flashplugin_${FLASH_VERSION}.orig.tar.gz

db_get flashplugin-installer/local
echo "$SHA256SUM_TGZ  $RET/$FILENAME" \
| sha256sum -c > /dev/null 2>&1 \
|| db_set flashplugin-installer/local /var/cache/flashplugin-installer

db_get flashplugin-installer/local
echo "$SHA256SUM_TGZ  $RET/$FILENAME" \
| sha256sum -c > /dev/null 2>&1 \
|| db_set flashplugin-installer/local /usr/lib/flashplugin-installer-unpackdir

db_get flashplugin-installer/local
echo "$SHA256SUM_TGZ  $RET/$FILENAME" \
| sha256sum -c > /dev/null 2>&1 \
|| db_reset flashplugin-installer/local 

while true; do
    db_input medium flashplugin-installer/local || true
    db_go
    db_get flashplugin-installer/local
    if [ -d "$RET" -a -f "$RET"/$FILENAME ]; then
		LOCAL="true"
		break;
    elif [ "x$RET" = "x" ]; then
		break;
    fi
    db_reset flashplugin-installer/not_exist || true
    db_reset flashplugin-installer/local || true
    db_text medium flashplugin-installer/not_exist || true
    db_go
done

if [ "$LOCAL" != "true" ]; then
    db_reset flashplugin-installer/httpget
    db_input medium flashplugin-installer/httpget || true
    db_go
    db_get flashplugin-installer/httpget
fi
