Source
# Copyright (c) 2008-2010 Apple Inc. All Rights Reserved.
#
# @APPLE_LICENSE_HEADER_START@
#
# This file contains Original Code and/or Modifications of Original Code
# as defined in and that are subject to the Apple Public Source License
# Version 2.0 (the 'License'). You may not use this file except in
# compliance with the License. Please obtain a copy of the License at
# http://www.opensource.apple.com/apsl/ and read it before using this
# file.
#
# The Original Code and all software distributed under the License are
# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
# Please see the License for the specific language governing rights and
# limitations under the License.
#
# @APPLE_LICENSE_HEADER_END@
X11DIR=__PREFIX__
X11FONTDIR=${X11DIR}/share/fonts
FC_LOCKFILE=""
# Are we caching system fonts or user fonts?
system=0
# Are we including OSX font dirs ({/,~/,/System/}Library/Fonts)
osxfonts=1
# Do we want to force a recache?
force=0
# How noisy are we?
verbose=0
# Check if the data in the given directory is newer than its cache
check_dirty() {
local dir=$1
local fontfiles=""
local retval=1
# If the dir does not exist, we just exit
if [[ ! -d "${dir}" ]]; then
return 1
fi
# Create a list of all files in the dir
# Filter out config / cache files. Ugly... counting down the day until
# xfs finally goes away
fontfiles="$(find ${dir}/ -maxdepth 1 -type f | awk '$0 !~ /fonts\..*$|^.*\.dir$/ {print}')"
# Fonts were deleted (or never there). Kill off the caches
if [[ -z "${fontfiles}" ]] ; then
local f
for f in "${dir}"/fonts.* "${dir}"/encodings.dir; do
if [[ -f ${f} ]] ; then
rm -f "${f}"
fi
done
return 1
fi
# Force a recache
if [[ ${force} == 1 ]] ; then
retval=0
fi
# If we don't have our caches, we are dirty
if [[ ! -f "${dir}/fonts.list" || ! -f "${dir}/fonts.dir" || ! -f "${dir}/encodings.dir" ]]; then
retval=0
fi
# Check that no files were added or removed....
if [[ "${retval}" -ne 0 && "$(cat ${dir}/fonts.list)" != "${fontfiles}" ]] ; then
retval=0
fi
# Check that no files were updated....
if [[ "${retval}" -ne 0 ]] ; then
local changed="$(find ${dir}/ -type f -cnewer ${dir}/fonts.dir | awk '$0 !~ /fonts\..*$|^.*\.dir$/ {print}')"
if [[ -n "${changed}" ]] ; then
retval=0
fi
fi
# Recreate fonts.list since something changed
if [[ "${retval}" == 0 ]] ; then