Moves build related shell scripts to bin/scripts

This commit is contained in:
Ryan L McIntyre 2016-10-29 16:45:55 -04:00
parent 5eafddc7ce
commit e72a164f80
3 changed files with 295 additions and 0 deletions

View file

@ -0,0 +1,27 @@
#!/bin/bash
# project: Nerd Fonts (https://github.com/ryanoasis/nerd-fonts)
# version: 0.9.0
# Executes the 2to3 conversion to generate latest py3 version of font patcher
# Check for 2to3
type 2to3 >/dev/null 2>&1 || {
echo >&2 "# 2to3 must be installed before running this script."
echo >&2 "# Please see details at"
echo >&2 "# https://docs.python.org/2/library/2to3.html"
exit 1
}
# -x unicode: ignore changing unicode to str
# purpose: to prevent 2to3 by default from changing 'unicode' to 'str'
# because in FontForge 'str' is not an attribute of the glyph object
# for more information:
# see: https://docs.python.org/2/library/2to3.html#to3-fixers
# see: https://github.com/ryanoasis/nerd-fonts/issues/49
# see: https://github.com/ryanoasis/nerd-fonts/issues/79
2to3 -x unicode -n -w ../font-patcher --add-suffix=-py3
# fix environment (first line in file)
# from `/usr/bin/env python2` when it should
# be `/usr/bin/env python3`
# using 1 as line number and '%' as delimiter:
sed -i '1s%.*%#!/usr/bin/env python3%' ../../font-patcher-py3

View file

@ -0,0 +1,185 @@
#!/bin/bash
# version: 0.9.0
# Check for Fontforge
type fontforge >/dev/null 2>&1 || {
echo >&2 "# FontForge must be installed before running this script."
echo >&2 "# Please see installation instructions at"
echo >&2 "# http://designwithfontforge.com/en-US/Installing_Fontforge.html"
exit 1
}
res1=$(date +%s)
parent_dir="${PWD}/../../"
# Set source and target directories
source_fonts_dir="${PWD}/../../src/unpatched-fonts"
patched_fonts_dir="${PWD}/../../patched-fonts"
like_pattern=''
complete_variation_count=0
total_variation_count=0
total_count=0
last_parent_dir=""
unpatched_parent_dir="bin/scripts/../../src/unpatched-fonts"
patched_parent_dir="patched-fonts"
if [ $# -eq 1 ]
then
like_pattern=$1
echo "# Parameter given, limiting search and patch to pattern '$like_pattern' given"
fi
# correct way to output find results into an array (when files have space chars, etc)
# source: http://stackoverflow.com/questions/8213328/bash-script-find-output-to-array
source_fonts=()
while IFS= read -d $'\0' -r file ; do
source_fonts=("${source_fonts[@]}" "$file")
done < <(find "$source_fonts_dir" -name "$like_pattern*.[o,t]tf" -type f -print0)
# print total number of source fonts found
echo "# Total source fonts found: ${#source_fonts[*]}"
function patch_font {
local f=$1; shift
echo "f $f"
echo "basename $(basename $f)"
echo "dirname $(dirname $f)"
echo pwd
## take everything before the last slash (/) to start building the full path
#echo "patched_font_dir $patched_font_dir"
local patched_font_dir="${f%/*}/"
echo "patched_font_dir $patched_font_dir"
#local patched_font_dir="${patched_font_dir/../../unpatched-fonts/patched-fonts}"
#echo "patched_font_dir $patched_font_dir"
# find replace unpatched parent dir with patched parent dir:
local patched_font_dir="${patched_font_dir/$unpatched_parent_dir/$patched_parent_dir}"
echo "patched_font_dir $patched_font_dir"
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd)
config_dir=$( cd "$( dirname "$f" )" && pwd)
config_parent_dir_name=$(basename $config_parent_dir)
#is_unpatched_fonts_root=$("$config_parent_dir_name" == "unpatched-fonts")
is_unpatched_fonts_root=0
echo "config_parent_dir_name $config_parent_dir_name"
if [ "$config_parent_dir_name" == "unpatched-fonts" ]
then
echo "ITS ROOT"
is_unpatched_fonts_root=1
fi
echo "is_unpatched_fonts_root $is_unpatched_fonts_root"
# source the font config file if exists:
if [ -f "$config_dir/config.cfg" ]
then
source "$config_dir/config.cfg"
elif [ -f "$config_parent_dir/config.cfg" ]
then
source "$config_parent_dir/config.cfg"
fi
if [ "$config_has_powerline" ]
then
powerline=""
combinations=$(printf "./font-patcher ${f##*/} %s\n" {' --use-single-width-glyphs',}{' --windows',}{' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',})
else
powerline="--powerline"
combinations=$(printf "./font-patcher ${f##*/} %s\n" {' --powerline',}{' --use-single-width-glyphs',}{' --windows',}{' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',})
fi
echo "f ${f}"
echo "output to ${patched_font_dir}complete/"
cd "$parent_dir"
fontforge -quiet -script ./font-patcher "$f" -q -s $powerline --complete --outputdir "${patched_font_dir}complete/" 2>/dev/null &
fontforge -quiet -script ./font-patcher "$f" -q -w $powerline --complete --outputdir "${patched_font_dir}complete/" 2>/dev/null &
fontforge -quiet -script ./font-patcher "$f" -q -s -w $powerline --complete --outputdir "${patched_font_dir}complete/" 2>/dev/null &
#wait
complete_variation_count=$((complete_variation_count+3))
combination_count=$(printf "%s" "$combinations" | wc -l)
# generate the readmes:
# if first time with this font then re-build parent dir readme, else skip:
if [[ $config_parent_dir != "$last_parent_dir" && (! $is_unpatched_fonts_root) ]];
then
echo "config_parent_dir $config_parent_dir"
echo "last_parent_dir $last_parent_dir"
echo "Re-generate parent directory readme"
generate_readme "$patched_font_dir/.."
fi
generate_readme "$patched_font_dir"
last_parent_dir=$config_parent_dir
total_variation_count=$((total_variation_count+combination_count))
total_count=$((complete_variation_count+combination_count))
}
# Re-generate all the readmes
# $1 = fontdir path
function generate_readme {
patched_font_dir=$1
combinations_filename="$patched_font_dir/readme.md"
font_info="$patched_font_dir/font-info.md"
# clear output file (needed for multiple runs or updates):
> "$combinations_filename"
if [ -f font_info ];
then
cat "$patched_font_dir/font-info.md" >> "$combinations_filename"
else
echo "# Could not append font-info.md (file not found). Was standardize script run? It should be executed first"
fi
cat "$parent_dir/src/readme-per-directory-variations.md" >> "$combinations_filename"
# add to the file
{
printf "\`\`\`sh"
printf "\n# %s Possible Combinations:\n" "$combination_count"
printf "\n"
printf "%s" "$combinations"
printf "\n"
printf "\`\`\`"
} >> "$combinations_filename"
}
# Use for loop iterate through source fonts
# $f stores current value
for f in "${source_fonts[@]}"
do
#echo "patch $f"
patch_font "$f"
# 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!
#wait
done
# wait for all bg commands to finish
wait
res2=$(date +%s)
dt=$(echo "$res2 - $res1" | bc)
dd=$(echo "$dt/86400" | bc)
dt2=$(echo "$dt-86400*$dd" | bc)
dh=$(echo "$dt2/3600" | bc)
dt3=$(echo "$dt2-3600*$dh" | bc)
dm=$(echo "$dt3/60" | bc)
ds=$(echo "$dt3-60*$dm" | bc)
printf "# Total runtime: %d:%02d:%02d:%02d\n" "$dd" "$dh" "$dm" "$ds"
printf "# All fonts patched to sub-directories in '%s'\n" "$patched_parent_dir"
printf "# The total number of 'variation' patched fonts created was '%s'\n" "$total_variation_count"
printf "# The total number of 'complete' patched fonts created was '%s'\n" "$complete_variation_count"
printf "# The total number of patched fonts created was '%s'\n" "$total_count"

