#!/bin/sh
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-ttf-indic-fonts

VERSION=0.4.7.4
ARCH=noarch
BUILD=1

rm -rf $PKG
mkdir -p $PKG
cd $TMP
rm -rf ttf-indic-fonts-$VERSION
tar xjvf $CWD/ttf-indic-fonts-$VERSION.tar.bz2
cd ttf-indic-fonts-$VERSION
# Patch copyright notices so that they do not give inaccurate
# information about where to find the GPL:
zcat $CWD/ttf-indic-fonts.copyright.diff.gz | patch -p1 --verbose || exit 1

# I'm very interested in making this a better package, but have a
# long way to go in understanding how all of this works.  I know
# that at least some of the Wikipedia articles I read are filled
# in better now, but...
#
# For example, the hints files in the debian directory (where most
# of these fonts were found) -- what do they do?  And where do they
# go?  Also, some of the nicer looking fonts do not seem to be the
# defaults (perhaps also due to the lack of "hints").
#
# Hopefully this will at least provide a useful start for now.
#
# Have fun :-)
#
# -- Pat <volkerdi@slackware.com>

chown -R root:root .
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;

mkdir -p $PKG/usr/share/fonts/TTF/
cp -a */*.ttf $PKG/usr/share/fonts/TTF

# This is a better Malayalam font:
cp -a $CWD/Samyak_Malayalam.ttf.bz2 $PKG/usr/share/fonts/TTF
( cd $PKG/usr/share/fonts/TTF
  bzip2 -d Samyak_Malayalam.ttf.bz2
  chmod 644 Samyak_Malayalam.ttf
  chown root:root Samyak_Malayalam.ttf
)
# Remove the old Malayalam font:
rm -f $PKG/usr/share/fonts/TTF/malayalam.ttf

# Put copyright notices in the docs directory:
mkdir -p $PKG/usr/doc/ttf-indic-fonts-$VERSION
find . -name "*.copyright" -exec cp -a {} $PKG/usr/doc/ttf-indic-fonts-$VERSION \;
cp -a $CWD/COPYING.bz2 $PKG/usr/doc/ttf-indic-fonts-$VERSION
cp -a $CWD/Samyak_Malayalam.url $PKG/usr/doc/ttf-indic-fonts-$VERSION
( cd $PKG/usr/doc/ttf-indic-fonts-$VERSION ; bzip2 -d COPYING.bz2 )

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $PKG
makepkg -l y -c n $TMP/ttf-indic-fonts-$VERSION-$ARCH-$BUILD.tgz