#!/bin/bash
#############################################################################
# This software is distributed under the terms of the General Public License.
#
# Program :         kastrolog 5.4-1.1
# Authors : see the AUTHORS file
# E-Mail  : Llyra@altavista.com
############################################################################# 

XDIR=/usr/X11R6/lib/X11/fonts/Type1
KASDIR=/opt/kde/share/apps/kastrolog

if [ -d $XDIR ]; then
    if [ "$1" = "-u" ]; then
	#gawk "! /kastrolog.pfb/ {print}"  < $XDIR/fonts.dir > /tmp/inst.$$
	#cat /tmp/inst.$$ > $XDIR/fonts.dir
	gawk "! /kastrolog.pfb/ {print}"  < $XDIR/fonts.scale > /tmp/inst.$$
	cat /tmp/inst.$$ > $XDIR/fonts.scale
	rm /tmp/inst.$$ $XDIR/kastrolog.pfb
	mkfontdir $XDIR
	xset fp rehash
    else
	if gawk "/kastrolog.pfb/ { exit 1; }" < $XDIR/fonts.dir; then
		 echo -e "\nkastrolog.pfb -adobe-astrolog-medium-r-normal--0-0-0-0-m-0-iso8859-1\n" >>  $XDIR/fonts.dir 
	fi
	if gawk "/kastrolog.pfb/ { exit 1; }" < $XDIR/fonts.scale; then
		 echo -e "\nkastrolog.pfb -adobe-astrolog-medium-r-normal--0-0-0-0-m-0-iso8859-1\n" >>  $XDIR/fonts.scale 
	fi
	cp $KASDIR/kastrolog.pfb $XDIR
	mkfontdir $XDIR
	xset fp rehash
    fi
else
	echo -e "Can't find the X11 Type 1 font directory\n"
	exit 1
fi

if   [ -d /usr/share/ghostscript/fonts ]; then
	GSDIR=/usr/share/ghostscript/fonts
elif [ -d /usr/local/share/ghostscript/fonts ]; then
	GSDIR=/usr/local/share/ghostscript/fonts
else
     echo -n "Can't find the postscript font directory\n"
     exit 1
fi
if [ "$1" = "-u" ]; then
    gawk "! /Astro/ { print}" < $GSDIR/Fontmap > /tmp/inst.$$
    cat /tmp/inst.$$ > $GSDIR/Fontmap
    rm /tmp/inst.$$ $GSDIR/kastrolog.pf{b,m}
else
    if gawk "/kastrolog.pfb/ { exit 1; }" < $GSDIR/Fontmap; then
	    echo -e "\n/Astrolog-Roman                         (kastrolog.pfb)  ;" >> $GSDIR/Fontmap
            echo -e "\n/Astro                                  /Astrolog-Roman  ;\n" >> $GSDIR/Fontmap

    fi
    cp $KASDIR/kastrolog.pf{b,m} $GSDIR
fi













