1
0
mirror of https://github.com/ryanoasis/nerd-fonts.git synced 2024-12-13 17:18:37 +02:00
nerd-fonts/bin/scripts/archive-fonts.sh

57 lines
1.8 KiB
Bash
Raw Normal View History

2018-07-09 16:20:40 +02:00
#!/usr/bin/env bash
# Nerd Fonts Version: 2.1.0
# Script Version: 1.1.0
# Iterates over all patched fonts directories
# to generate ruby cask files for homebrew-fonts (https://github.com/caskroom/homebrew-fonts)
# adds Windows versions of the fonts as well (casks files just won't download them)
#set -x
LINE_PREFIX="# [Nerd Fonts] "
scripts_root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
echo "dir $scripts_root_dir"
2019-11-21 17:05:58 +02:00
outputdir=$scripts_root_dir../../archives
cd "$scripts_root_dir/../../patched-fonts/" || {
2017-05-14 00:02:53 +02:00
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
exit 1
}
# 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'"
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"
fi
# clear out the directory zips
2018-04-01 21:39:36 +02:00
find "${outputdir:?}" -name "$search_pattern" -type f -delete
#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
2019-11-21 17:05:58 +02:00
# uncomment to test all fonts:
find -- * -maxdepth 0 -iregex "$pattern" -type d |
while read -r filename
do
basename=$(basename "$filename")
searchdir=$filename
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
2018-04-01 22:30:03 +02:00
# -ic (ignore case not working)
zip -9 "$outputdir/$basename" -rj "$searchdir" -i '*.[o,t]tf' -i '*.[O,T]TF'
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"
zip -9 "$outputdir/$basename" -r "$searchdir" -i '*.[o,t]tf' -i '*.[O,T]TF'
fi;
done