oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#!/bin/sh
2# Fetch Timeless Sans, the face Base is set in.
3#
4# The Timeless Free Font License 1.2 allows embedding in a website but
5# forbids putting the fonts in a public repository, so the repo holds this
6# fetch step and a pinned checksum instead of the font. The file lands in
7# internal/look/static/fonts/timeless/, which is git-ignored, and `go build`
8# embeds it from there. Without it the site still builds and runs, set in
9# DM Sans.
10#
11# A release is never built without it: `make release` runs this script and
12# then `hack/fonts.sh check`, which fails unless the file is there and is
13# exactly the pinned font.
14#
15# make fonts fetch it (needs the network: media.timeless.co)
16# FORCE=1 make fonts fetch it again even if it is already there
17# hack/fonts.sh check check the file that is there; never downloads
18set -eu
19
20VERSION=1.094
21URL="https://media.timeless.co/type/Timeless-Type-Family-$VERSION.zip"
22SHA256=510685dfce6010b74a1a250af7de1204e1b9901be152a39f5dd6be85fc6d6084
23MEMBER=Timeless-Type-Family-$VERSION/Sans-Grotesk/TimelessSansVF.woff2
24# The extracted file, from the zip above, so a file already in place can be
25# checked without the network.
26FONT_SHA256=353b3fbb75b8e9b927db12d520ff8d446d89c36897b47a90d70dbe36e9eeb23a
27
28root=$(cd "$(dirname "$0")/.." && pwd)
29dest="$root/internal/look/static/fonts/timeless/$VERSION"
30font="$dest/TimelessSansVF.woff2"
31
32sha256() {
33 if command -v sha256sum >/dev/null 2>&1; then
34 sha256sum "$1" | cut -d' ' -f1
35 else
36 shasum -a 256 "$1" | cut -d' ' -f1
37 fi
38}
39
40# verify FILE WANT fails loudly unless FILE's SHA-256 is WANT.
41verify() {
42 got=$(sha256 "$1")
43 if [ "$got" != "$2" ]; then
44 echo "fonts: checksum mismatch for $1" >&2
45 echo "fonts: want $2" >&2
46 echo "fonts: got $got" >&2
47 return 1
48 fi
49}
50
51case "${1:-}" in
52check)
53 if [ ! -f "$font" ]; then
54 echo "fonts: $font is not there; run make fonts" >&2
55 exit 1
56 fi
57 verify "$font" "$FONT_SHA256" || { echo "fonts: FORCE=1 make fonts fetches it again" >&2; exit 1; }
58 echo "fonts: $font is the pinned Timeless Sans"
59 exit 0
60 ;;
61"") ;;
62*)
63 echo "usage: hack/fonts.sh [check]" >&2
64 exit 2
65 ;;
66esac
67
68if [ -f "$font" ] && [ -z "${FORCE:-}" ]; then
69 verify "$font" "$FONT_SHA256" || { echo "fonts: FORCE=1 make fonts fetches it again" >&2; exit 1; }
70 echo "fonts: $font is already there (FORCE=1 to fetch again)"
71 exit 0
72fi
73
74# Scratch space on disk, never a bare /tmp, which on shared machines is a
75# RAM disk everyone shares: $TMPDIR when set, else a directory in the user
76# cache. Both the scratch and that directory, if this made it, go at exit.
77if [ -n "${TMPDIR:-}" ]; then
78 scratch=$TMPDIR
79 made=
80else
81 scratch="${XDG_CACHE_HOME:-$HOME/.cache}/base-fonts"
82 made=
83 [ -d "$scratch" ] || made=1
84 mkdir -p "$scratch"
85fi
86work=$(mktemp -d "$scratch/base-fonts.XXXXXX")
87cleanup() {
88 rm -rf "$work"
89 if [ -n "$made" ]; then rmdir "$scratch" 2>/dev/null || true; fi
90}
91trap cleanup EXIT
92trap 'exit 1' INT TERM
93
94echo "fonts: downloading $URL"
95curl --fail --silent --show-error --location --proto '=https' --output "$work/timeless.zip" "$URL"
96
97verify "$work/timeless.zip" "$SHA256" || { echo "fonts: (downloaded from $URL)" >&2; exit 1; }
98
99# Only the one file comes out of the zip, into a scratch directory first,
100# so a failed extraction leaves nothing half-installed.
101mkdir "$work/out"
102if command -v unzip >/dev/null 2>&1; then
103 unzip -q -j -o "$work/timeless.zip" "$MEMBER" -d "$work/out"
104else
105 python3 -I -c '
106import sys, os, zipfile
107zf, member, out = sys.argv[1:4]
108with zipfile.ZipFile(zf) as z, z.open(member) as src:
109 with open(os.path.join(out, os.path.basename(member)), "wb") as dst:
110 dst.write(src.read())
111' "$work/timeless.zip" "$MEMBER" "$work/out"
112fi
113
114verify "$work/out/TimelessSansVF.woff2" "$FONT_SHA256"
115
116mkdir -p "$dest"
117mv "$work/out/TimelessSansVF.woff2" "$font"
118echo "fonts: wrote $font"
119