View file

@ -0,0 +1,83 @@
#!/bin/bash
# version: 0.9.0
# Iterates over all patched fonts directories
# converts all non markdown readmes to markdown (e.g., txt, rst) using pandoc
# adds information on additional-variations and complete font variations
infofilename="font-info.md"
unpatched_parent_dir="src/unpatched-fonts"
patched_parent_dir="patched-fonts"
cd ../../src/unpatched-fonts/ || {
echo >&2 "# Could not find source fonts directory"
exit 1
}
#find ./ProFont -type d | # uncomment to test 1 font
#find ./DejaVuSansMono -type d | # uncomment to test 1 font
find . -type d | # uncomment to do ALL fonts
while read -r filename
do
dirname=$(dirname "$filename")
searchdir=$filename
# limit looking for the readme files in the parent dir not the child dirs:
if [[ $dirname != "." ]];
then
searchdir=$dirname
fi
RST=( $(find "$searchdir" -type f -iname 'readme.rst') )
TXT=( $(find "$searchdir" -type f -iname 'readme.txt') )
outputdir=$PWD/../../patched-fonts/$filename/
echo "# Generating readme for: $filename"
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
if [ "${RST[0]}" ];
then
for i in "${RST[@]}"
do
echo "## Found RST"
from="$PWD/$i"
from_dir=$(dirname "$from")
to_dir="${from_dir/$unpatched_parent_dir/$patched_parent_dir}"
to="${to_dir}/$infofilename"
[[ -d "$to_dir" ]] || mkdir -p "$to_dir"
# clear output file (needed for multiple runs or updates):
> "$to" 2> /dev/null
pandoc "$from" --from=rst --to=markdown --output="$to"
cat "$PWD/../../src/readme-per-directory-addendum.md" >> "$to"
done
elif [ "${TXT[0]}" ];
then
for i in "${TXT[@]}"
do
echo "## Found TXT"
from="$PWD/$i"
from_dir=$(dirname "$from")
to_dir="${from_dir/$unpatched_parent_dir/$patched_parent_dir}"
to="${to_dir}/$infofilename"
[[ -d "$to_dir" ]] || mkdir -p "$to_dir"
# clear output file (needed for multiple runs or updates):
> "$to" 2> /dev/null
cp "$from" "$to"
cat "$PWD/../../src/readme-per-directory-addendum.md" >> "$to"
done
else
echo "# Did not find RST nor TXT"
fi
done