From 4322d0791f011258407136486c13e690c16ec07f Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 5 Dec 2026 21:40:22 +0800 Subject: [PATCH 1/2] fix(installer): show package progress and restore session controls --- Documentation/admin-guide/installation.rst | 5 + .../LC_MESSAGES/admin-guide/installation.po | 3 + .../LC_MESSAGES/admin-guide/installation.po | 3 + configs/nls/po/installer/installer.pot | 64 +++++++++++ configs/nls/po/installer/ja_JP.po | 64 +++++++++++ configs/nls/po/installer/zh_CN.po | 64 +++++++++++ packages/arch/reliefos-apps/PKGBUILD | 2 + system/installer/icewm/preferences | 2 +- tools/build/arch-guest-packages.sh | 4 +- tools/test_installer_input.py | 56 ++++++++- tools/test_installer_swap_host_compile.py | 2 +- tools/test_installer_swap_tty.py | 2 +- tools/tests/installer_package_progress_test.c | 60 ++++++++++ tools/tests/installer_progress_test.c | 20 +++- userland/apps/installer/Kbuild | 2 + .../apps/installer/arch-online-install.sh | 28 ++--- .../apps/installer/arch-package-progress.awk | 89 +++++++++++++++ userland/apps/installer/install_ops.c | 106 +++++++++++++++--- userland/apps/installer/install_ops.h | 2 + userland/apps/installer/installer_job.c | 3 + userland/apps/installer/installer_job.h | 2 + .../installer/installer_package_progress.c | 94 ++++++++++++++++ .../installer/installer_package_progress.h | 38 +++++++ userland/apps/installer/installer_tui_job.c | 15 +++ userland/apps/installer/main.cpp | 31 +++++ 25 files changed, 725 insertions(+), 36 deletions(-) create mode 100644 tools/tests/installer_package_progress_test.c create mode 100644 userland/apps/installer/arch-package-progress.awk create mode 100644 userland/apps/installer/installer_package_progress.c create mode 100644 userland/apps/installer/installer_package_progress.h diff --git a/Documentation/admin-guide/installation.rst b/Documentation/admin-guide/installation.rst index d224247c..e0d054ec 100644 --- a/Documentation/admin-guide/installation.rst +++ b/Documentation/admin-guide/installation.rst @@ -97,6 +97,11 @@ F3 继续、F2 返回修改,PgUp/PgDn 滚动页面或许可证。界面适 进度页显示分区、下载、验签、包事务、配置及引导安装等阶段。 安装失败时保留错误详情,完整日志位于安装环境的 ``/var/log/installer.log``。 +下载和安装阶段按 pacman 的实际进度更新总进度条,下方另有当前软件包的百分比进度条。 +下载时显示待下载、已下载数量、当前软件包,以及下载量、传输速度和预计剩余时间; +安装时切换为待安装、已安装数量和当前包的安装百分比。已缓存的软件包无需重新下载, +下载数量可以少于安装数量。包事务完成后继续显示配置及引导安装进度。 + 图形安装器可随时通过侧栏的“查看日志 (F4)”按钮或 F4 打开独立日志窗口, 安装期间和结果页面均可使用;关闭日志窗口不会退出安装器或中断安装。 窗口显示最近约 8 KiB 日志,默认每秒刷新并跟随新内容;取消“跟随日志”可暂停阅读, diff --git a/Documentation/locale/en/LC_MESSAGES/admin-guide/installation.po b/Documentation/locale/en/LC_MESSAGES/admin-guide/installation.po index ee3ff5f2..b7fbca1a 100644 --- a/Documentation/locale/en/LC_MESSAGES/admin-guide/installation.po +++ b/Documentation/locale/en/LC_MESSAGES/admin-guide/installation.po @@ -448,3 +448,6 @@ msgstr "The graphical entry of the installation ISO starts Xorg through systemd msgid "图形安装器可随时通过侧栏的“查看日志 (F4)”按钮或 F4 打开独立日志窗口, 安装期间和结果页面均可使用;关闭日志窗口不会退出安装器或中断安装。 窗口显示最近约 8 KiB 日志,默认每秒刷新并跟随新内容;取消“跟随日志”可暂停阅读, 也可点击“刷新”手动更新。日志可滚动和复制,完整内容仍保存在上述日志文件中。 控制台安装器在进度页用 F4 显示或隐藏日志。" msgstr "In the graphical installer, use the sidebar’s “View log (F4)” button or F4 to open a separate log window at any time, including during installation and on the result page. Closing it does not exit the installer or interrupt installation. The window displays approximately the latest 8 KiB of the log, refreshing once per second and following new output by default. Clear “Follow log” to pause reading, or click “Refresh” to update manually. You can scroll and copy the log; the complete contents remain in the log file above. In the console installer, F4 shows or hides the log on the progress page." + +msgid "下载和安装阶段按 pacman 的实际进度更新总进度条,下方另有当前软件包的百分比进度条。 下载时显示待下载、已下载数量、当前软件包,以及下载量、传输速度和预计剩余时间; 安装时切换为待安装、已安装数量和当前包的安装百分比。已缓存的软件包无需重新下载, 下载数量可以少于安装数量。包事务完成后继续显示配置及引导安装进度。" +msgstr "During downloads and installation, the overall progress bar follows pacman’s actual progress, with a second bar for the current package. Download details show pending and completed downloads, the current package, transferred size, speed, and estimated remaining time. Installation details show pending and installed package counts and the current package’s installation percentage. Cached packages do not need to be downloaded again, so fewer packages may be downloaded than installed. After the package transaction, progress continues through system configuration and bootloader installation." diff --git a/Documentation/locale/ja/LC_MESSAGES/admin-guide/installation.po b/Documentation/locale/ja/LC_MESSAGES/admin-guide/installation.po index e04d67b4..9c58f95d 100644 --- a/Documentation/locale/ja/LC_MESSAGES/admin-guide/installation.po +++ b/Documentation/locale/ja/LC_MESSAGES/admin-guide/installation.po @@ -361,3 +361,6 @@ msgstr "インストール ISO のグラフィカル起動では、systemd が X msgid "图形安装器可随时通过侧栏的“查看日志 (F4)”按钮或 F4 打开独立日志窗口, 安装期间和结果页面均可使用;关闭日志窗口不会退出安装器或中断安装。 窗口显示最近约 8 KiB 日志,默认每秒刷新并跟随新内容;取消“跟随日志”可暂停阅读, 也可点击“刷新”手动更新。日志可滚动和复制,完整内容仍保存在上述日志文件中。 控制台安装器在进度页用 F4 显示或隐藏日志。" msgstr "グラフィカルインストーラーでは、サイドバーの「ログを表示 (F4)」ボタンまたは F4 で、インストール中や結果画面を含め、いつでも独立したログウィンドウを開けます。ログウィンドウを閉じても、インストーラーは終了せず、インストールも中断しません。直近の約 8 KiB のログを表示し、既定では毎秒更新して新しい出力を追尾します。「ログを追尾」を解除すると表示を一時停止でき、「更新」で手動更新できます。ログはスクロールとコピーが可能で、完全な内容は上記のログファイルに保存されます。コンソールインストーラーでは、進捗ページで F4 を押すとログを表示または非表示にします。" + +msgid "下载和安装阶段按 pacman 的实际进度更新总进度条,下方另有当前软件包的百分比进度条。 下载时显示待下载、已下载数量、当前软件包,以及下载量、传输速度和预计剩余时间; 安装时切换为待安装、已安装数量和当前包的安装百分比。已缓存的软件包无需重新下载, 下载数量可以少于安装数量。包事务完成后继续显示配置及引导安装进度。" +msgstr "ダウンロードとインストール中は、pacman の実際の進捗に従って全体の進捗バーが更新され、その下に現在のパッケージの進捗バーが表示されます。ダウンロード中は未完了・完了済みの件数、現在のパッケージ、転送量、速度、推定残り時間を表示します。インストール中は未インストール・インストール済みの件数と現在のパッケージのインストール率に切り替わります。キャッシュ済みのパッケージは再ダウンロードが不要なため、ダウンロード件数はインストール件数より少なくなる場合があります。パッケージ処理が完了すると、システム設定とブートローダーのインストールの進捗を表示します。" diff --git a/configs/nls/po/installer/installer.pot b/configs/nls/po/installer/installer.pot index cd6590de..c4f51906 100644 --- a/configs/nls/po/installer/installer.pot +++ b/configs/nls/po/installer/installer.pot @@ -1185,3 +1185,67 @@ msgstr "" #: userland/apps/installer/installer_plan.c:425 msgid "unformatted" msgstr "" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for download list" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for package list" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Pending downloads: %u" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Pending packages: %u" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Downloaded packages: %u" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Installed packages: %u" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +msgid "Verifying downloaded packages" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +msgid "Package installation complete" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Downloading: %s (%u%%)" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Installing: %s (%u%%)" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for package transaction" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Current download: %s" +msgstr "" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Total download: %s" +msgstr "" + +#: userland/apps/installer/install_ops.c +msgid "Running package hooks" +msgstr "" diff --git a/configs/nls/po/installer/ja_JP.po b/configs/nls/po/installer/ja_JP.po index 81da98f1..02039fff 100644 --- a/configs/nls/po/installer/ja_JP.po +++ b/configs/nls/po/installer/ja_JP.po @@ -1264,3 +1264,67 @@ msgstr "root パスワード" #: userland/apps/installer/installer_plan.c:425 msgid "unformatted" msgstr "未フォーマット" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for download list" +msgstr "ダウンロード一覧を取得しています" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for package list" +msgstr "パッケージ一覧を取得しています" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Pending downloads: %u" +msgstr "未ダウンロード:%u" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Pending packages: %u" +msgstr "未インストール:%u" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Downloaded packages: %u" +msgstr "ダウンロード済み:%u" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Installed packages: %u" +msgstr "インストール済み:%u" + +#: userland/apps/installer/installer_package_progress.c +msgid "Verifying downloaded packages" +msgstr "ダウンロードしたパッケージを検証しています" + +#: userland/apps/installer/installer_package_progress.c +msgid "Package installation complete" +msgstr "パッケージのインストールが完了しました" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Downloading: %s (%u%%)" +msgstr "ダウンロード中:%s(%u%%)" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Installing: %s (%u%%)" +msgstr "インストール中:%s(%u%%)" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for package transaction" +msgstr "パッケージ処理を待機しています" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Current download: %s" +msgstr "現在のダウンロード:%s" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Total download: %s" +msgstr "ダウンロード全体:%s" + +#: userland/apps/installer/install_ops.c +msgid "Running package hooks" +msgstr "パッケージフックを実行しています" diff --git a/configs/nls/po/installer/zh_CN.po b/configs/nls/po/installer/zh_CN.po index ab240084..48dc311c 100644 --- a/configs/nls/po/installer/zh_CN.po +++ b/configs/nls/po/installer/zh_CN.po @@ -1262,3 +1262,67 @@ msgstr "root 密码" #: userland/apps/installer/installer_plan.c:425 msgid "unformatted" msgstr "未格式化" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for download list" +msgstr "等待下载列表" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for package list" +msgstr "等待软件包列表" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Pending downloads: %u" +msgstr "待下载软件包:%u" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Pending packages: %u" +msgstr "待安装软件包:%u" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Downloaded packages: %u" +msgstr "已下载软件包:%u" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Installed packages: %u" +msgstr "已安装软件包:%u" + +#: userland/apps/installer/installer_package_progress.c +msgid "Verifying downloaded packages" +msgstr "正在验证已下载的软件包" + +#: userland/apps/installer/installer_package_progress.c +msgid "Package installation complete" +msgstr "软件包安装完成" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Downloading: %s (%u%%)" +msgstr "正在下载:%s(%u%%)" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Installing: %s (%u%%)" +msgstr "正在安装:%s(%u%%)" + +#: userland/apps/installer/installer_package_progress.c +msgid "Waiting for package transaction" +msgstr "等待软件包事务" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Current download: %s" +msgstr "当前下载:%s" + +#: userland/apps/installer/installer_package_progress.c +#, c-format +msgid "Total download: %s" +msgstr "下载总计:%s" + +#: userland/apps/installer/install_ops.c +msgid "Running package hooks" +msgstr "正在运行软件包钩子" diff --git a/packages/arch/reliefos-apps/PKGBUILD b/packages/arch/reliefos-apps/PKGBUILD index 9782d67f..5fadfa5a 100644 --- a/packages/arch/reliefos-apps/PKGBUILD +++ b/packages/arch/reliefos-apps/PKGBUILD @@ -83,6 +83,8 @@ package_reliefos-installer() { install_app installer install -Dm755 "$RELIEFOS_SOURCE_ROOT/userland/apps/installer/arch-online-install.sh" \ "$pkgdir/usr/libexec/reliefos/arch-online-install" + install -Dm644 "$RELIEFOS_SOURCE_ROOT/userland/apps/installer/arch-package-progress.awk" \ + "$pkgdir/usr/libexec/reliefos/arch-package-progress.awk" install -Dm644 "$RELIEFOS_SOURCE_ROOT/tools/build/arch-guest-packages.sh" \ "$pkgdir/usr/libexec/reliefos/arch-guest-packages" install -Dm644 "$RELIEFOS_SOURCE_ROOT/tools/build/arch-applications.list" \ diff --git a/system/installer/icewm/preferences b/system/installer/icewm/preferences index bea90200..15d694a2 100644 --- a/system/installer/icewm/preferences +++ b/system/installer/icewm/preferences @@ -1,6 +1,6 @@ # A dedicated live session; do not start installed-desktop applications. ShowTaskBar=1 -TaskBarShowStartMenu=0 +TaskBarShowStartMenu=1 TaskBarShowWindowListMenu=1 TaskBarShowMailboxStatus=0 TaskBarShowCPUStatus=0 diff --git a/tools/build/arch-guest-packages.sh b/tools/build/arch-guest-packages.sh index 19019bf8..e88a4562 100644 --- a/tools/build/arch-guest-packages.sh +++ b/tools/build/arch-guest-packages.sh @@ -35,7 +35,9 @@ reliefos_guest_packages() { local -a application_packages glibc_only_packages reliefos_application_packages installer || return local_packages+=("${application_packages[@]}") - official_packages+=(core/grub extra/icewm extra/xorg-server extra/xorg-xinit extra/xorg-xauth + # FLTK creates core X11 cursors from the cursor font. TTF fonts + # alone do not supply it, even when the WM's pointer is visible. + official_packages+=(core/grub extra/icewm extra/xorg-server extra/xorg-xinit extra/xorg-xauth extra/xorg-fonts-misc extra/xf86-video-fbdev extra/xf86-input-evdev extra/ttf-dejavu) ;; console) ;; diff --git a/tools/test_installer_input.py b/tools/test_installer_input.py index 10fdc56a..db719a40 100644 --- a/tools/test_installer_input.py +++ b/tools/test_installer_input.py @@ -10,6 +10,59 @@ class InstallerInputTests(unittest.TestCase): + def test_package_telemetry_validates_counters_and_partial_install_progress(self): + with tempfile.TemporaryDirectory(prefix="installer-packages-") as tmp: + executable = Path(tmp) / "packages" + subprocess.run([ + "cc", "-std=c11", "-O1", "-g", "-Wall", "-Wextra", "-Werror", + "-fsanitize=address,undefined", "-fno-sanitize-recover=all", + "tools/tests/installer_package_progress_test.c", + "userland/apps/installer/installer_package_progress.c", "-o", executable, + ], cwd=ROOT, check=True) + subprocess.run([executable], cwd=ROOT, check=True, timeout=10) + + def test_pacman_redraws_report_parallel_downloads_and_failed_hooks(self): + with tempfile.TemporaryDirectory(prefix="installer-pacman-") as tmp: + marker = Path(tmp) / "downloaded" + collector = ["awk", "-v", "total=3", "-v", f"marker={marker}", + "-f", "userland/apps/installer/arch-package-progress.awk"] + trace = ( + ":: Retrieving packages...\r\n" + " Total (0/2) 0.0 KiB 0 KiB/s 00:00 [---] 0%\r" + "\033[2A alpha-1.0-1-x86_64 2.0 MiB 1.0 MiB/s 00:02 [#--] 25%\r" + " Total (0/2) 6.0 MiB 2.0 MiB/s 00:02 [##-] 60%\r" + " beta-1.0-1-x86_64 1.0 MiB 1.0 MiB/s 00:00 [###] 100%\r" + " Total (1/2) 7.0 MiB 2.0 MiB/s 00:01 [##-] 70%\r" + " alpha-1.0-1-x86_64 9.0 MiB 2.0 MiB/s 00:00 [###] 100%\r" + " Total (2/2) 10.0 MiB 2.0 MiB/s 00:00 [###] 100%\r" + "(3/3) checking package integrity [###] 100%\r\n" + ":: Processing package changes...\r\n" + "(1/3) installing alpha [---] 0%\r" + "(1/3) installing alpha [#--] 50%\r" + "(1/3) installing alpha [###] 100%\r\n" + "(2/3) installing beta [###] 100%\r\n" + "(3/3) installing cached [###] 100%\r\n" + ":: Running post-transaction hooks...\r\n" + ) + result = subprocess.run(collector, input=trace, capture_output=True, text=True, + cwd=ROOT, check=True) + self.assertNotIn("\x1b", result.stdout) + records = [line.split("\t") for line in result.stdout.splitlines() + if line.startswith("@reliefos-package ")] + self.assertTrue(marker.is_file()) + self.assertTrue(any(row[0] == "@reliefos-package 1 3 0 2 0 25 60" + and row[1] == "alpha-1.0-1-x86_64" for row in records)) + self.assertTrue(any(row[0] == "@reliefos-package 3 3 0 2 2 50 100" + and row[1] == "alpha" for row in records)) + self.assertEqual(records[-1][0], "@reliefos-package 4 3 3 2 2 100 100") + single = subprocess.run(collector, input=" solo 2.0 MiB 1.0 MiB/s 00:00 [###] 100%\r", + capture_output=True, text=True, cwd=ROOT, check=True) + self.assertIn("@reliefos-package 1 3 0 1 1 100 100", single.stdout) + failed = subprocess.run(collector, input=trace + "error: hook failed\r\n", + capture_output=True, text=True, cwd=ROOT) + self.assertNotEqual(failed.returncode, 0) + self.assertIn("error: hook failed", failed.stdout) + def test_wrapped_labels_preserve_words_utf8_and_reflow(self): """Keep all label text visible as width, language and font metrics change.""" import os @@ -87,7 +140,8 @@ def test_installer_progress_tracks_online_packages(self): "cc", "-std=gnu11", "-D_GNU_SOURCE", "-O1", "-g", "-ffunction-sections", "-fdata-sections", "-Wl,--gc-sections", *INSTALLER_HOST_INCLUDES, - "tools/tests/installer_progress_test.c", "-o", executable, + "tools/tests/installer_progress_test.c", + "userland/apps/installer/installer_package_progress.c", "-o", executable, ], cwd=ROOT, check=True) subprocess.run([executable, tmp], cwd=ROOT, check=True, timeout=10) diff --git a/tools/test_installer_swap_host_compile.py b/tools/test_installer_swap_host_compile.py index cc22f6fe..1baf85b6 100644 --- a/tools/test_installer_swap_host_compile.py +++ b/tools/test_installer_swap_host_compile.py @@ -21,7 +21,7 @@ def main(): compat.write_text('#include \n') sources=['install_ops.c','installer_capacity.c','installer_swap.c','installer_swap_bundle.c', 'installer_swap_config.c','installer_swap_prepare.c','installer_swap_storage.c','installer_tty.c', - 'installer_tui.c','installer_tui_job.c','installer_job.c','installer_log.c'] + 'installer_tui.c','installer_tui_job.c','installer_job.c','installer_log.c','installer_package_progress.c'] for name in sources: selected_headers=base_headers if name=='installer_swap_storage.c' else headers # glibc must see the XSI feature level before the forced include. diff --git a/tools/test_installer_swap_tty.py b/tools/test_installer_swap_tty.py index 78bc693f..7d72bfa9 100644 --- a/tools/test_installer_swap_tty.py +++ b/tools/test_installer_swap_tty.py @@ -20,7 +20,7 @@ def compile_fixture(binary): sources = ["installer_tui.c", "installer_tui_job.c", "installer_job.c", "installer_log.c", "installer_tui_partitions.c", "installer_tty.c", "model.c", - "installer_capacity.c", "installer_partitions.c", "apache_license.S"] + "installer_capacity.c", "installer_partitions.c", "installer_package_progress.c", "apache_license.S"] subprocess.run([ "cc", "-std=gnu11", "-D_GNU_SOURCE", "-O1", "-g", "-Wall", "-Wextra", "-Werror", "-fsanitize=address,undefined", "-fno-omit-frame-pointer", "-fno-pie", "-no-pie", diff --git a/tools/tests/installer_package_progress_test.c b/tools/tests/installer_package_progress_test.c new file mode 100644 index 00000000..0830611c --- /dev/null +++ b/tools/tests/installer_package_progress_test.c @@ -0,0 +1,60 @@ +#include "../../userland/apps/installer/installer_package_progress.h" +#include +#include +#include + +int main(int argc, char **argv) +{ + struct installer_package_progress state = {0}, saved; + struct installer_package_labels labels; + if (argc == 2 && !strcmp(argv[1], "--records")) { + char line[2048]; + while (fgets(line, sizeof(line), stdin)) { + line[strcspn(line, "\n")] = 0; + if (!installer_package_progress_parse(&state, line)) continue; + printf("%u %u %u %u %u %u %u %s\n", state.phase, + installer_package_progress_value(&state), state.completed, state.total, + state.downloaded, state.download_total, state.percent, state.name); + } + return 0; + } + assert(argc == 1); + assert(installer_package_progress_parse(&state, + "@reliefos-package 1 3 0 2 1 25 60\talpha\t2.0 MiB 1.0 MiB/s 00:02\t6.0 MiB 2.0 MiB/s 00:02")); + assert(installer_package_progress_value(&state) == 45); + installer_package_progress_format(&state, &labels); + assert(!strcmp(labels.pending, "Pending downloads: 1")); + assert(!strcmp(labels.completed, "Downloaded packages: 1")); + assert(strstr(labels.current, "alpha (25%)")); + assert(strstr(labels.transfer, "1.0 MiB/s")); + saved = state; + const char *invalid[] = { + "diagnostic only", "@reliefos-package 1 3 0 2 3 0 60\talpha\t-\t-", + "@reliefos-package 3 3 4 2 2 0 100\talpha\t-\t-", + "@reliefos-package 3 3 0 2 2 101 100\talpha\t-\t-", + "@reliefos-package 3 4294967297 0 0 0 0 0\talpha\t-\t-", + "@reliefos-package 3 3 0 0 0 0 0\talpha\t-", + "@reliefos-package 3 3 0 0 0 0 0\talpha bad\t-\t-", + "@reliefos-package 3 3 0 0 0 0 0\talpha\t-\t-\ttrailing", + }; + for (unsigned i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i) { + assert(!installer_package_progress_parse(&state, invalid[i])); + assert(!memcmp(&state, &saved, sizeof(state))); + } + assert(installer_package_progress_parse(&state, + "@reliefos-package 3 3 1 2 2 50 100\tbeta\t-\t-")); + assert(installer_package_progress_value(&state) == 68); + installer_package_progress_format(&state, &labels); + assert(!strcmp(labels.pending, "Pending packages: 2")); + assert(!strcmp(labels.completed, "Installed packages: 1")); + assert(!strcmp(labels.current, "Installing: beta (50%)")); + assert(!*labels.transfer && !*labels.total_transfer); + assert(installer_package_progress_parse(&state, + "@reliefos-package 3 3 2 2 2 100 100\tbeta\t-\t-")); + assert(installer_package_progress_value(&state) == 73); /* Do not count beta twice. */ + assert(installer_package_progress_parse(&state, + "@reliefos-package 4 3 3 2 2 100 100\t-\t-\t-")); + assert(installer_package_progress_value(&state) == 82); + puts("PASS package progress: counters, fractions, download details and malformed records"); + return 0; +} diff --git a/tools/tests/installer_progress_test.c b/tools/tests/installer_progress_test.c index 5ee9085d..3a079c66 100644 --- a/tools/tests/installer_progress_test.c +++ b/tools/tests/installer_progress_test.c @@ -14,7 +14,7 @@ static int progress_spawn(pid_t *pid, const char *path, const posix_spawn_file_a #undef printf #undef posix_spawn -static unsigned output_calls, refresh_calls, package_progress; +static unsigned output_calls, refresh_calls, last_package_progress; static unsigned long test_time; /** @brief Count status output emitted by production progress presentation. */ @@ -31,7 +31,8 @@ unsigned long reliefos_uptime_ms(void) { return test_time; } void refresh_ui(void) { ++refresh_calls; - if (strcmp(status_text, "Installing packages") == 0) package_progress = progress_value; + if (strcmp(status_text, "Installing packages") == 0 || strcmp(status_text, "Running package hooks") == 0) + last_package_progress = progress_value; } /** @brief Use a short-lived child and publish the download milestone before it exits. */ @@ -44,8 +45,14 @@ static int progress_spawn(pid_t *pid, const char *path, const posix_spawn_file_a assert(snprintf(marker, sizeof(marker), "%s/packages-downloaded", argv[2]) < (int)sizeof(marker)); FILE *file = fopen(marker, "w"); assert(file && fclose(file) == 0); - char *const child[] = {(char *)"sleep", (char *)"0.3", NULL}; - return posix_spawn(pid, "/bin/sleep", actions, attributes, child, envp); + /* Split a record across writes and leave the final snapshot immediately + * before exit. The production reader must retain both without waiting for + * a full line in its UI loop or losing the tail when waitpid succeeds. */ + char *const child[] = {(char *)"sh", (char *)"-c", (char *) + "printf '@reliefos-package 3 3 1 2 2 50 100'; sleep 0.1; " + "printf '\talpha\t-\t-\n'; sleep 0.1; " + "printf '@reliefos-package 4 3 3 2 2 100 100\t-\t-\t-\n'", NULL}; + return posix_spawn(pid, "/bin/sh", actions, attributes, child, envp); } /** @brief Short I/O slices must not turn either frontend into a per-slice logger. */ @@ -55,7 +62,10 @@ int main(int argc, char **argv) installer_tty_mode = 1; test_time = 1000; assert(installer_online_run("install", argv[1], 32, "Downloading packages") == 0); - assert(package_progress > 32 && package_progress < 83); + assert(last_package_progress > 32 && last_package_progress < 83); + assert(last_package_progress == 82); + assert(package_progress.phase == INSTALLER_PACKAGES_HOOKS); + assert(package_progress.completed == 3 && package_progress.total == 3); puts("PASS installer progress: separate download/install stages"); return 0; } diff --git a/userland/apps/installer/Kbuild b/userland/apps/installer/Kbuild index dcf56dd5..d82c9dca 100644 --- a/userland/apps/installer/Kbuild +++ b/userland/apps/installer/Kbuild @@ -6,6 +6,8 @@ RELIEFOS_APP_OBJECTS += installer_tui.o installer_tui_job.o installer_tui_partit RELIEFOS_APP_C_OBJECTS += installer_tui.o installer_tui_job.o installer_tui_partitions.o installer_job.o RELIEFOS_APP_OBJECTS += installer_plan.o installer_log.o RELIEFOS_APP_C_OBJECTS += installer_plan.o installer_log.o +RELIEFOS_APP_OBJECTS += installer_package_progress.o +RELIEFOS_APP_C_OBJECTS += installer_package_progress.o RELIEFOS_APP_ASM_OBJECTS := apache_license.o ifneq ($(RELIEFOS_CAPTURE_APP_KBUILD),1) include $(srctree)/scripts/reliefos/Makefile.app-kbuild diff --git a/userland/apps/installer/arch-online-install.sh b/userland/apps/installer/arch-online-install.sh index c448ba30..df0508f8 100644 --- a/userland/apps/installer/arch-online-install.sh +++ b/userland/apps/installer/arch-online-install.sh @@ -19,20 +19,19 @@ retry() { # Pacman verifies the cached archives as part of the install transaction. A # separate download-only transaction would read and verify every archive twice. install_packages() { - local marker=$work/packages-downloaded log=$work/transaction.log attempt + local marker=$work/packages-downloaded log=$work/transaction.log attempt command total + read -r total < "$work/package-count" + [[ $total =~ ^[1-9][0-9]{0,5}$ ]] || fail 'invalid package count' + # Pacman disables its progress callbacks when stdout is a pipe. A private + # PTY preserves the official package transaction and its exit status while + # the collector turns redraws into frontend telemetry and readable logs. + printf -v command '%q ' stdbuf -oL "${pacman[@]}" --logfile "$work/install-pacman.log" \ + -S "${guest_packages[@]}" for attempt in 1 2 3; do - if stdbuf -oL "${pacman[@]}" --logfile "$work/install-pacman.log" \ - -S "${guest_packages[@]}" 2>&1 | awk -v marker="$marker" ' - /(^|\r):: Processing package changes[.][.][.]\r?$/ { - printf "%s", "" > marker - close(marker) - print "[arch-online] package downloads verified; starting installation" - writing = 1 - } - writing && /(^|\r)error:/ { failed = 1 } - { print; fflush() } - END { if (failed) exit 1 } - ' | tee "$log"; then + if TERM=dumb SHELL=/bin/bash script --quiet --flush --return \ + --command "stty cols 640 rows 24 && exec $command" /dev/null 2>&1 | + awk -v marker="$marker" -v total="$total" \ + -f /usr/libexec/reliefos/arch-package-progress.awk | tee "$log"; then return 0 fi # The download error is reported before the package transaction starts. @@ -159,6 +158,9 @@ CONF if (!packages || !bytes || bytes > 1000000000000) exit 1 printf "%.0f\n", 4 * bytes + 536870912 }' "$work/package-sizes" > "$work/root-bytes" + awk '/^size=[0-9]+$/ { packages++ } END { print packages }' \ + "$work/package-sizes" > "$work/package-count" + printf '@reliefos-package 0 %s 0 0 0 0 0\t-\t-\t-\n' "$(<"$work/package-count")" ;; install|configure) [[ $root == /* && -d $root && ! -L $root && $root != / ]] || fail 'invalid target' diff --git a/userland/apps/installer/arch-package-progress.awk b/userland/apps/installer/arch-package-progress.awk new file mode 100644 index 00000000..20565268 --- /dev/null +++ b/userland/apps/installer/arch-package-progress.awk @@ -0,0 +1,89 @@ +# Consume pacman's C-locale PTY redraws. Keep errors and completed progress in +# the log, and flush bounded records for the GUI/TUI worker on every change. +BEGIN { + RS = "[\r\n]" + phase = 1 + name = transfer = total_transfer = "-" + emit() +} + +function emit( record) { + record = sprintf("@reliefos-package %u %u %u %u %u %u %u\t%s\t%s\t%s", + phase, total, completed, download_total, downloaded, percent, download_percent, + name, transfer, total_transfer) + if (record != previous) { print record; fflush(); previous = record } +} + +{ + # Cursor positioning for parallel downloads must never reach the log or UI. + gsub(/\033\[[0-9;?]*[A-Za-z]/, "") + sub(/^[[:space:]]+/, "") + sub(/[[:space:]]+$/, "") + if (!$0) next + if ($0 == ":: Processing package changes...") { + printf "%s", "" > marker + close(marker) + print "[arch-online] package downloads verified; starting installation" + phase = 3 + name = transfer = "-" + percent = 0 + download_percent = 100 + emit() + } + if (phase >= 3 && /^error:/) failed = 1 + if (match($0, /\][[:space:]]+([0-9]{1,3})%$/, progress) && progress[1] <= 100) { + value = progress[1] + 0 + if (match($0, /^\([[:space:]]*([0-9]+)\/[[:space:]]*([0-9]+)\)[[:space:]]+(installing|upgrading|downgrading|reinstalling)[[:space:]]+([^[:space:]]+)/, package)) { + if (package[1] > 0 && package[1] <= package[2] && package[2] <= 1000000) { + phase = 3 + total = package[2] + 0 + completed = package[1] - (value < 100) + percent = value + name = package[4] + emit() + } + } else if (phase < 3 && match($0, /^Total[[:space:]]+\([[:space:]]*([0-9]+)\/[[:space:]]*([0-9]+)\)[[:space:]]+/, count)) { + if (count[1] <= count[2] && count[2] <= 1000000) { + download_total = count[2] + 0 + downloaded = count[1] + 0 + have_total = 1 + if (value > download_percent) download_percent = value + total_transfer = substr($0, RLENGTH + 1) + sub(/[[:space:]]*\[.*$/, "", total_transfer) + sub(/[[:space:]]+$/, "", total_transfer) + emit() + } + } else if (phase < 3 && match($0, /^([^[:space:]()]+)[[:space:]]+/, file) && $0 !~ /^\(/) { + phase = 1 + name = file[1] + percent = value + transfer = substr($0, RLENGTH + 1) + sub(/[[:space:]]*\[.*$/, "", transfer) + sub(/[[:space:]]+$/, "", transfer) + # A one-package download has no Total progress bar. + if (!have_total) { + download_total = 1 + downloaded = (value == 100) + download_percent = value + } + emit() + } else if (phase < 3 && /^\(/) { + phase = 2 + download_percent = 100 + emit() + } + if (value == 100) { print; fflush() } + next + } + if ($0 == ":: Running post-transaction hooks..." && phase == 3) { + phase = 4 + completed = total + name = "-" + percent = 100 + emit() + } + print + fflush() +} + +END { if (failed) exit 1 } diff --git a/userland/apps/installer/install_ops.c b/userland/apps/installer/install_ops.c index 7692a668..2ad4b01f 100644 --- a/userland/apps/installer/install_ops.c +++ b/userland/apps/installer/install_ops.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,7 @@ char status_text[128] = "Ready"; char detail_text[128] = ""; char progress_text[256] = "Ready"; uint32_t progress_value; +struct installer_package_progress package_progress; uint8_t install_success; int reboot_error; uint8_t install_running; @@ -997,9 +999,52 @@ static int installer_online_downloaded(const char *work) return n >= 0 && (size_t)n < sizeof(marker) && access(marker, F_OK) == 0; } +/* Drain bounded helper output without blocking the worker or waiting for a + * newline. A partial record survives until the next read. Long diagnostics are + * logged in chunks and never treated as progress records. */ +struct installer_online_output { + char line[2048]; + size_t used; + int fragmented, eof; +}; + +static void installer_online_line(struct installer_online_output *output) +{ + output->line[output->used] = 0; + if (output->fragmented || !installer_package_progress_parse(&package_progress, output->line)) { + fwrite(output->line, 1, output->used, stdout); + putchar('\n'); + } + output->used = 0; + output->fragmented = 0; +} + +static int installer_online_output_read(int fd, struct installer_online_output *output) +{ + char buffer[4096]; + size_t budget = 32768; + while (budget) { + size_t length = budget < sizeof(buffer) ? budget : sizeof(buffer); + ssize_t count = read(fd, buffer, length); + if (count < 0 && errno == EINTR) continue; + if (count <= 0) { if (!count) output->eof = 1; return 0; } + budget -= (size_t)count; + for (ssize_t i = 0; i < count; ++i) { + if (buffer[i] == '\n') { installer_online_line(output); continue; } + if (output->used == sizeof(output->line) - 1) { + fwrite(output->line, 1, output->used, stdout); + output->used = 0; + output->fragmented = 1; + } + output->line[output->used++] = buffer[i]; + } + } + return 1; +} + /** - * @brief Run an online helper and publish the current phase to both frontends. - * @param operation Fixed helper subcommand; install reports the download milestone. + * @brief Run an online helper and publish live package telemetry to both frontends. + * @param operation Fixed helper subcommand. * @param work Borrowed installer state directory. * @param progress Initial progress value. * @param message Initial localized display label. @@ -1019,25 +1064,59 @@ static int installer_online_run(const char *operation, const char *work, pid_t child; int status; unsigned long start = reliefos_uptime_ms(); - int downloading = text_eq(operation, "install"); + int installing = text_eq(operation, "install"); show_progress(progress, message, ""); - int result = posix_spawn(&child, helper, NULL, NULL, argv, environ); - if (result) return -result; + int descriptors[2]; + if (pipe(descriptors) < 0) return -errno; + int result = 0; + if (fcntl(descriptors[0], F_SETFL, O_NONBLOCK) < 0 || + fcntl(descriptors[0], F_SETFD, FD_CLOEXEC) < 0 || + fcntl(descriptors[1], F_SETFD, FD_CLOEXEC) < 0) result = errno; + posix_spawn_file_actions_t actions; + int initialized = 0; + if (!result) { result = posix_spawn_file_actions_init(&actions); initialized = !result; } + if (!result) result = posix_spawn_file_actions_addclose(&actions, descriptors[0]); + if (!result) result = posix_spawn_file_actions_adddup2(&actions, descriptors[1], STDOUT_FILENO); + if (!result) result = posix_spawn_file_actions_adddup2(&actions, descriptors[1], STDERR_FILENO); + if (!result) result = posix_spawn_file_actions_addclose(&actions, descriptors[1]); + if (!result) result = posix_spawn(&child, helper, &actions, NULL, argv, environ); + if (initialized) posix_spawn_file_actions_destroy(&actions); + close(descriptors[1]); + if (result) { close(descriptors[0]); return -result; } + struct installer_online_output output = {0}; for (;;) { + installer_online_output_read(descriptors[0], &output); pid_t pid = waitpid(child, &status, WNOHANG); - if (pid == child) break; + if (pid == child) { + /* The child is reaped; consume its remaining records before final + * publication, without waiting on inherited daemon descriptors. */ + while (installer_online_output_read(descriptors[0], &output)) {} + if (output.used) installer_online_line(&output); + break; + } if (pid < 0 && errno == EINTR) continue; - if (pid < 0) return -errno; - if (downloading && installer_online_downloaded(work)) { - downloading = 0; - progress = 55; - message = T("Installing packages"); - start = reliefos_uptime_ms(); + if (pid < 0) { int error = errno; close(descriptors[0]); return -error; } + if (installing) { + if (package_progress.phase >= INSTALLER_PACKAGES_INSTALL || installer_online_downloaded(work)) { + if (progress < 55) progress = 55; + message = package_progress.phase == INSTALLER_PACKAGES_HOOKS + ? T("Running package hooks") : T("Installing packages"); + } else if (package_progress.phase == INSTALLER_PACKAGES_VERIFY) { + message = T("Verifying downloaded packages"); + } + unsigned value = installer_package_progress_value(&package_progress); + if (value > progress) progress = value; } char detail[96]; snprintf(detail, sizeof(detail), T("Elapsed time: %lu s"), (reliefos_uptime_ms() - start) / 1000); show_progress(progress, message, detail); - nanosleep(&(struct timespec){.tv_sec = 1}, NULL); + struct pollfd descriptor = {.fd = output.eof ? -1 : descriptors[0], .events = POLLIN}; + (void)poll(&descriptor, 1, 100); + } + close(descriptors[0]); + if (installing) { + unsigned value = installer_package_progress_value(&package_progress); + show_progress(value > progress ? value : progress, message, ""); } if (WIFEXITED(status) && WEXITSTATUS(status) == 0) return 0; fprintf(stderr, "[installer.elf] online stage %s failed (wait status %#x)\n", operation, (unsigned)status); @@ -1180,6 +1259,7 @@ static int perform_online_install(const char **failure) int perform_install(void) { int ret; + memset(&package_progress, 0, sizeof(package_progress)); if (!confirmation_ok()) { finish_install(-EPERM, T("Installation has not been confirmed")); return -EPERM; diff --git a/userland/apps/installer/install_ops.h b/userland/apps/installer/install_ops.h index e421ac3f..4f089821 100644 --- a/userland/apps/installer/install_ops.h +++ b/userland/apps/installer/install_ops.h @@ -13,6 +13,7 @@ extern "C" { #include #include "installer_setup.h" +#include "installer_package_progress.h" #include "model.h" /* Shared page names used by the installation backend. */ @@ -48,6 +49,7 @@ extern char status_text[128]; extern char detail_text[128]; extern char progress_text[256]; extern uint32_t progress_value; +extern struct installer_package_progress package_progress; extern uint8_t install_success; extern uint8_t install_running; extern int reboot_error; diff --git a/userland/apps/installer/installer_job.c b/userland/apps/installer/installer_job.c index 73bcfd1a..28f00b1f 100644 --- a/userland/apps/installer/installer_job.c +++ b/userland/apps/installer/installer_job.c @@ -138,6 +138,9 @@ int installer_job_step(struct installer_job *job) if (job->complete || job->incoming.progress > 100) job->error = EPROTO; job->incoming.message[sizeof(job->incoming.message) - 1] = 0; job->incoming.detail[sizeof(job->incoming.detail) - 1] = 0; + job->incoming.packages.name[sizeof(job->incoming.packages.name) - 1] = 0; + job->incoming.packages.transfer[sizeof(job->incoming.packages.transfer) - 1] = 0; + job->incoming.packages.total_transfer[sizeof(job->incoming.packages.total_transfer) - 1] = 0; job->latest = job->incoming; if (job->incoming.complete == 1) { job->final = job->incoming; diff --git a/userland/apps/installer/installer_job.h b/userland/apps/installer/installer_job.h index 8ffa307e..16e161d4 100644 --- a/userland/apps/installer/installer_job.h +++ b/userland/apps/installer/installer_job.h @@ -4,6 +4,7 @@ #include #include #include +#include "installer_package_progress.h" #ifdef __cplusplus extern "C" { @@ -13,6 +14,7 @@ struct installer_job_packet { unsigned complete, progress; int result, selected, root, esp; unsigned automatic, replaced, format_esp, success; + struct installer_package_progress packages; char message[256], detail[768], boot_file[128]; }; diff --git a/userland/apps/installer/installer_package_progress.c b/userland/apps/installer/installer_package_progress.c new file mode 100644 index 00000000..4fbd9a9f --- /dev/null +++ b/userland/apps/installer/installer_package_progress.c @@ -0,0 +1,94 @@ +#include "installer_package_progress.h" +#include +#include +#include +#include +#include +#include + +#define T(s) gettext(s) + +static int field(const char **input, char *output, size_t capacity, int last) +{ + const char *end = last ? *input + strlen(*input) : strchr(*input, '\t'); + if (!end || end == *input || (size_t)(end - *input) >= capacity) return 0; + for (const char *p = *input; p < end; ++p) + if ((unsigned char)*p < 32 || (unsigned char)*p > 126) return 0; + size_t count = (size_t)(end - *input); + memcpy(output, *input, count); + output[count] = 0; + if (!strcmp(output, "-")) output[0] = 0; + *input = end + !last; + return 1; +} + +int installer_package_progress_parse(struct installer_package_progress *state, const char *line) +{ + static const char prefix[] = "@reliefos-package "; + if (!state || !line || strncmp(line, prefix, sizeof(prefix) - 1)) return 0; + const char *p = line + sizeof(prefix) - 1; + unsigned numbers[7]; + for (unsigned i = 0; i < 7; ++i) { + if (*p < '0' || *p > '9') return 0; + char *end; + errno = 0; + unsigned long value = strtoul(p, &end, 10); + if (errno || value > 1000000 || *end != (i == 6 ? '\t' : ' ')) return 0; + numbers[i] = (unsigned)value; + p = end + 1; + } + struct installer_package_progress next = { + .phase = numbers[0], .total = numbers[1], .completed = numbers[2], + .download_total = numbers[3], .downloaded = numbers[4], + .percent = numbers[5], .download_percent = numbers[6], + }; + if (next.phase > INSTALLER_PACKAGES_HOOKS || next.completed > next.total || + next.downloaded > next.download_total || next.percent > 100 || next.download_percent > 100 || + !field(&p, next.name, sizeof(next.name), 0) || + !field(&p, next.transfer, sizeof(next.transfer), 0) || + !field(&p, next.total_transfer, sizeof(next.total_transfer), 1)) return 0; + for (const char *n = next.name; *n; ++n) + if (*n == ' ') return 0; + *state = next; + return 1; +} + +unsigned installer_package_progress_value(const struct installer_package_progress *state) +{ + if (state->phase < INSTALLER_PACKAGES_VERIFY) + return 32 + 22 * state->download_percent / 100; + if (state->phase == INSTALLER_PACKAGES_VERIFY) return 54; + if (!state->total) return 55; + uint64_t done = (uint64_t)state->completed * 100; + if (state->completed < state->total && state->percent < 100) done += state->percent; + return 55 + (unsigned)(27 * done / ((uint64_t)state->total * 100)); +} + +void installer_package_progress_format(const struct installer_package_progress *state, + struct installer_package_labels *labels) +{ + memset(labels, 0, sizeof(*labels)); + int downloading = state->phase == INSTALLER_PACKAGES_DOWNLOAD || state->phase == INSTALLER_PACKAGES_VERIFY; + if (downloading && !state->download_total) + snprintf(labels->pending, sizeof(labels->pending), "%s", T("Waiting for download list")); + else if (!state->total) + snprintf(labels->pending, sizeof(labels->pending), "%s", T("Waiting for package list")); + else + snprintf(labels->pending, sizeof(labels->pending), downloading ? T("Pending downloads: %u") : T("Pending packages: %u"), + downloading ? state->download_total - state->downloaded : state->total - state->completed); + snprintf(labels->completed, sizeof(labels->completed), downloading ? T("Downloaded packages: %u") : T("Installed packages: %u"), + downloading ? state->downloaded : state->completed); + if (state->phase == INSTALLER_PACKAGES_VERIFY) + snprintf(labels->current, sizeof(labels->current), "%s", T("Verifying downloaded packages")); + else if (state->phase == INSTALLER_PACKAGES_HOOKS) + snprintf(labels->current, sizeof(labels->current), "%s", T("Package installation complete")); + else if (*state->name) + snprintf(labels->current, sizeof(labels->current), downloading ? T("Downloading: %s (%u%%)") : T("Installing: %s (%u%%)"), + state->name, state->percent); + else + snprintf(labels->current, sizeof(labels->current), "%s", T("Waiting for package transaction")); + if (downloading && *state->transfer) + snprintf(labels->transfer, sizeof(labels->transfer), T("Current download: %s"), state->transfer); + if (downloading && *state->total_transfer) + snprintf(labels->total_transfer, sizeof(labels->total_transfer), T("Total download: %s"), state->total_transfer); +} diff --git a/userland/apps/installer/installer_package_progress.h b/userland/apps/installer/installer_package_progress.h new file mode 100644 index 00000000..365b6459 --- /dev/null +++ b/userland/apps/installer/installer_package_progress.h @@ -0,0 +1,38 @@ +#ifndef RELIEFOS_INSTALLER_PACKAGE_PROGRESS_H +#define RELIEFOS_INSTALLER_PACKAGE_PROGRESS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum installer_package_phase { + INSTALLER_PACKAGES_WAITING, + INSTALLER_PACKAGES_DOWNLOAD, + INSTALLER_PACKAGES_VERIFY, + INSTALLER_PACKAGES_INSTALL, + INSTALLER_PACKAGES_HOOKS, +}; + +struct installer_package_progress { + unsigned phase, total, completed, download_total, downloaded; + unsigned percent, download_percent; + char name[256], transfer[128], total_transfer[128]; +}; + +struct installer_package_labels { + char pending[128], completed[128], current[384]; + char transfer[192], total_transfer[192]; +}; + +/* Parse one complete helper record. Reject malformed records without changing + * the last usable snapshot; no package output is ever interpreted as a command. */ +int installer_package_progress_parse(struct installer_package_progress *, const char *); +unsigned installer_package_progress_value(const struct installer_package_progress *); +void installer_package_progress_format(const struct installer_package_progress *, struct installer_package_labels *); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/userland/apps/installer/installer_tui_job.c b/userland/apps/installer/installer_tui_job.c index 5e5a5920..d03913a8 100644 --- a/userland/apps/installer/installer_tui_job.c +++ b/userland/apps/installer/installer_tui_job.c @@ -29,6 +29,7 @@ void installer_tui_publish_progress(void) { struct installer_job_packet packet = {0}; packet.progress = progress_value; + packet.packages = package_progress; snprintf(packet.message, sizeof(packet.message), "%s", status_text); snprintf(packet.detail, sizeof(packet.detail), "%s", detail_text); installer_job_publish(&packet); @@ -60,6 +61,7 @@ static int run_job(void *opaque, struct installer_job_packet *packet) if (!result && job->kind == TUI_JOB_INSTALL && context->boot_entry_path) context->boot_entry_path(packet->boot_file, sizeof(packet->boot_file)); packet->progress = progress_value; + packet->packages = package_progress; packet->selected = *context->selected_partition; packet->root = *context->root_partition; packet->esp = *context->esp_partition; @@ -100,6 +102,18 @@ int tui_run_job(const struct installer_tty_context *context, struct tui_job *job tui_text(&view, bar); tui_text(&view, *packet->message ? packet->message : T("Preparing operation")); tui_text(&view, packet->detail); + struct installer_package_labels labels; + installer_package_progress_format(&packet->packages, &labels); + tui_text(&view, labels.pending); + tui_text(&view, labels.current); + unsigned package_percent = packet->packages.percent > 100 ? 100 : packet->packages.percent; + memset(fill, ' ', 50); + memset(fill, '#', package_percent / 2); + snprintf(bar, sizeof(bar), "[%s] %3u%%", fill, package_percent); + tui_text(&view, bar); + tui_text(&view, labels.completed); + if (*labels.transfer) tui_text(&view, labels.transfer); + if (*labels.total_transfer) tui_text(&view, labels.total_transfer); tui_text(&view, T("Disk operations are running. Please wait for completion.")); tui_text(&view, log_path); tui_button(&view, T("Show / hide log (F4)"), TUI_LOG); @@ -114,6 +128,7 @@ int tui_run_job(const struct installer_tty_context *context, struct tui_job *job return job_error(result); } const struct installer_job_packet *final = &state.final; + package_progress = final->packages; if (job->kind == TUI_JOB_INSTALL) tui_report_install_result(final->result, final->result == 0 && final->success); *context->selected_partition = final->selected; diff --git a/userland/apps/installer/main.cpp b/userland/apps/installer/main.cpp index ad2369dc..aca6e602 100644 --- a/userland/apps/installer/main.cpp +++ b/userland/apps/installer/main.cpp @@ -102,6 +102,9 @@ static Fl_Box *detail_box; static Fl_Box *progress_text_box; static Fl_Box *progress_percent_box; static Fl_Progress *progress_bar; +static Fl_Box *package_pending_box, *package_completed_box, *package_current_box; +static Fl_Box *package_transfer_box, *package_total_transfer_box; +static Fl_Progress *package_progress_bar; static int ui_busy; static int license_accepted; static int primary_pending; @@ -302,6 +305,16 @@ static void refresh_status_widgets(void) progress_percent_box->copy_label(percent); } } + if (package_current_box) { + struct installer_package_labels labels; + installer_package_progress_format(&package_progress, &labels); + package_pending_box->copy_label(labels.pending); + package_completed_box->copy_label(labels.completed); + package_current_box->copy_label(labels.current); + package_transfer_box->copy_label(labels.transfer); + package_total_transfer_box->copy_label(labels.total_transfer); + package_progress_bar->value(package_progress.percent); + } } static void show_page(void); @@ -330,6 +343,7 @@ static int run_install_worker(void *, struct installer_job_packet *packet) packet->automatic = installer_partition_auto; packet->replaced = installer_partition_table_replaced; packet->format_esp = setup.format_esp; + packet->packages = package_progress; copy_text(packet->message, sizeof(packet->message), status_text); copy_text(packet->detail, sizeof(packet->detail), detail_text); if (!result) installer_boot_entry_path(packet->boot_file, sizeof(packet->boot_file)); @@ -341,6 +355,7 @@ static void install_pump(void *) int result = installer_job_step(&install_job); const struct installer_job_packet *packet = result == 0 ? &install_job.final : &install_job.latest; progress_value = packet->progress; + package_progress = packet->packages; copy_text(status_text, sizeof(status_text), packet->message); copy_text(detail_text, sizeof(detail_text), packet->detail); snprintf(progress_text, sizeof(progress_text), "%s - %.120s", status_text, detail_text); @@ -387,6 +402,7 @@ static void start_install_job(void) ui_busy = install_running = 1; install_success = 0; progress_value = 0; + memset(&package_progress, 0, sizeof(package_progress)); installed_boot_file[0] = 0; page = INSTALLER_PAGE_PROGRESS; copy_text(progress_text, sizeof(progress_text), T("Preparing operation")); @@ -1227,6 +1243,18 @@ static void build_progress_page(void) snprintf(percent, sizeof(percent), "%u%%", (unsigned)value); progress_percent_box = make_label(percent, CONTENT_X + CONTENT_W - 98, 162, 72, 30, 14, 0); + package_pending_box = make_label("", CONTENT_X, 232, CONTENT_W / 2, 30, 14, 1); + package_completed_box = make_label("", CONTENT_X + CONTENT_W / 2, 232, + CONTENT_W / 2, 30, 14, 1); + package_current_box = make_label("", CONTENT_X, 276, CONTENT_W, 64, 14, 1); + package_progress_bar = new Fl_Progress(CONTENT_X, 350, CONTENT_W, 20); + package_progress_bar->minimum(0); + package_progress_bar->maximum(100); + package_progress_bar->color(fl_rgb_color(218, 222, 232)); + package_progress_bar->selection_color(COLOR_SIDEBAR); + reliefos_fltk::style(package_progress_bar); + package_transfer_box = make_label("", CONTENT_X, 386, CONTENT_W, 26, 13, 1); + package_total_transfer_box = make_label("", CONTENT_X, 420, CONTENT_W, 28, 13, 1); } static void build_finish_page(void) @@ -1277,6 +1305,9 @@ static void clear_page_widgets(void) progress_text_box = NULL; progress_percent_box = NULL; progress_bar = NULL; + package_pending_box = package_completed_box = package_current_box = nullptr; + package_transfer_box = package_total_transfer_box = nullptr; + package_progress_bar = nullptr; for (int i = 0; i < 5; ++i) account_inputs[i] = NULL; } From 065bc490a9c0d95db2ba8621eb49f4243ccc82a5 Mon Sep 17 00:00:00 2001 From: LeonMMcoset Date: Sat, 5 Dec 2026 14:18:29 +0000 Subject: [PATCH 2/2] fix(ci): run installer retry tests through the PTY pipeline --- .github/workflows/ci.yml | 4 +- tools/tests/test_ci_arch_online_install.py | 72 ++++++++++++++-------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5596af1..76fc49f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,9 +70,9 @@ jobs: run: '"$GOBIN/actionlint" -color' - name: Check CI scripts run: | - if ! command -v cpio >/dev/null || ! /usr/bin/python3 -c 'from PIL import Image' 2>/dev/null; then + if ! command -v cpio >/dev/null || ! command -v gawk >/dev/null || ! command -v script >/dev/null || ! /usr/bin/python3 -c 'from PIL import Image' 2>/dev/null; then sudo apt-get update - sudo apt-get install -y --no-install-recommends cpio python3-pil + sudo apt-get install -y --no-install-recommends cpio gawk util-linux python3-pil fi shellcheck scripts/ci/{install,smoke,arch-host}.sh tools/build/arch-{root,libreliefos,paru,desktop,filesystem,kernel,boot}.sh \ tools/build/arch-image{,-build}.sh tools/build/arch-installer-build.sh \ diff --git a/tools/tests/test_ci_arch_online_install.py b/tools/tests/test_ci_arch_online_install.py index 11eca27d..1752b38b 100644 --- a/tools/tests/test_ci_arch_online_install.py +++ b/tools/tests/test_ci_arch_online_install.py @@ -2,6 +2,8 @@ """Check the online installer's pacman configuration and target setup.""" from pathlib import Path +import shlex +import shutil import subprocess import tempfile import unittest @@ -39,40 +41,60 @@ def test_install_retries_before_writing_and_propagates_hook_errors(self): source = INSTALL.read_text() helper = "install_packages() {\n" + source.split( "install_packages() {\n", 1)[1].split("\n}\n", 1)[0] + "\n}\n" - fixture = r""" -work=$1 -fault=$2 + collector = ROOT / "userland/apps/installer/arch-package-progress.awk" + helper = helper.replace("/usr/libexec/reliefos/arch-package-progress.awk", + shlex.quote(str(collector))) + gawk = shutil.which("gawk") + self.assertIsNotNone(gawk, "the Arch progress collector requires GNU awk") + fixture = r"""work=$1 +export FIXTURE_WORK=$work FIXTURE_FAULT=$2 +export PATH="$work/bin:$PATH" sleep() { :; } -stdbuf() { - shift - "$@" -} -fixture_pacman() { - printf '%s\n' "$*" >> "$work/invocations" - if [[ $fault == download && $(wc -l < "$work/invocations") == 1 ]]; then - printf '%s\n' 'error: failed to commit transaction (failed to retrieve some files)' - return 1 - fi - printf '%s\n' ':: Processing package changes...' 'installing systemd...' - if [[ $fault == hook ]]; then - printf '%s\n' 'error: command failed to execute correctly' - fi -} -pacman=(fixture_pacman) +pacman=("$work/pacman fixture") guest_packages=(core/systemd) install_packages """ - for fault, attempts, result in (("none", 1, 0), ("download", 2, 0), ("hook", 1, 1)): - with self.subTest(fault=fault), tempfile.TemporaryDirectory() as directory: + pacman = r"""#!/bin/bash +set -eu +work=$FIXTURE_WORK +fault=$FIXTURE_FAULT +[[ -t 1 ]] || exit 70 +printf '%s\n' "$*" >> "$work/invocations" +if [[ $fault == command ]]; then exit 9; fi +if [[ $fault == download_all || ( $fault == download && $(wc -l < "$work/invocations") == 1 ) ]]; then + printf '%s\n' 'error: failed to commit transaction (failed to retrieve some files)' + exit 1 +fi +printf '%s\n' ':: Processing package changes...' 'installing systemd...' +printf '(1/1) installing systemd [###] 100%%\r\n' +if [[ $fault == hook ]]; then + printf '%s\n' ':: Running post-transaction hooks...' 'error: command failed to execute correctly' +fi +""" + cases = (("none", 1, 0), ("download", 2, 0), ("hook", 1, 1), + ("download_all", 3, 2), ("command", 1, 1)) + for fault, attempts, result in cases: + with self.subTest(fault=fault), tempfile.TemporaryDirectory(prefix="online install ") as directory: state = Path(directory) + (state / "package-count").write_text("1\n") + (state / "bin").mkdir() + (state / "bin/awk").symlink_to(gawk) + executable = state / "pacman fixture" + executable.write_text(pacman) + executable.chmod(0o755) run = subprocess.run( ["bash", "-eu", "-o", "pipefail", "-c", helper + fixture, "test", - directory, fault], capture_output=True, text=True) - self.assertEqual(run.returncode, result, run.stderr) + directory, fault], capture_output=True, text=True, timeout=15) + self.assertEqual(run.returncode, result, run.stdout + run.stderr) self.assertEqual((state / "invocations").read_text().splitlines(), [f"--logfile {state}/install-pacman.log -S core/systemd"] * attempts) - self.assertTrue((state / "packages-downloaded").exists()) - self.assertIn("installing systemd...", run.stdout) + transaction_started = fault in ("none", "download", "hook") + self.assertEqual((state / "packages-downloaded").exists(), transaction_started) + if transaction_started: + self.assertIn("installing systemd...", run.stdout) + self.assertIn("@reliefos-package 3 1 1 0 0 100 100\tsystemd\t", run.stdout) + if fault == "hook": + self.assertIn("error: command failed to execute correctly", run.stdout) def test_join_target_keyring_before_announcing_boot_bundle(self): configure = INSTALL.read_text().split(' locale=$6\n', 1)[1]