2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-11-21 12:23:08 +02:00
|
|
|
# Nerd Fonts Version: 3.1.0
|
2023-05-06 08:55:04 +02:00
|
|
|
# Script Version: 1.4.5
|
2023-04-20 16:30:55 +02:00
|
|
|
#
|
|
|
|
# You can supply options to the font-patcher via environment variable NERDFONTS
|
|
|
|
# That option will override the defaults (also defaults of THIS script).
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2020-04-12 12:51:29 +02:00
|
|
|
# used for debugging
|
|
|
|
# set -x
|
2016-11-21 02:32:03 +02:00
|
|
|
|
2017-05-14 00:02:53 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
# Check for Fontforge
|
|
|
|
type fontforge >/dev/null 2>&1 || {
|
2017-05-14 00:02:53 +02:00
|
|
|
echo >&2 "$LINE_PREFIX FontForge must be installed before running this script."
|
2016-10-29 22:45:55 +02:00
|
|
|
echo >&2 "# Please see installation instructions at"
|
|
|
|
echo >&2 "# http://designwithfontforge.com/en-US/Installing_Fontforge.html"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-07-12 17:57:35 +02:00
|
|
|
# Get script directory to set source and target dirs relative to it
|
2023-06-01 10:52:47 +02:00
|
|
|
sd="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P )"
|
2022-07-12 17:57:35 +02:00
|
|
|
|
2023-06-01 10:52:47 +02:00
|
|
|
repo_root_dir=$(dirname "$(dirname "${sd}")") # two levels up (i.e. ../../)
|
2016-10-29 22:45:55 +02:00
|
|
|
# Set source and target directories
|
2023-01-04 20:54:55 +02:00
|
|
|
like_pattern='.*\.\(otf\|ttf\|sfd\)'
|
2023-04-25 17:56:56 +02:00
|
|
|
last_font_root=""
|
2023-01-24 13:28:08 +02:00
|
|
|
unpatched_parent_dir="src/unpatched-fonts"
|
2016-10-29 22:45:55 +02:00
|
|
|
patched_parent_dir="patched-fonts"
|
2023-01-05 10:23:36 +02:00
|
|
|
timestamp_parent_dir=${patched_parent_dir}
|
2023-01-24 13:48:25 +02:00
|
|
|
source_fonts_dir="${repo_root_dir}/${unpatched_parent_dir}"
|
2023-01-05 18:42:30 +02:00
|
|
|
max_parallel_process=8
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-01-05 10:23:36 +02:00
|
|
|
function activate_keeptime {
|
|
|
|
type ttfdump >/dev/null 2>&1 || {
|
|
|
|
echo >&2 "$LINE_PREFIX ttfdump must be installed for option --keeptime"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
keeptime=TRUE
|
|
|
|
}
|
|
|
|
|
|
|
|
function activate_checkfont {
|
|
|
|
patched_parent_dir="check-fonts"
|
|
|
|
}
|
|
|
|
|
|
|
|
function activate_info {
|
2023-01-15 22:22:14 +02:00
|
|
|
info_only=TRUE
|
2023-01-05 10:23:36 +02:00
|
|
|
echo "${LINE_PREFIX} 'Info Only' option given, only generating font info (not patching)"
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_help {
|
|
|
|
echo "Usage: $0 [OPTION] [FILTER]"
|
|
|
|
echo
|
|
|
|
echo " OPTION:"
|
|
|
|
echo " -c, --checkfont Create the font(s) in check-fonts/ instead"
|
|
|
|
echo " -t, --keeptime Try to preserve timestamp of previously patched"
|
|
|
|
echo " font in patched-fonts/ directory"
|
2023-01-05 16:13:40 +02:00
|
|
|
echo " -v, --verbose Show more information when running"
|
2023-01-05 10:23:36 +02:00
|
|
|
echo " -i, --info Rebuild JUST the readmes"
|
2023-01-05 18:42:30 +02:00
|
|
|
echo " -j, --jobs Run up to 8 patch processes in parallel"
|
2023-01-05 10:23:36 +02:00
|
|
|
echo " -h, --help Show this help"
|
|
|
|
echo
|
|
|
|
echo " FILTER:"
|
|
|
|
echo " The filter argument to this script is a filter for the fonts to patch."
|
|
|
|
echo " The filter is a regex (glob "*" is expressed as "[^/]*", see \`man 7 glob\`)"
|
|
|
|
echo " All font files that start with that filter (and are ttf, otf, or sfd files) will"
|
|
|
|
echo " be processed only."
|
|
|
|
echo " Example ./gotta-patch-em-all-font-patcher\!.sh \"iosevka\""
|
|
|
|
echo " Process all font files that start with \"iosevka\""
|
|
|
|
echo " If the argument starts with a '/' all font files in a directory that matches"
|
|
|
|
echo " the filter are processed only."
|
|
|
|
echo " Example ./gotta-patch-em-all-font-patcher\!.sh \"/iosevka\""
|
|
|
|
echo " Process all font files that are in directory \"iosevka\""
|
|
|
|
}
|
|
|
|
|
2023-01-24 14:22:18 +02:00
|
|
|
function find_font_root {
|
|
|
|
# e.g. /a/b/c/nerd-fonts/src/unpatched-fonts/Meslo
|
|
|
|
sed -E "s|(${unpatched_parent_dir}/[^/]*).*|\1|" <<< "$1"
|
|
|
|
}
|
|
|
|
|
2023-01-05 18:42:30 +02:00
|
|
|
while getopts ":chijtv-:" option; do
|
2023-01-04 21:08:14 +02:00
|
|
|
case "${option}" in
|
2023-01-05 10:23:36 +02:00
|
|
|
c)
|
|
|
|
activate_checkfont
|
|
|
|
;;
|
2023-01-04 21:08:14 +02:00
|
|
|
h)
|
2023-01-05 10:23:36 +02:00
|
|
|
show_help
|
2023-01-04 21:08:14 +02:00
|
|
|
exit 0;;
|
2023-01-05 10:23:36 +02:00
|
|
|
i)
|
|
|
|
activate_info
|
|
|
|
;;
|
2023-01-05 18:42:30 +02:00
|
|
|
j)
|
|
|
|
parallel=TRUE
|
|
|
|
;;
|
2023-01-05 10:23:36 +02:00
|
|
|
t)
|
|
|
|
activate_keeptime
|
|
|
|
;;
|
2023-01-05 16:13:40 +02:00
|
|
|
v)
|
|
|
|
verbose=TRUE
|
|
|
|
;;
|
2023-01-04 21:08:14 +02:00
|
|
|
-)
|
|
|
|
case "${OPTARG}" in
|
2023-01-05 16:13:40 +02:00
|
|
|
checkfont)
|
|
|
|
activate_checkfont
|
|
|
|
;;
|
2023-01-12 15:11:40 +02:00
|
|
|
help)
|
|
|
|
show_help
|
|
|
|
exit 0;;
|
2023-01-04 21:08:14 +02:00
|
|
|
info)
|
2023-01-05 10:23:36 +02:00
|
|
|
activate_info
|
|
|
|
;;
|
2023-01-05 18:42:30 +02:00
|
|
|
jobs)
|
|
|
|
parallel=TRUE
|
|
|
|
;;
|
2023-01-05 10:23:36 +02:00
|
|
|
keeptime)
|
|
|
|
activate_keeptime
|
|
|
|
;;
|
2023-01-05 16:13:40 +02:00
|
|
|
verbose)
|
|
|
|
verbose=TRUE
|
2023-01-04 21:08:14 +02:00
|
|
|
;;
|
|
|
|
*)
|
2023-01-05 10:23:36 +02:00
|
|
|
echo >&2 "Option '--${OPTARG}' unknown"
|
2023-01-04 21:08:14 +02:00
|
|
|
exit 1;;
|
|
|
|
esac;;
|
|
|
|
*)
|
2023-01-05 10:23:36 +02:00
|
|
|
echo >&2 "Option '-${OPTARG}' unknown"
|
2023-01-04 21:08:14 +02:00
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
2023-06-01 10:52:47 +02:00
|
|
|
shift $((OPTIND-1))
|
2023-01-04 21:08:14 +02:00
|
|
|
|
|
|
|
if [ $# -gt 1 ]
|
|
|
|
then
|
2023-01-05 10:23:36 +02:00
|
|
|
echo >&2 "Unknown parameter(s): $2 ..."
|
2023-01-04 21:08:14 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -eq 1 ]
|
2022-04-22 13:32:30 +02:00
|
|
|
then
|
|
|
|
if [[ "${1:0:1}" == "/" ]]
|
2016-10-29 22:45:55 +02:00
|
|
|
then
|
2022-03-03 17:03:10 +02:00
|
|
|
like_pattern=".*$1/.*\.\(otf\|ttf\|sfd\)"
|
2023-01-04 21:08:14 +02:00
|
|
|
echo "$LINE_PREFIX Filter given, limiting search and patch to pathname pattern '$1'"
|
2022-04-22 13:32:30 +02:00
|
|
|
else
|
2022-03-03 17:03:10 +02:00
|
|
|
like_pattern=".*/$1[^/]*\.\(otf\|ttf\|sfd\)"
|
2023-01-04 21:08:14 +02:00
|
|
|
echo "$LINE_PREFIX Filter given, limiting search and patch to filename pattern '$1'"
|
2022-04-22 13:32:30 +02:00
|
|
|
fi
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# correct way to output find results into an array (when files have space chars, etc)
|
2017-07-28 22:29:44 +02:00
|
|
|
# source: https://stackoverflow.com/questions/8213328/bash-script-find-output-to-array
|
2016-10-29 22:45:55 +02:00
|
|
|
source_fonts=()
|
2020-04-12 12:52:31 +02:00
|
|
|
while IFS= read -d $'\0' -r file ; do
|
|
|
|
source_fonts=("${source_fonts[@]}" "$file")
|
2023-06-01 10:52:47 +02:00
|
|
|
done < <(find "$source_fonts_dir" -iregex "${like_pattern}" -type f -print0)
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
# print total number of source fonts found
|
2017-05-14 00:02:53 +02:00
|
|
|
echo "$LINE_PREFIX Total source fonts found: ${#source_fonts[*]}"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-01-04 21:30:21 +02:00
|
|
|
# Use one date-time for ALL fonts and for creation and modification date in the font file
|
|
|
|
if [ -z "${SOURCE_DATE_EPOCH}" ]
|
|
|
|
then
|
|
|
|
export SOURCE_DATE_EPOCH=$(date +%s)
|
|
|
|
fi
|
2023-06-01 10:52:47 +02:00
|
|
|
release_timestamp=$(date -R "--date=@${SOURCE_DATE_EPOCH}" 2>/dev/null) || {
|
2023-01-04 21:30:21 +02:00
|
|
|
echo >&2 "$LINE_PREFIX Invalid release timestamp SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH}"
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
echo "$LINE_PREFIX Release timestamp is ${release_timestamp}"
|
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
function patch_font {
|
|
|
|
local f=$1; shift
|
2016-11-21 02:32:03 +02:00
|
|
|
local i=$1; shift
|
2022-02-16 09:59:23 +02:00
|
|
|
local purge=$1; shift
|
2023-01-05 10:23:36 +02:00
|
|
|
|
|
|
|
# Try to copy the release date from the 'original' patch
|
|
|
|
if [ -n "${keeptime}" ]
|
|
|
|
then
|
|
|
|
# take everything before the last slash (/) to start building the full path
|
|
|
|
local ts_font_dir="${f%/*}/"
|
|
|
|
local ts_font_dir="${ts_font_dir/$unpatched_parent_dir/$timestamp_parent_dir}"
|
2023-06-01 10:52:47 +02:00
|
|
|
local one_font=$(find "${ts_font_dir}" -name '*.[ot]tf' | head -n 1)
|
2023-01-05 10:23:36 +02:00
|
|
|
if [ -n "${one_font}" ]
|
|
|
|
then
|
|
|
|
orig_font_date=$(ttfdump -t head "${one_font}" | \
|
|
|
|
grep -E '[^a-z]modified:.*0x' | sed 's/.*x//' | tr 'a-f' 'A-F')
|
|
|
|
SOURCE_DATE_EPOCH=$(dc -e "16i ${orig_font_date} Ai 86400 24107 * - p")
|
2023-06-01 10:52:47 +02:00
|
|
|
echo "$LINE_PREFIX Release timestamp adjusted to $(date -R "--date=@${SOURCE_DATE_EPOCH}")"
|
2023-01-05 10:23:36 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-11-01 04:01:00 +02:00
|
|
|
# take everything before the last slash (/) to start building the full path
|
2016-10-29 22:45:55 +02:00
|
|
|
local patched_font_dir="${f%/*}/"
|
|
|
|
# find replace unpatched parent dir with patched parent dir:
|
|
|
|
local patched_font_dir="${patched_font_dir/$unpatched_parent_dir/$patched_parent_dir}"
|
2016-11-01 04:01:00 +02:00
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
|
2023-04-30 13:24:37 +02:00
|
|
|
if [ -n "${purge}" ]
|
2022-02-16 09:59:23 +02:00
|
|
|
then
|
2023-01-05 16:13:40 +02:00
|
|
|
if [ -n "${verbose}" ]
|
|
|
|
then
|
2023-04-28 11:42:12 +02:00
|
|
|
echo "Purging patched font dir ${patched_font_dir}"
|
2023-01-05 16:13:40 +02:00
|
|
|
fi
|
2023-06-01 10:52:47 +02:00
|
|
|
rm -- "${patched_font_dir}"/*
|
2022-02-16 09:59:23 +02:00
|
|
|
fi
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd)
|
|
|
|
config_dir=$( cd "$( dirname "$f" )" && pwd)
|
|
|
|
|
|
|
|
# source the font config file if exists:
|
2022-01-10 09:35:38 +02:00
|
|
|
# fetches for example config_patch_flags
|
2023-05-12 08:53:27 +02:00
|
|
|
unset config_patch_flags
|
2016-10-29 22:45:55 +02:00
|
|
|
if [ -f "$config_dir/config.cfg" ]
|
|
|
|
then
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-10-29 22:45:55 +02:00
|
|
|
source "$config_dir/config.cfg"
|
|
|
|
elif [ -f "$config_parent_dir/config.cfg" ]
|
|
|
|
then
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-10-29 22:45:55 +02:00
|
|
|
source "$config_parent_dir/config.cfg"
|
2023-06-01 10:52:47 +02:00
|
|
|
elif [ -f "$(find_font_root "$config_parent_dir")/config.cfg" ]
|
2023-01-26 19:57:16 +02:00
|
|
|
then
|
|
|
|
# shellcheck source=/dev/null
|
2023-06-01 10:52:47 +02:00
|
|
|
source "$(find_font_root "$config_parent_dir")/config.cfg"
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
2018-02-26 04:52:36 +02:00
|
|
|
if [ -f "$config_parent_dir/config.json" ]
|
|
|
|
then
|
|
|
|
# load font configuration file and remove ligatures (for mono fonts):
|
|
|
|
font_config="--removeligatures --configfile $config_parent_dir/config.json"
|
|
|
|
else
|
|
|
|
font_config=""
|
|
|
|
fi
|
|
|
|
|
2016-12-15 04:50:36 +02:00
|
|
|
if [ "$post_process" ]
|
|
|
|
then
|
2023-04-25 08:56:09 +02:00
|
|
|
# There is no postprocess active anymore, see the commit that introduced
|
|
|
|
# this comment for the Hack postprocess we once had. It called e.g. ttfautohint.
|
2023-01-24 13:48:25 +02:00
|
|
|
post_process="--postprocess=${repo_root_dir}/${post_process}"
|
2016-12-15 04:50:36 +02:00
|
|
|
else
|
|
|
|
post_process=""
|
|
|
|
fi
|
|
|
|
|
2023-01-24 13:48:25 +02:00
|
|
|
cd "$repo_root_dir" || {
|
2016-11-06 18:29:35 +02:00
|
|
|
echo >&2 "# Could not find project parent directory"
|
2023-01-04 21:08:14 +02:00
|
|
|
exit 3
|
2016-11-06 18:29:35 +02:00
|
|
|
}
|
2023-05-06 08:55:04 +02:00
|
|
|
# Add logfile always (but can be overridden by config_patch_flags in config.cfg and env var NERDFONTS)
|
|
|
|
config_patch_flags="--debug 1 ${config_patch_flags}"
|
2022-08-19 12:57:42 +02:00
|
|
|
# Use absolute path to allow fontforge being an AppImage (used in CI)
|
2023-06-01 10:52:47 +02:00
|
|
|
PWD=$(pwd)
|
2023-04-20 16:30:55 +02:00
|
|
|
# Create "Nerd Font"
|
2023-01-05 16:13:40 +02:00
|
|
|
if [ -n "${verbose}" ]
|
|
|
|
then
|
2023-06-01 10:52:47 +02:00
|
|
|
echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}"
|
2023-01-05 16:13:40 +02:00
|
|
|
fi
|
2023-06-01 10:52:47 +02:00
|
|
|
# shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them
|
|
|
|
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q ${font_config} $post_process -c --no-progressbars \
|
2023-04-28 11:42:12 +02:00
|
|
|
--outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
|
2023-06-01 10:52:47 +02:00
|
|
|
# shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block
|
|
|
|
if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi
|
2023-04-20 16:30:55 +02:00
|
|
|
# Create "Nerd Font Mono"
|
2023-01-05 16:13:40 +02:00
|
|
|
if [ -n "${verbose}" ]
|
|
|
|
then
|
2023-06-01 10:52:47 +02:00
|
|
|
echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q -s ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}"
|
2023-01-05 16:13:40 +02:00
|
|
|
fi
|
2023-06-01 10:52:47 +02:00
|
|
|
# shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them
|
|
|
|
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q -s ${font_config} $post_process -c --no-progressbars \
|
2023-04-28 11:42:12 +02:00
|
|
|
--outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
|
2023-06-01 10:52:47 +02:00
|
|
|
# shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block
|
|
|
|
if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi
|
2023-04-20 16:30:55 +02:00
|
|
|
# Create "Nerd Font Propo"
|
|
|
|
if [ -n "${verbose}" ]
|
|
|
|
then
|
2023-06-01 10:52:47 +02:00
|
|
|
echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q --variable ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}"
|
2023-04-20 16:30:55 +02:00
|
|
|
fi
|
2023-06-01 10:52:47 +02:00
|
|
|
# shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them
|
|
|
|
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q --variable ${font_config} $post_process -c --no-progressbars \
|
2023-04-28 11:42:12 +02:00
|
|
|
--outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
|
2023-06-01 10:52:47 +02:00
|
|
|
# shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block
|
|
|
|
if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi
|
2023-04-25 17:56:56 +02:00
|
|
|
|
2016-11-06 18:29:35 +02:00
|
|
|
# wait for this group of background processes to finish to avoid forking too many processes
|
|
|
|
# that can add up quickly with the number of combinations
|
2016-10-29 22:45:55 +02:00
|
|
|
#wait
|
|
|
|
|
2016-11-21 02:32:03 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 12:52:31 +02:00
|
|
|
# Generates font information: readmes, combinations, licenses, and variation counts
|
|
|
|
# $1 = fontdir path
|
|
|
|
# $2 = font file name (used for metadata)
|
2016-11-21 02:32:03 +02:00
|
|
|
function generate_info {
|
|
|
|
local f=$1; shift
|
2020-04-12 12:52:31 +02:00
|
|
|
local font_file=$1; shift
|
2023-04-25 17:56:56 +02:00
|
|
|
|
2016-11-21 02:32:03 +02:00
|
|
|
# take everything before the last slash (/) to start building the full path
|
|
|
|
local patched_font_dir="${f%/*}/"
|
|
|
|
# find replace unpatched parent dir with patched parent dir:
|
|
|
|
local patched_font_dir="${patched_font_dir/$unpatched_parent_dir/$patched_parent_dir}"
|
|
|
|
|
2020-04-12 12:52:31 +02:00
|
|
|
echo "$LINE_PREFIX Generating info for '$font_file':"
|
|
|
|
|
2016-11-21 02:32:03 +02:00
|
|
|
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
|
|
|
|
|
2023-04-25 17:56:56 +02:00
|
|
|
local font_root=$(echo "$patched_font_dir" | sed "s|.*$patched_parent_dir/||;s|/.*||")
|
2016-10-29 22:45:55 +02:00
|
|
|
# if first time with this font then re-build parent dir readme, else skip:
|
2023-04-25 17:56:56 +02:00
|
|
|
if [ "$last_font_root" != "$font_root" ]
|
2016-10-29 22:45:55 +02:00
|
|
|
then
|
2023-04-25 17:56:56 +02:00
|
|
|
echo "$LINE_PREFIX --- Calling standardize-and-complete-readmes for $font_root"
|
2023-06-01 10:52:47 +02:00
|
|
|
"${sd}/standardize-and-complete-readmes.sh" "$font_root" "$patched_parent_dir"
|
2023-04-25 17:56:56 +02:00
|
|
|
echo "$LINE_PREFIX ---"
|
|
|
|
last_font_root=$font_root
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
2023-04-25 17:56:56 +02:00
|
|
|
# Copy 'all' license files found in the complete font`s source tree
|
2023-01-24 14:22:18 +02:00
|
|
|
# into the destination. This will overwrite all same-names files
|
|
|
|
# so make sure all licenses of one fontface are identical
|
2023-04-25 17:56:56 +02:00
|
|
|
echo "$LINE_PREFIX * Copying license files"
|
2023-06-01 10:52:47 +02:00
|
|
|
current_dir=$(dirname "$f")
|
|
|
|
copy_license "$(find_font_root "$current_dir")" "$patched_font_dir"
|
2016-10-29 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 12:52:31 +02:00
|
|
|
|
|
|
|
# Copy any license file to the patched font directory
|
|
|
|
# $1 = fontdir source path
|
|
|
|
# $2 = fontdir destination path
|
|
|
|
function copy_license {
|
|
|
|
local src=$1
|
|
|
|
local dest=$2
|
|
|
|
local license_file=""
|
|
|
|
|
|
|
|
while IFS= read -d $'\0' -r license_file ; do
|
2023-04-28 11:42:12 +02:00
|
|
|
[[ -d "$dest" ]] || mkdir -p "$dest"
|
|
|
|
cp "$license_file" -t "$dest"
|
2023-01-26 09:21:28 +02:00
|
|
|
done < <(find "$src" -iregex ".*\(licen[cs]e\|ofl\).*" -type f -print0)
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-25 17:56:56 +02:00
|
|
|
# To check which files will or will not be copied and make sure all relevant
|
|
|
|
# licences do match
|
|
|
|
# find src/unpatched-fonts -not -iname "*.[ot]tf" -type f -not -name 'README.md' -not -name 'config.cfg' -iregex ".*\(licen[cs]e\|ofl\).*"
|
|
|
|
# find src/unpatched-fonts -not -iname "*.[ot]tf" -type f -not -name 'README.md' -not -name 'config.cfg' -not -iregex ".*\(licen[cs]e\|ofl\).*"
|
2016-10-29 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
2018-01-13 05:20:52 +02:00
|
|
|
if [ ! "$info_only" ]
|
2016-11-21 02:32:03 +02:00
|
|
|
then
|
|
|
|
# Iterate through source fonts
|
|
|
|
for i in "${!source_fonts[@]}"
|
|
|
|
do
|
2022-02-16 09:59:23 +02:00
|
|
|
purge_destination=""
|
2022-08-20 19:27:57 +02:00
|
|
|
current_source_dir=$(dirname "${source_fonts[$i]}")
|
2022-02-16 09:59:23 +02:00
|
|
|
if [ "${current_source_dir}" != "${last_source_dir}" ]
|
|
|
|
then
|
|
|
|
# If we are going to patch ALL font files from a certain source directory
|
|
|
|
# the destination directory is purged (all font files therein deleted)
|
|
|
|
# to follow font naming changed. We can not do this if we patch only
|
|
|
|
# some of the source font files in that directory.
|
|
|
|
last_source_dir=${current_source_dir}
|
2023-06-01 10:52:47 +02:00
|
|
|
num_to_patch=$(find "${current_source_dir}" -iregex "${like_pattern}" -type f | wc -l)
|
2023-01-26 09:21:28 +02:00
|
|
|
num_existing=$(find "${current_source_dir}" -iname "*.[ot]tf" -o -iname "*.sfd" -type f | wc -l)
|
2023-06-01 10:52:47 +02:00
|
|
|
if [ "${num_to_patch}" -eq "${num_existing}" ]
|
2022-02-16 09:59:23 +02:00
|
|
|
then
|
|
|
|
purge_destination="TRUE"
|
|
|
|
fi
|
|
|
|
fi
|
2023-01-05 16:13:40 +02:00
|
|
|
echo "$LINE_PREFIX Processing font $((i+1))/${#source_fonts[@]}"
|
2023-01-05 18:42:30 +02:00
|
|
|
if [ -n "${parallel}" ]
|
|
|
|
then
|
|
|
|
patch_font "${source_fonts[$i]}" "$i" "$purge_destination" 2>/dev/null &
|
|
|
|
else
|
|
|
|
patch_font "${source_fonts[$i]}" "$i" "$purge_destination" 2>/dev/null
|
|
|
|
fi
|
2022-02-16 09:59:23 +02:00
|
|
|
|
2016-11-21 02:32:03 +02:00
|
|
|
|
|
|
|
# un-comment to test this script (patch 1 font)
|
|
|
|
#break
|
|
|
|
|
|
|
|
# wait for this set of bg commands to finish: dont do too many at once!
|
|
|
|
# if we spawn a background process for each set of fonts it will
|
|
|
|
# end up using too many system resources
|
|
|
|
# however we want to run a certain number in parallel to decrease
|
|
|
|
# the amount of time patching all the fonts will take
|
|
|
|
# for now set a 'wait' for each X set of processes:
|
2023-01-05 18:42:30 +02:00
|
|
|
if [[ $(((i + 1) % max_parallel_process)) == 0 ]];
|
2016-11-21 02:32:03 +02:00
|
|
|
then
|
|
|
|
wait
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# wait for all bg commands to finish
|
|
|
|
wait
|
|
|
|
fi
|
|
|
|
|
|
|
|
# update information in separate iteration (to avoid issues with bg processes and the counts):
|
2016-11-07 00:04:53 +02:00
|
|
|
# Iterate through source fonts
|
|
|
|
for i in "${!source_fonts[@]}"
|
2016-10-29 22:45:55 +02:00
|
|
|
do
|
2017-07-29 19:50:37 +02:00
|
|
|
# only output after last slash (/):
|
|
|
|
path=${source_fonts[$i]}
|
|
|
|
font_file=${path##*/}
|
2020-04-12 12:52:31 +02:00
|
|
|
generate_info "$path" "$font_file" 2>/dev/null
|
2016-10-29 22:45:55 +02:00
|
|
|
done
|