Skip to content

feat(module): add mscorefonts module for Microsoft core fonts (Times New Roman, Arial, ...) - #421

Merged
ycpss91255 merged 1 commit into
mainfrom
feat/mscorefonts-module
Nov 16, 2026
Merged

ycpss91255 merged 1 commit into
mainfrom
feat/mscorefonts-module

Conversation

@ycpss91255

Copy link
Copy Markdown
Owner

Summary

新增 mscorefonts 模組,用來安裝 Microsoft 核心字型(Times New Roman、Arial、Courier New、Georgia、Verdana 等),並能修復「套件顯示已安裝、但字型其實不存在」的狀態。

目前沒有對應的 issue(本次只要求補上這個字型),所以沒有 Closes #N。

起因:一台機器上 fc-list 找不到 Times New Roman,文件會退回 Liberation Serif。實際追查後發現 ttf-mscorefonts-installer 是被某個辦公軟體的 .deb 當成依賴自動帶進來的,安裝時沒有跳出授權確認,debconf 的 msttcorefonts/accepted-mscorefonts-eula 記錄成 false。這個套件只是下載器,授權沒接受時 postinst 會移除所有字型並留下一個 "License refused." 的 README,所以 dpkg 顯示 ii(已安裝),字型目錄裡卻只有 README。

Changes

  • module/mscorefonts.module.sh(新增):apt archetype 加上手寫的 install、is_installed、doctor。
    • is_installed:除了 dpkg 顯示 ii,還要檢查字型檔(Times_New_Roman.ttf 或 times.ttf)確實存在,所以「授權被拒」的狀態會被判定為未安裝。
    • install:先用 debconf-set-selections 預設授權答案為 true,再安裝。套件已存在但字型缺失時改用 apt-get install --reinstall,讓 postinst 重新下載。透過 sudo env DEBIAN_FRONTEND=noninteractive 傳遞非互動旗標。安裝後字型仍不存在則回傳失敗,因此不會寫入 sidecar(ADR-0015)。
    • doctor:除了 is_installed,還確認 fc-match 'Times New Roman' 解析到真正的字型,而不是 Liberation Serif 這類替代字型。
    • WARN_MESSAGE(en / zh-TW)明確說明安裝本模組等於代為接受 Microsoft 授權條款。
    • 屬性:CATEGORY=optional、僅 desktop、is_recommended 永遠為否(專有字型,必須明確指定才會安裝)。
  • test/unit/module/mscorefonts_spec.bats(新增):67 個測試。
  • doc/module/INDEX.md:用 script/gen-module-index.sh 重新產生(90 → 91 個模組)。
  • doc/changelog/CHANGELOG.md:在 [Unreleased] 的 Added 加上條目。

請優先看 is_installed 與 install 兩個函式。

Decision

  • 獨立新模組,不併入既有的 font 模組:font 是 user-home 安裝、不需要 sudo、從 GitHub 下載 Nerd Font;這個是 sudo、apt、還有授權條款,屬於不同的 archetype 與風險。
  • is_installed 以字型檔為準,不只看 dpkg:預設的 apt 檢查在「授權被拒」的狀態下會回傳已安裝,module_skip_if_installed 就會永遠跳過安裝,無法自我修復。
  • 自動接受授權是這個 PR 最需要審視的決定:這個 repo 是個人使用的初始化工具,模組本來就是由使用者明確指定安裝,所以選擇預設答案為 true,並在 WARN_MESSAGE 與 CHANGELOG 中明確揭露。不預設接受的話,非互動安裝一定會得到空的字型目錄。
  • 字型是安裝時才從 SourceForge 下載,所以安裝依賴該網站可用;已確認撰寫當下來源可連線。這個限制已寫在 WARN_MESSAGE。
  • 刻意不處理 multiverse 元件:Ubuntu 桌面與官方 Docker 映像預設已啟用。
  • 沒有新增任何 shellcheck disable。

Tests

  • just -f justfile.ci lint:ShellCheck、fish 語法、Hadolint 全部通過。
  • just -f justfile.ci test-unit mscorefonts:67 個測試全部通過。
  • just -f justfile.ci test-unit(完整單元測試):7566 個通過、0 失敗、1 個 skip。
  • 以上測試都是在 Docker 內執行,沒有在主機上執行模組的 install。
  • 端對端:在拋棄式的 ubuntu:24.04 容器內實際執行。
    1. 以非互動方式安裝 ttf-mscorefonts-installer,重現問題狀態(目錄只有 README,fc-match "Times New Roman" 回傳 Liberation Serif)。
    2. 模組的 is-installed 回傳非 0(正確判定為未安裝)。
    3. 執行 install 後下載了 60 個字型檔,fc-match 回傳 Times_New_Roman.ttf,is-installed、doctor、verify 皆回傳 0。
    4. 再執行一次 install 會回報 already installed 並跳過(冪等)。
  • 尚未做:22.04 與 26.04 映像上的實機驗證,CI 矩陣會涵蓋。

…New Roman, Arial, ...)

ttf-mscorefonts-installer only downloads the fonts when the msttcorefonts/accepted-mscorefonts-eula debconf answer is true. When the package is pulled in non-interactively as a dependency the answer is false: the postinst removes every font and leaves a License-refused README, so dpkg reports the package as installed while Times New Roman is missing and fontconfig falls back to Liberation Serif.

The module judges is_installed by the font files rather than dpkg alone, preseeds the EULA answer before installing, and uses apt-get install --reinstall when the package is already present so the downloader runs again. doctor also checks that fc-match resolves Times New Roman to the real font.
@ycpss91255
ycpss91255 merged commit 679eced into main Nov 16, 2026
12 checks passed
@ycpss91255
ycpss91255 deleted the feat/mscorefonts-module branch November 16, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant