#!/bin/sh
#
# This script packages the Microsoft TrueType core fonts for the Web.
# These fonts can be distributed only in their original format (.exe).
# Putting the .exe files inside a tarball is not clearly legal so we
# distribute these fonts as a separate .exe files in their very
# original format which is perfectly legal. These files are no longer
# available for download from microsoft.com but can be downloaded for
# free from these addresses:
# - http://sourceforge.net/projects/corefonts/
# - http://sourceforge.net/projects/font-tool/
#
# This script needs files found in the directory 'scripts/corefonts-data'.
#
# By using these fonts you agree to Microsoft's EULA.
#

umask 0022

PKG=/tmp/fonts-corefonts-noversion-noarch-1unknown.tlz
TMP=/tmp/package-corefonts

rm -rf "$TMP"
mkdir "$TMP" || exit 1
mkdir -p \
  "$TMP/usr/X11R6/lib/X11/fonts/TTF" \
  "$TMP/usr/doc/fonts/corefonts" \
  "$TMP/install"

cd "$(dirname "$0")/corefonts-data"
cp -v EULA.txt "$TMP/usr/doc/fonts/corefonts"
./cabextract -LF '*.ttf' -d "$TMP/usr/X11R6/lib/X11/fonts/TTF" \
  andale32.exe \
  arial32.exe \
  arialb32.exe \
  comic32.exe \
  courie32.exe \
  georgi32.exe \
  impact32.exe \
  times32.exe \
  trebuc32.exe \
  verdan32.exe \
  webdin32.exe

cd "$TMP"
cat << EOF > install/slack-desc
fonts-corefonts: Microsoft's TrueType core fonts for the Web
fonts-corefonts:
fonts-corefonts: Fonts: Andale Mono, Arial, Arial Black, Comic Sans MS, Courier New,
fonts-corefonts: Georgia, Impact, Times New Roman, Trebuchet MS, Verdana, Webdings
fonts-corefonts:
fonts-corefonts: This package contains TrueType fonts which have been distributed
fonts-corefonts: by Microsoft under relatively permissive license but are no longer
fonts-corefonts: availabe for download from http://microsoft.com/. They can be still
fonts-corefonts: downloaded for free from either of these projects in Sourceforge:
fonts-corefonts: http://sf.net/projects/corefonts/ & http://sf.net/projects/font-tool/
fonts-corefonts:
fonts-corefonts: NOTE: BY USING THIS PACKAGE YOU ACCEPT THE END USER LICENSE
fonts-corefonts: AGREEMENT WHICH IS AVAILABLE IN /usr/doc/fonts/corefonts/EULA.txt.
EOF

cat << EOF > install/doinst.sh
# Update the X font indexes:
if [ -x /usr/X11R6/bin/fc-cache ]; then
  /usr/X11R6/bin/fc-cache -f
fi
# else we'll catch it later with setup.fontconfig :-)
EOF

rm -rf "$PKG"
makepkg -c y -l y "$PKG"
cd ..
rm -r "$TMP"
