|
1 |
| -#!/bin/sh |
| 1 | +#!/bin/bash |
2 | 2 |
|
3 |
| -set -exu |
| 3 | +set -e |
4 | 4 |
|
5 |
| -cd $(dirname "$0") |
| 5 | +function failed () { |
| 6 | + info 0 |
| 7 | + info 2 "unexpected exitcode! exiting..." |
| 8 | +} |
6 | 9 |
|
7 |
| -mkdir tmp |
8 |
| -cd tmp |
9 |
| -wget --https-only -O Noto.zip 'https://fonts.google.com/download?family=Noto%20Sans%20JP' |
10 |
| -unzip Noto.zip static/NotoSansJP-Medium.ttf OFL.txt |
11 |
| -mv static/NotoSansJP-Medium.ttf OFL.txt ../ |
12 |
| -cd ../ |
13 |
| -rm -rf tmp |
| 10 | +trap failed ERR |
| 11 | + |
| 12 | +export TERM="${TERM:-xterm-256color}" |
| 13 | + |
| 14 | +function info () { |
| 15 | + local SUFFIX=$(tput sgr0) |
| 16 | + |
| 17 | + if [ $1 -eq 0 ]; then |
| 18 | + local PREFIX |
| 19 | + elif [ $1 -eq 1 ]; then |
| 20 | + local PREFIX="$(tput bold)==> " |
| 21 | + elif [ $1 -eq 2 ]; then |
| 22 | + local PREFIX=" -> " |
| 23 | + fi |
| 24 | + |
| 25 | + echo -E "${PREFIX}${2}${SUFFIX}" >> /dev/stderr |
| 26 | +} |
| 27 | + |
| 28 | +function findtools () { |
| 29 | + info 1 "find ${1} ..." |
| 30 | + |
| 31 | + if which ${1} &> /dev/null; then |
| 32 | + local LOCATION=$(which ${1}) |
| 33 | + info 2 "found! (${LOCATION})" |
| 34 | + info 0 |
| 35 | + |
| 36 | + echo -n "${LOCATION}" |
| 37 | + else |
| 38 | + info 2 "not found! exiting..." |
| 39 | + fi |
| 40 | + |
| 41 | +} |
| 42 | + |
| 43 | +cd $(dirname "${0}") |
| 44 | + |
| 45 | +OTF_VARIANT="Sans" |
| 46 | +OTF_FILENAME="Noto${OTF_VARIANT}CJKjp-Medium.otf" |
| 47 | +OTF_URL="https://raw.githubusercontent.com/notofonts/noto-cjk/main/${OTF_VARIANT}/OTF/Japanese/${OTF_FILENAME}" |
| 48 | + |
| 49 | +TTF_FILENAME="${OTF_FILENAME%.*}.ttf" |
| 50 | + |
| 51 | +if [ -e "${TTF_FILENAME}" ]; then |
| 52 | + info 1 "${TTF_FILENAME} is exists! exiting..." |
| 53 | + exit |
| 54 | +fi |
| 55 | + |
| 56 | +WGET=$(findtools wget) |
| 57 | +[ ! ${WGET} ] && exit 1 |
| 58 | + |
| 59 | +FONTFORGE=$(findtools fontforge) |
| 60 | +[ ! ${FONTFORGE} ] && exit 1 |
| 61 | + |
| 62 | +info 1 "download ${OTF_FILENAME}" |
| 63 | +$WGET --https-only --output-document "${OTF_FILENAME}" "${OTF_URL}" |
| 64 | +# info 0 |
| 65 | + |
| 66 | +info 1 "convert ${OTF_FILENAME} to ${TTF_FILENAME}" |
| 67 | +$FONTFORGE -lang=ff -c 'Open($1); Generate($2)' "${OTF_FILENAME}" "${TTF_FILENAME}" |
| 68 | +info 0 |
| 69 | + |
| 70 | +info 1 "remove unnecessary file" |
| 71 | +info 2 "delete ${OTF_FILENAME}" |
| 72 | +rm -f "${OTF_FILENAME}" |
| 73 | +info 0 |
| 74 | + |
| 75 | +info 1 "complete! font file is now available" |
| 76 | +info 2 "at ${TTF_FILENAME}" |
0 commit comments