2016-11-06 05:09:12 +02:00
#!/bin/bash
# version: 0.9.0
# Iterates over all patched fonts directories
# to generate ruby cask files for homebrew-fonts (https://github.com/caskroom/homebrew-fonts)
# only adds non-Windows versions of the fonts
2016-11-13 19:22:10 +02:00
set -x
2016-11-06 05:09:12 +02:00
2016-11-13 19:22:10 +02:00
version = "0.8.0"
2016-11-06 05:09:12 +02:00
patched_parent_dir = "patched-fonts"
homepage = "https://github.com/ryanoasis/nerd-fonts"
2016-11-13 19:22:10 +02:00
downloadarchive = "https://github.com/ryanoasis/nerd-fonts/releases/download/v#{version}/"
sha256sum = ":no_check"
appcast = "https://github.com/ryanoasis/nerd-fonts/releases.atom"
appcastcheckpoint = $( curl --compressed --location --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' "https://github.com/ryanoasis/nerd-fonts/releases.atom" | sed 's|<pubDate>[^<]*</pubDate>||g' | shasum --algorithm 256 | head -c 64)
2016-11-06 05:09:12 +02:00
cd ../../patched-fonts/ || {
echo >& 2 "# Could not find patched fonts directory"
exit 1
}
2016-11-13 19:22:10 +02:00
find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
#find . -maxdepth 1 -type d | # uncomment to test 1 font
2016-11-06 05:09:12 +02:00
while read -r filename
do
dirname = $( dirname " $filename " )
basename = $( basename " $filename " )
2016-11-13 19:22:10 +02:00
sha256sum = $( sha256sum " ../archives/ ${ basename } .zip " | head -c 64)
2016-11-06 05:09:12 +02:00
searchdir = $filename
fontdir = $( basename " $( dirname " $dirname " ) " )
FONTS = ( )
while IFS = read -d $'\0' -r file ; do
FONTS = ( " ${ FONTS [@] } " " $file " )
done < <( find " $searchdir " -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' \) -print0)
outputdir = $PWD /../casks/
formattedbasename = $( echo " $basename " | tr "[:upper:]" "[:lower:]" )
echo " # Generating cask for: $fontdir "
[ [ -d " $outputdir " ] ] || mkdir -p " $outputdir "
caskname = " font- $formattedbasename -nerd-font "
to = " $outputdir / ${ caskname } .rb "
# clear output file (needed for multiple runs or updates):
> " $to " 2> /dev/null
# add to the file
{
printf "cask '%s' do\n" " $caskname "
2016-11-13 19:22:10 +02:00
printf " version '%s'\n" " $version "
printf " sha256 '%s'\n\n" " $sha256sum "
printf " url '%s%s.zip'\n" " $downloadarchive " " $basename "
2016-11-17 01:19:58 +02:00
printf " appcast '%s',\n" " $appcast "
2016-11-13 19:22:10 +02:00
printf " checkpoint: '%s'\n" " $appcastcheckpoint "
2016-11-06 05:09:12 +02:00
} >> " $to "
if [ " ${ FONTS [0] } " ] ;
then
for i in " ${ !FONTS[@] } "
do
echo "## Found Font"
2016-11-13 19:22:10 +02:00
individualfont = $( basename " ${ FONTS [ $i ] } " )
#downloadfont="${individualfont/$searchdir\//}"
2016-11-06 05:09:12 +02:00
echo " individualfont $individualfont "
echo " downloadfont $downloadfont "
echo " $i "
2016-11-13 19:22:10 +02:00
echo " ${ FONTS [ $i ] } "
2016-11-06 05:09:12 +02:00
if [ " $i " = = 0 ] ;
then
familyname = $( fc-query --format= '%{family}' " ${ FONTS [ $i ] } " )
2016-11-13 19:22:10 +02:00
{
printf " name '%s (%s)'\n" " $familyname " " $basename "
printf " homepage '%s'" " $homepage "
printf "\n\n"
} >> " $to "
2016-11-06 05:09:12 +02:00
fi
2016-11-13 19:22:10 +02:00
printf " font '%s'\n" " $individualfont " >> " $to "
2016-11-06 05:09:12 +02:00
done
else
echo "# Did not find TTF or OTF"
fi
# add to the file
{
printf "end"
} >> " $to "
done