#!/bin/bash

# Flash Player shared object updater.
# Checks to see if libflashplayer.so is installed, if so checks its version.
# Then parses http://get.adobe.com/flashplayer/ HTML to get current version, if no match, apt-get install --reinstall flashplayer-nonfree 
# which downloads the new version and keeps the package version the same.
#
# GPLv2+
# Matthew Kukowski <elitescripts2000@yahoo.com>

if [ ! -f /usr/lib/flashplugin-nonfree/libflashplayer.so ]
  then
     # echo "libflashplugin-nonfree not installed"
     exit 0
fi

LOCAL_VERSION=$(strings /usr/lib/flashplugin-nonfree/libflashplayer.so 2> /dev/null | grep LNX | cut -d ' ' -f 2 | sed -e "s/,/./g");

echo LOCAL_VERSION = $LOCAL_VERSION

# User Agent is needed, otherwise http://get.adobe.com/flashplayer/ complains.  It also shows Linux Version over OSX or Windows.
CURRENT_VERSION=$(wget -U 'Mozilla/5.0 (X11; Linux i686; rv:38.0)' -q -r 0 -t 2 -O - http://get.adobe.com/flashplayer/ | grep 'Version ' | sed 's|</b>|-|g' | sed 's|<[^>]*>||g' | sed 's/^ *//;s/ *$//' | cut -d' ' -f2);

echo CURRENT_VERSION = $CURRENT_VERSION

if [ $LOCAL_VERSION != $CURRENT_VERSION ]
  then
     apt-get -qq update && apt-get install --reinstall flashplugin-nonfree
fi
