#!/bin/sh

# SPDX-FileCopyrightText: 2009 Craig Drummond <craig@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later

if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
    echo "KDE Font Installer helper application - used to configure X11 font folders."
    echo ""
    echo "Usage: $1 <folder> [<folder> ... <folder>]"
fi

IFS="
"

suffix=".fontinst-$$"

for d in $* ; do
    for f in fonts.scale fonts.dir ; do
        # Call standard xorg app...
        if [ "$f" = "fonts.scale" ] ; then
            mkfontscale "$d"
        else
            mkfontdir "$d"
        fi

        if [ -f "$d/$f" ] ; then
            # Remove any disabled (ie. hidden) fonts
            egrep "\-" "$d/$f" | egrep "^[^\.]" > "$d/$f$suffix"
            wc -l "$d/$f$suffix" | awk '{print $1}' > "$d/$f"
            cat "$d/$f$suffix" >> "$d/$f"
            rm "$d/$f$suffix"
        fi
    done
done

# Tell X to refresh its font list
xset fp rehash
