#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://labs.adobe.com/downloads/flashplayer9.html
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG1=$TMP/package-flash-plugin
PKG2=$TMP/package-flash-standalone
NAME=flash-player
NAME1=flash-player-plugin
NAME2=flash-player-standalone
VERSION=9.0.48.0
ARCH=i386
BUILD=1sl

if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG1 ]; then
 mkdir -p $PKG1
fi
if [ ! -d $PKG2 ]; then
 mkdir -p $PKG2
fi

cd $TMP
tar xzvf $CWD/flash_player_9_linux_dev.tar.gz

(cd flash_player_9_linux_dev/plugin/debugger
 tar xzvf install_flash_player_9_linux.tar.gz
 cd install_flash_player_9_linux
 chown -R root:root .
 find . \( -perm 777 -o -perm 775 -o -perm 711 \) -exec chmod 755 {} \;
 find . \( -perm 700 -o -perm 555 -o -perm 511 \) -exec chmod 755 {} \;
 find . \( -perm 666 -o -perm 664 -o -perm 600 \) -exec chmod 644 {} \;
 find . \( -perm 444 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
 mkdir -p $PKG1/usr/doc/$NAME1-$VERSION/SlackBuild
 mkdir -p $PKG1/usr/lib/mozilla/plugins
 install -m 755 libflashplayer.so $PKG1/usr/lib/mozilla/plugins
 mkdir -p $PKG1/usr/lib/mozilla/components
 install -m 644 flashplayer.xpt $PKG1/usr/lib/mozilla/components
 mkdir -p $PKG1/install
 cat $CWD/slack-desc-plugin > $PKG1/install/slack-desc
 cat $CWD/slack-desc-plugin > $PKG1/usr/doc/$NAME1-$VERSION/SlackBuild/slack-desc-plugin
 cat $CWD/$NAME.SlackBuild > $PKG1/usr/doc/$NAME1-$VERSION/SlackBuild/$NAME.SlackBuild
 cd $PKG1
 requiredbuilder -v -y -s $CWD $PKG1
 makepkg -l y -c n $CWD/$NAME1-$VERSION-$ARCH-$BUILD.tgz
)

(cd flash_player_9_linux_dev/standalone/debugger
 tar xzvf flashplayer.tar.gz
 chown -R root:root .
 find . \( -perm 777 -o -perm 775 -o -perm 711 \) -exec chmod 755 {} \;
 find . \( -perm 700 -o -perm 555 -o -perm 511 \) -exec chmod 755 {} \;
 find . \( -perm 666 -o -perm 664 -o -perm 600 \) -exec chmod 644 {} \;
 find . \( -perm 444 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
 mkdir -p $PKG2/usr/bin
 install -m 755 flashplayer $PKG2/usr/bin
 mkdir -p $PKG2/usr/doc/$NAME2-$VERSION/SlackBuild
 mkdir -p $PKG2/install
 cat $CWD/slack-desc-standalone > $PKG2/install/slack-desc
 cat $CWD/slack-desc-standalone > $PKG2/usr/doc/$NAME2-$VERSION/SlackBuild/slack-desc-standalone
 cat $CWD/$NAME.SlackBuild > $PKG2/usr/doc/$NAME2-$VERSION/SlackBuild/$NAME.SlackBuild
 cd $PKG2
 requiredbuilder -v -y $PKG2
 makepkg -l y -c n $CWD/$NAME2-$VERSION-$ARCH-$BUILD.tgz
)

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi
