#!/bin/sh
ver="0.2.3b"
copy="2002"
mail="PointedEars@gmx.de"
# ----------------------------------------------------------------------------
#     Flash Plugin Installer for GNU/Linux 0.2.3b"
#     Copyright (c) 2002  Thomas Lahn <PointedEars@gmx.de>"
#
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
#
#     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, write to the Free Software
#     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#     Send suggestions and bug reports to <bug-flash@PointedEars.de>
# ----------------------------------------------------------------------------

# from /etc/rc.status

if test -z "$LINES" -o -z "$COLUMNS" ; then
    eval `stty size 2>/dev/null | (read L C; \
    echo LINES=${L:-24} COLUMNS=${C:-80})`
fi
test $LINES   -eq 0 && LINES=24
test $COLUMNS -eq 0 && COLUMNS=80

if test "$TERM" != "raw" && stty size > /dev/null 2>&1 ; then
  esc=`echo -en "\033"`
  extd="${esc}[1m"
  warn="${esc}[1;31m"
  done="${esc}[1;32m"
  norm=`echo -en "${esc}[m\017"`
  rc_done="${extd}done${norm}"
else
  esc=""
  extd=""
  warn=""
  done=""
  norm=""
  rc_done="done"
fi

#

function help {
  echo "
Usage: ${extd}`basename $0`${norm} [PLUGIN_PATH] [TGZ_PATH]

PLUGIN_PATH  User-defined plugins directory. Use \`-' for the default
               (/usr/local/mozilla/plugins)
TGZ_PATH     User-defined .tar.gz file where the plugin files are contained.
               You MUST leave the .tar.gz suffix out and the respective archive
               MUST contain a TGZ_PATH directory to contain the plugin files.
               Use \`-' or leave this out for the default
               (install_flash_player_6_linux).
  "
}

echo "
${extd}Flash Plugin Installer for GNU/Linux $ver$norm
Copyright (c) $copy  Thomas Lahn <$mail>
Protected under the terms of the GNU General Public License (GPL).
See COPYING file or http://www.fsf.org/copyleft/gpl.html for details."
#"Currently under construction. Please stand by."
#exit 255
help=0
if [ -z "$1" ] || [ "$1" = "-?" ] || [ "$1" = "--help" ]; then
  help=1;
  help
fi
echo "Send suggestions and bug reports to <bug-flash@PointedEars.de>
"
test $help -eq 1 && exit 255

echo -n "checking for tar... "
chk=`which tar 2> /dev/null`
if [ -n "$chk" ]; then
  echo "`tar --version | head -n 1 -` ($chk)"
else
  echo "ERROR!

`basename $0`: Could not find tar which is required to extract the archive.
  "
  exit 254
fi

echo -n "checking for gzip... "
chk=`which gzip 2> /dev/null`
if [ -n "$chk" ]; then
  echo "`gzip --version | head -n 1 -` ($chk)"
else
  echo "ERROR!

`basename $0`: Could not find gzip which is required to extract the archive.
  "
  exit 253
fi

tgz=install_flash_player_6_linux
test -n "$2" -a "$2" != "-" && tgz=$2

echo -n "checking for archive... "
if [ -f "`dirname $0`/$tgz.tar.gz" ]; then
  echo "$rc_done
extracting files... "
  tar xvzf "`dirname $0`/$tgz.tar.gz" -C /tmp $tgz/libflashplayer.so $tgz/ShockwaveFlash.class $tgz/flashplayer.xpt 2> /dev/null
  if [ -d /tmp/$tgz ]; then
    echo "... $rc_done"
    cd /tmp/$tgz
    target="/usr/local/mozilla/plugins"
    test "$1" != "-" && target=$1
    echo -n "checking for target directory... "
    if [ -d "$target" ]; then
      echo "$target
installing plugins... "
      cp -piv * $target
      if [ $? -eq 0 ]; then
        echo "... $rc_done"
        echo -n "cleaning up... "
        rm -r /tmp/$tgz &> /dev/null
        if [ $? -eq 0 ]; then
          echo "$rc_done"
        else
          echo "${warn}ERROR!${norm}"
        fi
      else
        echo "... ${warn}ERROR!${norm}
        "
        exit 249
      fi
    else
      echo "${warn}ERROR!${norm}
      "
      echo "`basename $0`: $target: Unable to find target directory." >&2
      echo
      exit 250
    fi
  else
    echo "${warn}ERROR!${norm}
    "
    echo "`basename $0`: /tmp/$tgz: Unable to create directory." >&2
    echo
    exit 251
  fi
else
  echo "${warn}ERROR!${norm}
  "
  echo "`basename $0`: Unable to find $tgz.tar.gz" >&2
  echo
  exit 252
fi
echo
exit 255
