#!/bin/sh

# Copyright (C) 2006-2007 Bart Martens <bartm@knars.be>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e

die_hard() {
	echo "$1"
	exit 1
}

[ `whoami` = "root" ] || die_hard "must be root"

pwd | grep -q "^/tmp/flashplugin-nonfree\." || die_hard "current directory not suitable"

[ -f "pubkey.asc" ] || die_hard "public key missing"
[ -f "/usr/bin/gpg" ] || die_hard "needs \"gnupg\" installed"
[ -f "/usr/bin/wget" ] || die_hard "needs \"wget\" installed"

DOWNLOADFILE="flashplugin-nonfree-lastminute.gz"
DOWNLOADURL="http://people.debian.org/~bartm/flashplugin-nonfree/$DOWNLOADFILE"

[ ! -f /home/bartm/src/flashplugin-nonfree/bartm_debug ] || DOWNLOADURL="http://127.0.0.1/bartm/$DOWNLOADFILE"

wget -q -P "." "$DOWNLOADURL.asc" || die_hard "download failed"
wget -q -P "." "$DOWNLOADURL" || die_hard "download failed"

gpg -q --homedir "." --import "pubkey.asc" > /dev/null 2>&1 || die_hard "failed to import public key"
gpg -q --homedir "." --verify "$DOWNLOADFILE.asc" > /dev/null 2>&1 || die_hard "signature rejected"

gunzip "$DOWNLOADFILE" || die_hard "gunzip failed"

