#!/bin/sh
#
# Instructions:
#
# 1. Download Microsoft's Powerpoint Viewer installer
#    (PowerPointViewer.exe) from here or here:
#
# http://www.hunlock.com/blogs/Downloading_and_Using_Vista_Web_Fonts
#
# http://www.microsoft.com/downloads/details.aspx?familyid=048DC840-14E1-467D-8DCA-19D2A8FD7485&displaylang=en
#
# 2. Put it in the same directory as this script, the doinst.sh script,
#    and the slack-desc file.
#
# 3. Run this script in the same directory.
#
# 4. Install the /tmp/build/msftcfonts-*.tgz package.
#
# 5. ...
#
# 6. Profit.
#

APP=msftcfonts
VERSION=1.0
ARCH=noarch
BUILD=1beej

PREFIX=/usr

TARBALL=PowerPointViewer.exe

TTFFONTDIR=usr/share/fonts/TTF

STARTDIR=`pwd`

PACKAGENAME=$APP-$VERSION-$ARCH-$BUILD.tgz
PACKAGEDEST=/tmp/build   # final resting place of package

BUILDBASE=/tmp/build/$APP
BUILDSRC=$BUILDBASE/src
BUILDDEST=$BUILDBASE/dest

EXEFILESEARCHKEY='ELF.*executable'  # use ''; regex for file(1) output

INSTALLDOCS="true"
DOCDIR=$BUILDDEST/$PREFIX/doc/$APP-$VERSION

DOCLEANUP="true"

#--------------------------------------------------------------------
# set up build area
#
mkdir -p $BUILDBASE $BUILDSRC $BUILDDEST || exit 1

#--------------------------------------------------------------------
# extract
#
(
	cd $BUILDSRC
	cabextract $STARTDIR/$TARBALL ppviewer.cab
) || exit 1

#--------------------------------------------------------------------
# install
#
mkdir -p $BUILDDEST/$TTFFONTDIR
(
	cd $BUILDSRC
	for ff in *.TTF; do
		lowername=`echo $ff | tr [A-Z] [a-z]`
		mv $ff $BUILDDEST/$TTFFONTDIR/$lowername
	done
) || exit 3

#--------------------------------------------------------------------
# install setup files
#
installdir=$BUILDDEST/install
mkdir $installdir
if [ -f slack-desc ]; then 
    cp slack-desc $installdir
fi
if [ -f doinst.sh ]; then 
    cp doinst.sh $installdir
fi

#--------------------------------------------------------------------
# set ownership
#
chown -R root:root $BUILDDEST

#--------------------------------------------------------------------
# make package
#
(
	cd $BUILDDEST
	makepkg -l y -c y $PACKAGENAME
) || exit 6

mv $BUILDDEST/$PACKAGENAME $PACKAGEDEST

#--------------------------------------------------------------------
# cleanup
#
if [ $DOCLEANUP = "true" ]; then
    rm -rf $BUILDBASE
fi
