#!/bin/sh

XFS=

if [ -r /etc/sysconfig/xfs ]; then
	source /etc/sysconfig/xfs
		case "$XFS" in
			yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
				exit 0
		;;
		esac
fi

XPID=`pidof X`
FONTPATH=$1

[ -n "$FONTPATH" ] || exit 0

if [ -n "$XPID" ]; then
	for N in $XPID; do
		SERVER=`awk -F: '{print(substr($2,1,1))}' /proc/$N/cmdline`
		[ -n "$SERVER" ] || continue
		AUTH=`awk -F-auth '{print($2)}' /proc/$N/cmdline`
		[ -n "$AUTH" ] || continue
		export XAUTHORITY=$AUTH
		if xset q | grep -q "$FONTPATH"; then
			ACTION="-fp"
		else
			ACTION="fp+"
		fi
		xset -display :$SERVER $ACTION "$FONTPATH" > /dev/null 2>&1
		xdpyinfo -display :$SERVER | grep -q FontCache &&
			xset -display :$SERVER fp rehash
	done
fi
