2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-06-04 22:32:30 +02:00
|
|
|
# Nerd Fonts Version: 3.0.2
|
2023-06-02 12:30:27 +02:00
|
|
|
# Script Version: 1.2.0
|
2016-11-13 19:25:35 +02:00
|
|
|
# Iterates over all patched fonts directories
|
2023-06-02 12:29:26 +02:00
|
|
|
# to generate release archives of the patched font(s)
|
2023-06-05 21:01:23 +02:00
|
|
|
# Set RELEASE_VERSION to attribute a specific release
|
2023-06-02 12:29:26 +02:00
|
|
|
#
|
2020-04-13 11:41:52 +02:00
|
|
|
# Example run with pattern matching:
|
|
|
|
# ./archive-fonts heavydata
|
2020-04-13 12:36:17 +02:00
|
|
|
# Example with same font names for different paths
|
|
|
|
# ./archive-fonts gohu
|
2016-11-13 19:25:35 +02:00
|
|
|
|
2023-04-30 21:00:46 +02:00
|
|
|
set -e
|
|
|
|
|
2017-01-16 00:23:30 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2023-06-02 12:30:27 +02:00
|
|
|
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null 2>&1 || exit && pwd -P)"
|
2023-06-02 12:52:53 +02:00
|
|
|
outputdir=${root_dir}/archives
|
2023-06-05 21:01:23 +02:00
|
|
|
if [ -n "${RELEASE_VERSION}" ]; then
|
|
|
|
release_txt="the Nerd Fonts release v${RELEASE_VERSION}"
|
|
|
|
else
|
|
|
|
echo "${LINE_PREFIX} Do not have release version information, using generic readme"
|
|
|
|
release_txt="a Nerd Fonts release"
|
|
|
|
fi
|
2017-01-16 00:23:30 +02:00
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
mkdir -p "$outputdir"
|
|
|
|
|
2023-06-02 12:52:53 +02:00
|
|
|
cd "${root_dir}/patched-fonts/" || {
|
2023-06-02 12:29:26 +02:00
|
|
|
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
|
|
|
|
exit 1
|
2016-11-13 19:25:35 +02:00
|
|
|
}
|
|
|
|
|
2017-01-16 00:23:30 +02:00
|
|
|
# limit archiving to given pattern (first script param) or entire root folder if no param given:
|
2023-06-02 12:29:26 +02:00
|
|
|
if [ $# -eq 1 ]; then
|
2019-11-21 17:05:58 +02:00
|
|
|
pattern=$1
|
2023-06-02 12:30:27 +02:00
|
|
|
search_pattern=$1
|
2018-04-01 22:30:03 +02:00
|
|
|
echo "$LINE_PREFIX Limiting archive to pattern '$pattern'"
|
2017-01-16 00:23:30 +02:00
|
|
|
else
|
2019-11-21 17:05:58 +02:00
|
|
|
pattern=".*"
|
2023-06-02 12:30:27 +02:00
|
|
|
search_pattern=""
|
2019-11-21 17:05:58 +02:00
|
|
|
echo "$LINE_PREFIX No limiting pattern given, will search entire folder"
|
2017-01-16 00:23:30 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-02 12:30:27 +02:00
|
|
|
# clear out the directory
|
2023-06-02 19:05:25 +02:00
|
|
|
find "${outputdir:?}" -maxdepth 1 \( -name "${search_pattern}.zip" -o -name "${search_pattern}.tar.xz" \) -type f -delete
|
2018-04-01 17:29:01 +02:00
|
|
|
|
2023-06-02 12:29:26 +02:00
|
|
|
find . -maxdepth 1 -iregex "\./$pattern" -type d | sort |
|
|
|
|
while read -r filename; do
|
|
|
|
basename=$(basename "$filename")
|
|
|
|
searchdir=$filename
|
2016-11-13 19:25:35 +02:00
|
|
|
|
2023-06-02 12:29:26 +02:00
|
|
|
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
|
2016-11-13 19:25:35 +02:00
|
|
|
|
2023-06-02 12:30:27 +02:00
|
|
|
rm -f "${outputdir}/${basename}.tar"
|
|
|
|
expected=$(find "${searchdir}" -iname "*.[ot]tf" -exec echo "+" \; | wc -l)
|
|
|
|
echo "${LINE_PREFIX} Packing ${basename}.tar.xz (${expected} fonts)"
|
|
|
|
# This finds all files, uniq on the filename (ignoring path):
|
2023-06-02 19:05:25 +02:00
|
|
|
# shellcheck disable=SC2156 # It's hard enough with injection
|
2023-06-02 12:30:27 +02:00
|
|
|
while IFS= read -d $'\0' -r descriptor; do
|
2023-06-02 19:05:25 +02:00
|
|
|
path=${descriptor//|*/}
|
|
|
|
file=${descriptor//*|/}
|
2023-06-05 21:01:23 +02:00
|
|
|
if [ "$file" = "README.md" ]; then
|
|
|
|
{
|
|
|
|
echo "# Nerd Fonts"
|
|
|
|
echo
|
|
|
|
echo "This is an archived font from ${release_txt}."
|
|
|
|
echo
|
|
|
|
echo "For more information see:"
|
|
|
|
echo "* https://github.com/ryanoasis/nerd-fonts/"
|
|
|
|
echo "* https://github.com/ryanoasis/nerd-fonts/releases/latest/"
|
|
|
|
echo
|
|
|
|
} > "${outputdir}/${file}"
|
|
|
|
cat "${path}/${file}" >> "${outputdir}/${file}"
|
|
|
|
continue
|
|
|
|
fi
|
2023-06-02 19:05:25 +02:00
|
|
|
if grep -qi '.[ot]tf' <<< "${file}" ; then
|
2023-06-02 12:30:27 +02:00
|
|
|
expected=$((expected - 1))
|
|
|
|
fi
|
|
|
|
# Need to cd to the file because we want to archive 'flat' (without subdirs):
|
2023-06-02 19:05:25 +02:00
|
|
|
(cd "$path" && tar rf "$outputdir/$basename.tar" --no-recursion "$file")
|
2023-06-02 12:30:27 +02:00
|
|
|
done < <(find "${searchdir}" -type f -exec bash -c 'printf "%s\000" "{}" | sed "s!\(.*\)/!\1|!"' \; | sort -z -u '-t|' -k2,2 | sort -z)
|
2016-11-13 19:25:35 +02:00
|
|
|
|
2023-06-02 12:30:27 +02:00
|
|
|
if [ $expected -ne 0 ]; then
|
|
|
|
# Should never happen, but who knows
|
|
|
|
echo "${LINE_PREFIX} Did not pack expected number of font files! Likely same font names for different paths."
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-05 21:01:23 +02:00
|
|
|
(cd "${outputdir}" && tar rf "${outputdir}/${basename}.tar" "README.md")
|
2023-06-02 12:30:27 +02:00
|
|
|
xz -f -9 -T0 "${outputdir}/${basename}.tar"
|
2020-04-13 11:41:52 +02:00
|
|
|
|
2023-06-02 12:29:26 +02:00
|
|
|
# ZIP stuff:
|
|
|
|
# add font files:
|
|
|
|
# -ic (ignore case not working)
|
|
|
|
echo "${LINE_PREFIX} Packing ${basename}.zip"
|
|
|
|
zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -q
|
|
|
|
zipStatus=$?
|
|
|
|
if [ "$zipStatus" != "0" ]; then
|
|
|
|
echo "$LINE_PREFIX Could not create archive with the path junked (-j option) - likely same font names for different paths, zip status: $zipStatus"
|
|
|
|
echo "$LINE_PREFIX Retrying with full path"
|
|
|
|
# add font files and license files as full paths:
|
|
|
|
zip -9 "$outputdir/$basename" -r "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -i '*[Ll]icen[sc]e*' -i '*LICEN[SC]E*' -i 'OFL*' -i 'ofl*' -q
|
|
|
|
else
|
|
|
|
# we can copy the font files without full paths but not necessarily the license files:
|
|
|
|
# add license files separately:
|
|
|
|
# zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*license*' -i '*LICENSE*'
|
|
|
|
# work around to copy duplicate license files (only the last duplicate found)
|
|
|
|
# so we don't have to copy entire paths and can still use the junk option (-j)
|
|
|
|
find "$searchdir" -type f -iname "*licen[sc]e*" -o -iname 'ofl*' | awk -F/ '{a[$NF]=$0}END{for(i in a)print a[i]}' | zip -9 -j "$outputdir/$basename" -@
|
|
|
|
fi;
|
|
|
|
|
2023-06-05 21:01:23 +02:00
|
|
|
# add readme file
|
|
|
|
(cd "${outputdir}" && zip -9 "$outputdir/$basename" -j "README.md" -q)
|
2016-11-13 19:25:35 +02:00
|
|
|
done
|
2021-11-21 17:29:23 +02:00
|
|
|
|
2023-06-05 21:01:23 +02:00
|
|
|
rm -f "${outputdir}/README.md"
|
2022-08-25 08:04:14 +02:00
|
|
|
ls -al "$outputdir"
|