3 export PATH=@PATH@:$PATH
5 export FONTCONFIG_FILE="@FONTCONFIG_FILE@"
6 ENCODINGSDIR="@ENCODINGSDIR@"
9 # Are we caching system fonts or user fonts?
12 # Are we including OSX font dirs ({/,~/,/System/}Library/Fonts)
15 # Do we want to force a recache?
21 # Check if the data in the given directory is newer than its cache
27 # If the dir does not exist, we just exit
28 if [[ ! -d "${dir}" ]]; then
32 # Create a list of all files in the dir
33 # Filter out config / cache files. Ugly... counting down the day until
34 # xfs finally goes away
35 fontfiles="$(find ${dir}/ -maxdepth 1 -type f | awk '$0 !~ /fonts\..*$|^.*\.dir$/ {print}')"
37 # Fonts were deleted (or never there). Kill off the caches
38 if [[ -z "${fontfiles}" ]] ; then
40 for f in "${dir}"/fonts.* "${dir}"/encodings.dir; do
41 if [[ -f ${f} ]] ; then
49 if [[ ${force} == 1 ]] ; then
53 # If we don't have our caches, we are dirty
54 if [[ ! -f "${dir}/fonts.list" || ! -f "${dir}/fonts.dir" || ! -f "${dir}/encodings.dir" ]]; then
58 # Check that no files were added or removed....
59 if [[ "${retval}" -ne 0 && "$(cat ${dir}/fonts.list)" != "${fontfiles}" ]] ; then
63 # Check that no files were updated....
64 if [[ "${retval}" -ne 0 ]] ; then
65 local changed="$(find ${dir}/ -type f -cnewer ${dir}/fonts.dir | awk '$0 !~ /fonts\..*$|^.*\.dir$/ {print}')"
67 if [[ -n "${changed}" ]] ; then
72 # Recreate fonts.list since something changed
73 if [[ "${retval}" == 0 ]] ; then
74 echo "${fontfiles}" > "${dir}"/fonts.list
82 if [[ $system == 1 ]] ; then
83 if [[ $osxfonts == 1 ]] ; then
84 find {/System/,/}Library/Fonts -type d
87 if [[ $osxfonts == 1 && -d "${HOME}/Library/Fonts" ]] ; then
88 find "${HOME}/Library/Fonts" -type d
91 if [[ -d "${HOME}/.fonts" ]] ; then
92 find "${HOME}/.fonts" -type d
104 if [[ $system == 1 ]] ; then
105 echo "font_cache: Scanning system font directories to generate X11 font caches"
107 echo "font_cache: Scanning user font directories to generate X11 font caches"
113 for x in $(get_fontdirs) ; do
114 if [[ -d "${x}" ]] && check_dirty "${x}" ; then
115 if [[ -z "${fontdirs}" ]] ; then
118 fontdirs="${fontdirs}${IFS}${x}"
123 if [[ -n "${fontdirs}" ]] ; then
124 echo "font_cache: Making fonts.dir for updated directories."
125 for x in ${fontdirs} ; do
126 if [[ $verbose == 1 ]] ; then
127 echo "font_cache: ${x}"
130 # First, generate fonts.scale for scaleable fonts that might be there
132 -a $ENCODINGSDIR/encodings.dir \
133 -a $ENCODINGSDIR/large/encodings.dir \
136 # Next, generate fonts.dir
137 if [[ $verbose == 1 ]] ; then
140 -e $ENCODINGSDIR/large \
145 -e $ENCODINGSDIR/large \
152 # Finally, update fontconfig's cache
153 echo "font_cache: Updating FC cache"
154 if [[ $system == 1 ]] ; then
156 $([[ $force == 1 ]] && echo "-f -r") \
157 $([[ $verbose == 1 ]] && echo "-v")
160 $([[ $force == 1 ]] && echo "-f -r") \
161 $([[ $verbose == 1 ]] && echo "-v")
163 echo "font_cache: Done"
167 echo "font_cache [options]"
168 echo " -f, --force : Force cache recreation"
169 echo " -n, --no-osxfonts : Just cache X11 font directories"
170 echo " (-n just pertains to XFont cache, not fontconfig)"
171 echo " -s, --system : Cache system font dirs instead of user dirs"
172 echo " -v, --verbose : Verbose Output"
176 [[ -r "${FC_LOCKFILE}" ]] && rm -f "${FC_LOCKFILE}"
180 while [[ $# -gt 0 ]] ; do
182 -s|--system) system=1 ;;
183 -f|--force) force=1 ;;
184 -v|--verbose) verbose=1 ;;
185 -n|--no-osxfonts) osxfonts=0 ;;
186 --help) do_usage ; exit 0 ;;
187 *) do_usage ; exit 1 ;;
192 if [[ $system == 1 ]] ; then
193 FC_LOCKFILE="/tmp/font_cache.$UID.lock"
194 elif [[ -w "${TMPDIR}" ]] ; then
195 FC_LOCKFILE="${TMPDIR}/font_cache.lock"
196 elif [[ -w "/tmp" ]] ; then
197 FC_LOCKFILE="/tmp/font_cache.$UID.lock"
199 FC_LOCKFILE="${HOME}/.font_cache.lock"
202 if [[ -x /usr/bin/lockfile ]] ; then
203 if /usr/bin/lockfile -r 0 -l 240 -s 4 -! "${FC_LOCKFILE}" ; then
204 echo "font_cache is already running." >&2
205 echo "If you believe this to be erroneous, please remove ${FC_LOCKFILE}." >&2
209 if [[ -r "${FC_LOCKFILE}" ]] ; then
210 read OLD_PID < "${FC_LOCKFILE}"
211 if kill -0 ${OLD_PID} >& /dev/null ; then
212 echo "font_cache is already running with PID ${OLD_PID}." >&2
213 echo "If you believe this to be erroneous, please remove ${FC_LOCKFILE}." >&2
217 echo "Removing stale ${FC_LOCKFILE}" >&2
218 rm -f "${FC_LOCKFILE}"
221 echo $$ > "${FC_LOCKFILE}"
223 if [[ ! -r "${FC_LOCKFILE}" ]] ; then
224 echo "Unable to write to ${FC_LOCKFILE}." >&2
228 # Now make sure we didn't collide mid-air
229 read OLD_PID < "${FC_LOCKFILE}"
230 if [[ $$ != ${OLD_PID} ]] ; then
231 echo "font_cache is already running with PID ${OLD_PID}." >&2
236 trap cleanup SIGINT SIGQUIT SIGABRT SIGTERM
240 rm -f "${FC_LOCKFILE}"