#!/bin/sh

set -e
set -u
set -x

[ `id -u` = 0 ] || { echo "must be root"; exit 1; }

SRCID="$(cd "$(dirname "$1")";md5sum "$(basename "$1")")"
OSVERSION="`version`"
TODAY=`date +%Y/%m/%d`
PACKAGE="ttf-ocra-font"
SEP="-"
VERSION="2-20110319"
EXT="tcz"
DESCRIPTION="OCR-A typeface (font) in ttf format. Monospace, standardized and simple. Hence takes very few bytes."
AUTHORS="Matthew Skala, Richard B. Wales, Tor Lillqvist"
HOMEPAGE="http://ansuz.sooke.bc.ca/page/fonts"
LICENSE="Public Domain"
ME="Marco Caminati"
DEPS=""
PREFIX=/usr/local
REPO=${REPO:="/etc/sysconfig/tcedir/optional"} 
TCUSER=`cat /etc/sysconfig/tcuser`
THISDIR=`pwd`
PKGDIR="${THISDIR}/${PACKAGE}"
SRCDIR="${PKGDIR}/src"
RECUWARN=""
NAIVE=""

environment(){
   sudo -u ${TCUSER} tce-load -i ${REPO}/squashfs-tools-4.x.tcz
   mkdir -p "${PKGDIR}/tmp/${PACKAGE}/${PREFIX}/share/fonts/${PACKAGE}"
   cd ${PKGDIR}
   unzip "${1}"
}

workit(){
   cp OCRA.ttf "${PKGDIR}/tmp/${PACKAGE}/${PREFIX}/share/fonts/${PACKAGE}/"
}

packageit(){
   cd ${PKGDIR}/tmp/$1
   for dir in `ls -A`; do
      find ${dir} -not -type d | sort >> ../../${1}.${EXT}.list
   done

   mksquashfs . ../../${1}.${EXT}

   cd ${PKGDIR}
   md5sum ${1}.${EXT} > ${1}.${EXT}.md5.txt

   rm -f ${1}.${EXT}.dep
   for each in ${DEPS}; do echo ${each} >> ${1}.${EXT}.dep; done

   size=`du -h ${1}.${EXT} | cut -f 1`

cat <<EOF> ${1}.${EXT}.info
Title:		${1}.${EXT}
Description:	${DESCRIPTION}
Version:	${VERSION}
Author:		${AUTHORS}
Original-site:	${HOMEPAGE}
Copying-policy:	${LICENSE}
Size:		${size}
Extension_by:	${ME}
Comments:	Built under Core version ${OSVERSION} from ${SRCID}
		available on Original-site
		${NAIVE}
		${RECUWARN}
		In 1968, American Type Founders produced OCR-A, 
		one of the first optical character recognition typefaces 
		to meet the criteria set by the U.S. Bureau of Standards. 
		The result was a font made up of simple, thick strokes to form recognizable characters 
		that could be deciphered by the computers of that day and by humans.
		Specified by ANSI standard X3.17-1977, approved January 20, 1977, and now available as ISO 1073-1:1976.
		The present version by Matthew Skala is newly derived in 2011 from the Wales version 
		(in the Metafont form available at http://www.ctan.org/tex-archive/fonts/ocr-a), 
		and obsoletes an earlier 2006 version from the same author.
		Not every additional ASCII glyph is supplied: notably, ^ and ~ are missing.

Change-log:	----
Current:	${TODAY} First Version
EOF
}

#here we go

environment "$1"
workit
packageit "${PACKAGE}"

