2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-01-17 21:02:09 +02:00
|
|
|
# Nerd Fonts Version: 2.3.0
|
2022-08-25 08:04:14 +02:00
|
|
|
# Script Version: 1.1.2
|
2016-11-13 19:25:35 +02:00
|
|
|
# Iterates over all patched fonts directories
|
|
|
|
# to generate ruby cask files for homebrew-fonts (https://github.com/caskroom/homebrew-fonts)
|
2016-12-03 06:03:07 +02:00
|
|
|
# adds Windows versions of the fonts as well (casks files just won't download them)
|
2020-04-13 11:41:52 +02:00
|
|
|
# used for debugging
|
2020-04-13 12:36:17 +02:00
|
|
|
# set -x
|
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
|
|
|
|
2017-01-16 00:23:30 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2018-04-01 17:29:01 +02:00
|
|
|
scripts_root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
|
2020-04-13 12:36:17 +02:00
|
|
|
parent_dir="${PWD}/../../"
|
2018-04-01 17:29:01 +02:00
|
|
|
echo "dir $scripts_root_dir"
|
2019-11-21 17:05:58 +02:00
|
|
|
outputdir=$scripts_root_dir../../archives
|
2017-01-16 00:23:30 +02:00
|
|
|
|
2021-11-21 17:29:23 +02:00
|
|
|
mkdir -p "$outputdir"
|
|
|
|
|
2018-04-01 17:29:01 +02:00
|
|
|
cd "$scripts_root_dir/../../patched-fonts/" || {
|
2017-05-14 00:02:53 +02:00
|
|
|
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
|
2016-11-13 19:25:35 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2017-01-16 00:23:30 +02:00
|
|
|
# limit archiving to given pattern (first script param) or entire root folder if no param given:
|
|
|
|
if [ $# -eq 1 ]
|
|
|
|
then
|
2019-11-21 17:05:58 +02:00
|
|
|
pattern=$1
|
2018-04-01 21:39:36 +02:00
|
|
|
search_pattern="*$1*.zip"
|
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=".*"
|
2018-04-01 21:39:36 +02:00
|
|
|
search_pattern="*.zip"
|
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
|
|
|
|
|
2020-04-13 12:36:17 +02:00
|
|
|
# create a mini readme with basic info on Nerd Fonts project
|
2021-11-21 17:29:23 +02:00
|
|
|
touch "$outputdir/readme.md"
|
2020-04-13 12:36:17 +02:00
|
|
|
mini_readme="$outputdir/readme.md"
|
|
|
|
cat "$parent_dir/src/archive-readme.md" >> "$mini_readme"
|
|
|
|
|
2018-04-01 17:29:01 +02:00
|
|
|
# clear out the directory zips
|
2018-04-01 21:39:36 +02:00
|
|
|
find "${outputdir:?}" -name "$search_pattern" -type f -delete
|
2018-04-01 17:29:01 +02:00
|
|
|
|
2016-11-13 19:25:35 +02:00
|
|
|
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
|
2016-11-19 03:27:38 +02:00
|
|
|
#find ./ProFont -maxdepth 0 -type d | # uncomment to test 1 font
|
2021-11-21 17:29:23 +02:00
|
|
|
# find ./IBMPlexMono -maxdepth 0 -type d | # uncomment to test 1 font
|
2019-11-21 17:05:58 +02:00
|
|
|
# uncomment to test all fonts:
|
2022-08-25 08:04:14 +02:00
|
|
|
find . -maxdepth 1 -iregex "\./$pattern" -type d |
|
2016-11-13 19:25:35 +02:00
|
|
|
while read -r filename
|
|
|
|
do
|
|
|
|
|
2020-01-19 07:11:26 +02:00
|
|
|
basename=$(basename "$filename")
|
|
|
|
searchdir=$filename
|
2016-11-13 19:25:35 +02:00
|
|
|
|
2020-01-19 07:11:26 +02:00
|
|
|
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
|
2016-11-13 19:25:35 +02:00
|
|
|
|
2020-04-13 12:36:17 +02:00
|
|
|
# add font files:
|
2018-04-01 22:30:03 +02:00
|
|
|
# -ic (ignore case not working)
|
2022-10-24 11:43:43 +02:00
|
|
|
zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*.[ot]tf' -i '*.[OT]TF' -q
|
2020-01-19 07:11:26 +02:00
|
|
|
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"
|
2020-04-13 12:36:17 +02:00
|
|
|
# add font files and license files as full paths:
|
2022-10-24 11:43:43 +02:00
|
|
|
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
|
2020-04-13 12:36:17 +02:00
|
|
|
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*'
|
2022-08-25 08:04:14 +02:00
|
|
|
# work around to copy duplicate license files (only the last duplicate found)
|
2020-04-13 12:36:17 +02:00
|
|
|
# so we don't have to copy entire paths and can still use the junk option (-j)
|
2022-10-24 11:43:43 +02:00
|
|
|
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" -@
|
2020-01-19 07:11:26 +02:00
|
|
|
fi;
|
2020-04-13 11:41:52 +02:00
|
|
|
|
2020-04-13 12:36:17 +02:00
|
|
|
# add mini readme file
|
2021-11-21 17:29:23 +02:00
|
|
|
zip -9 "$outputdir/$basename" -rj "$mini_readme" -q
|
2016-11-13 19:25:35 +02:00
|
|
|
done
|
2022-08-25 08:04:14 +02:00
|
|
|
rm -f "$mini_readme"
|
2021-11-21 17:29:23 +02:00
|
|
|
|
2022-08-25 08:04:14 +02:00
|
|
|
ls -al "$outputdir"
|