% ConTeXt Packaging Scripts
% https://github.com/gucci-on-fleek/context-packaging
% SPDX-License-Identifier: CC0-1.0+
% SPDX-FileCopyrightText: 2026 Max Chernoff

% This TeX Live-specific file updates the ConTeXt LMTX filename cache if the
% system ls-R files are modified (typically by mktexlsr). It also sets the
% default paper size from the context-papersize.tex file which TeX Live
% creates/updates (in tlpkg/TLPaper.pm).

% Hans has moved the filename cache updating code into his upstream, so we only
% need to include the module here.
\usemodule[texlive]

% Report our version number in the log file.
\startluacode
    -- Get the distribution details and a logging handle.
    local reporter = logs.reporter("distribution")
    local details = resolvers.getdetails()

    -- Print the header information.
    reporter()
    reporter("This installation of ConTeXt is *NOT* provided by the ConTeXt Team; see below for details.")

    -- Print the distribution and package version information.
    reporter("Distribution name: %s %s",
        details.private.distribution_name, -- "TeX Live"
        details.private.distribution_version -- "2026"
    )
    reporter(
        "Package version:   %s %s",
        tokens.getters.macro("contextversion"), -- "2026.02.19 11:49"
        details.private.package_revision -- "A"
    )

    -- If the installation has been further modified from the original TeX Live
    -- distribution, also print the version of the TeX Live distribution it was
    -- derived from.
    if details.private.distribution_name ~= "TeX Live" then
        reporter("Derived from:      %s", details.private.derived_from) -- "TeX Live (2026-02-19 11:49 A)"
    end

    -- Print the engine version information, since this can sometimes get
    -- out-of-sync with the ConTeXt macro (.tex) version.
    local engine_name, engine_version = status.banner:match(
        "This is ([^%s,]*).*[Vv]ersion (%S*)"
    )
    reporter(
        "Engine version:    %s %s (%s %d)",
        engine_name, engine_version, os.platform, status.development_id
    )

    -- Tell people where they should report issues so that they don't bother
    -- the ConTeXt Team with issues that are actually my fault :).
    reporter("Report issues to:  %s", details.url)

    -- Print the footer information.
    reporter()
\stopluacode

% Set the default paper size
\readsysfile{context-papersize.tex}{}{}
