build-woff2.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/sh
  2. # ///////////////////////////////////////////////////////////////////
  3. #
  4. # build-woff2.sh
  5. # A shell script that builds the Hack woff2 web fonts from ttf files
  6. # Copyright 2018 Christopher Simpkins
  7. # MIT License
  8. #
  9. # Usage: ./build-woff2.sh (--system)
  10. # Arguments:
  11. # --system (optional) - use build dependencies installed on PATH
  12. #
  13. # NOTE: If you change the source, you must build new ttf files
  14. # PRIOR to the execution of this script. This script builds
  15. # directly from previous ttf builds, not source files.
  16. #
  17. # ///////////////////////////////////////////////////////////////////
  18. # The woff2 git clone directory.
  19. BUILD="$HOME"
  20. # woff2 executable path
  21. WOFF2_BIN="$BUILD/woff2/woff2_compress"
  22. # The font build directory paths and file paths for the woff builds
  23. TTF_BUILD="build/ttf"
  24. WOFF_BUILD="build/web/fonts"
  25. REGULAR_TTF="Hack-Regular.ttf"
  26. REGULAR_PRE="Hack-Regular.woff2"
  27. REGULAR_WOFF="hack-regular.woff2"
  28. BOLD_TTF="Hack-Bold.ttf"
  29. BOLD_PRE="Hack-Bold.woff2"
  30. BOLD_WOFF="hack-bold.woff2"
  31. ITALIC_TTF="Hack-Italic.ttf"
  32. ITALIC_PRE="Hack-Italic.woff2"
  33. ITALIC_WOFF="hack-italic.woff2"
  34. BOLDITALIC_TTF="Hack-BoldItalic.ttf"
  35. BOLDITALIC_PRE="Hack-BoldItalic.woff2"
  36. BOLDITALIC_WOFF="hack-bolditalic.woff2"
  37. # test for number of arguments
  38. if [ $# -gt 1 ]
  39. then
  40. echo "Inappropriate arguments included in your command." 1>&2
  41. echo "Usage: ./build-woff2.sh (--system)" 1>&2
  42. exit 1
  43. fi
  44. # determine if system installed executable on PATH is requested for build
  45. # then test for presence of the woff2_compress build dependency based upon where it should be located
  46. if [ "$1" = "--system" ]; then
  47. WOFF2_BIN="woff2_compress"
  48. if ! which $WOFF2_BIN; then
  49. echo "Unable to identify woff2_compress executable on system PATH. Please install and try again." 1>&2
  50. exit 1
  51. else
  52. # display version of installed woff2_compress
  53. echo "Beginning web font build with $WOFF2_BIN"
  54. fi
  55. fi
  56. # test for woff2_compress executable with default build approach
  57. if [ $# -eq 0 ]; then
  58. if [ -f "$WOFF2_BIN" ]; then
  59. echo "Beginning web font build with $WOFF2_BIN"
  60. else
  61. echo "Unable to locate woff2_compress on path $WOFF2_BIN. Please attempt a manual install of this build dependency and then repeat your build attempt." 1>&2
  62. exit 1
  63. fi
  64. fi
  65. # Build woff2 files from ttf files
  66. # regular set
  67. if ! "$WOFF2_BIN" "$TTF_BUILD/$REGULAR_TTF"; then
  68. echo "Failed to build woff2 from $REGULAR_TTF." 1>&2
  69. exit 1
  70. else
  71. echo "Regular woff2 font set successfully built from $REGULAR_TTF"
  72. fi
  73. # bold set
  74. if ! "$WOFF2_BIN" "$TTF_BUILD/$BOLD_TTF"; then
  75. echo "Failed to build woff2 from $BOLD_TTF" 1>&2
  76. exit 1
  77. else
  78. echo "Bold woff2 set successfully built from $BOLD_TTF"
  79. fi
  80. # italic set
  81. if ! "$WOFF2_BIN" "$TTF_BUILD/$ITALIC_TTF"; then
  82. echo "Failed to build woff2 from $ITALIC_TTF" 1>&2
  83. exit 1
  84. else
  85. echo "Italic woff2 set successfully built from $ITALIC_TTF"
  86. fi
  87. # bold italic set
  88. if ! "$WOFF2_BIN" "$TTF_BUILD/$BOLDITALIC_TTF"; then
  89. echo "Failed to build woff2 from $BOLDITALIC_TTF" 1>&2
  90. exit 1
  91. else
  92. echo "Bold Italic woff2 set successfully built from $BOLDITALIC_TTF"
  93. fi
  94. echo "Moving woff2 files to build directory..."
  95. # create directory if it does not exist
  96. # (occurs with git + empty directories)
  97. if ! [ -d "$WOFF_BUILD" ]; then
  98. mkdir $WOFF_BUILD
  99. fi
  100. # move woff2 files to appropriate build directory
  101. mv "$TTF_BUILD/$REGULAR_PRE" "$WOFF_BUILD/$REGULAR_WOFF"
  102. mv "$TTF_BUILD/$BOLD_PRE" "$WOFF_BUILD/$BOLD_WOFF"
  103. mv "$TTF_BUILD/$ITALIC_PRE" "$WOFF_BUILD/$ITALIC_WOFF"
  104. mv "$TTF_BUILD/$BOLDITALIC_PRE" "$WOFF_BUILD/$BOLDITALIC_WOFF"
  105. echo " "
  106. if [ -f "$WOFF_BUILD/$REGULAR_WOFF" ]; then
  107. echo "Regular woff2 build path: $WOFF_BUILD/$REGULAR_WOFF"
  108. fi
  109. if [ -f "$WOFF_BUILD/$BOLD_WOFF" ]; then
  110. echo "Bold woff2 build path: $WOFF_BUILD/$BOLD_WOFF"
  111. fi
  112. if [ -f "$WOFF_BUILD/$ITALIC_WOFF" ]; then
  113. echo "Italic woff2 build path: $WOFF_BUILD/$ITALIC_WOFF"
  114. fi
  115. if [ -f "$WOFF_BUILD/$BOLDITALIC_WOFF" ]; then
  116. echo "Bold Italic woff2 build path: $WOFF_BUILD/$BOLDITALIC_WOFF"
  117. fi