summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 90c0932d15f0f4a3678a6cff28c4d3f97b4a5132 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# =============================================================================
# cosmostrix-bin — AUR binary package
# =============================================================================
# Maintainer  : rezky_nightky <with dot rezky at gmail dot com>
# Upstream    : https://github.com/oxyzenQ/cosmostrix
# GPG         : F5324E0967F104D58CE025F347A50AEF4B65AAC2
#
# Mutation policy:
#   AUR automation is ONLY allowed to modify: pkgver, _tag, .SRCINFO
#   All other PKGBUILD logic is stable infrastructure and MUST NOT be
#   modified automatically.
# =============================================================================

pkgname=cosmostrix-bin
pkgver=100.0.12
_tag=
pkgrel=1

pkgdesc="Professional-grade cinematic Matrix rain renderer for serious terminal environments."
# night-dragon-maintenance-6: the release lane ships Linux x86_64 static
# musl packages only (v3/v4), so the binary package tracks x86_64.
arch=('x86_64')
url="https://github.com/oxyzenQ/cosmostrix"
license=('AGPL3')

# The release binary is a fully static musl executable: no dynamic libc
# or libgcc linkage, so glibc/gcc-libs are not runtime dependencies.
# curl stays: the update checker shells out to the curl binary.
depends=('curl')

provides=('cosmostrix')
conflicts=('cosmostrix' 'cosmostrix-git')

options=('!strip')

# ---------------------------------------------------------------------------
# Source definitions
# ---------------------------------------------------------------------------
# source=() is intentionally empty.  Assets are selected dynamically in
# prepare() based on the host CPU, then downloaded and verified with the
# sidecar .sha512sum checksum from the GitHub Release.
#
# This avoids:
#   - downloading all x86_64 variants when only 1 is needed
#   - parse-time side effects from dynamic source=() definitions
#   - incompatibility between makepkg static checksums and adaptive selection
# ---------------------------------------------------------------------------
source=()
sha512sums=()

# ---------------------------------------------------------------------------
# prepare() — runtime CPU feature detection + verified download
# ---------------------------------------------------------------------------
# 1. Select the optimal binary variant for the host CPU
# 2. Download the asset and its .sha512sum sidecar from GitHub Releases
# 3. Verify integrity with sha512sum --check
# 4. Extract into srcdir
#
# Detection strategy for x86_64 (assets are the static musl pair):
#   v4 requires AVX-512 (avx512f)
#   v3 requires AVX2 (minimum supported — v1/v2 are no longer built)
#
# Falls back to v3 when /proc/cpuinfo is unavailable (containers, chroots).
# CPUs without AVX2 (pre-2013) are not supported — user must build from
# source with `cargo build --release` if v3 fails to run.
# ---------------------------------------------------------------------------
prepare() {
    local asset
    local tag
    if [[ -n "${_tag}" ]]; then
        tag="v${pkgver}-${_tag}"
    else
        tag="v${pkgver}"
    fi

    # -- Select optimal binary based on host architecture and CPU features --
    # night-dragon-maintenance-6: the release lane ships the Linux x86_64
    # static musl pair (linux-amd64-v3-musl / linux-amd64-v4-musl); the
    # gnu and linux-aarch64 packages are retired.
    case "${CARCH}" in
        x86_64)
            local level="v3"

            if [[ -r /proc/cpuinfo ]] && grep -q avx512f /proc/cpuinfo; then
                level="v4"
            elif [[ -r /proc/cpuinfo ]] && grep -q avx2 /proc/cpuinfo; then
                level="v3"
            else
                warning "CPU does not support AVX2 — v3 binary may not run."
                warning "Pre-2013 CPUs are not supported. Build from source if needed."
            fi

            asset="cosmostrix-${tag}-linux-amd64-${level}-musl.tar.gz"
            ;;
        *)
            error "Unsupported architecture: ${CARCH}"
            return 1
            ;;
    esac

    local url="https://github.com/oxyzenQ/cosmostrix/releases/download/${tag}/${asset}"

    msg2 "Selected asset: ${asset}"
    msg2 "Downloading: ${url}"

    # -- curl flags (shared across all downloads) --
    # --proto '=https': force HTTPS (no plain HTTP fallback).
    # --tlsv1.2: minimum TLS 1.2 (allows TLS 1.3 negotiation — GitHub supports both).
    # --retry 3 --retry-all-errors --retry-delay 5: if the CDN answers a
    #   transient error (HTTP 429 rate-limit, 5xx), wait 5s + retry instead
    #   of failing the install. --retry-all-errors (NIGHT-dinner-1) covers
    #   the exit-22 class plain --retry refuses to re-attempt when --fail
    #   converts a 5xx into a hard error (observed in the owner's fleet:
    #   a release-asset URL answering 500 mid-download).
    # --connect-timeout 30: TCP handshake timeout.
    # --max-time 300: total download timeout (5 min for large assets).
    local curl_flags=(
        --fail
        --location
        --proto '=https'
        --tlsv1.2
        --retry 3
        --retry-all-errors
        --retry-delay 5
        --connect-timeout 30
        --max-time 300
    )

    # -- Download the release asset --
    curl "${curl_flags[@]}" \
        --output "${srcdir}/${asset}" \
        "${url}"

    # -- Download the sidecar SHA512 checksum --
    curl "${curl_flags[@]}" \
        --output "${srcdir}/${asset}.sha512sum" \
        "${url}.sha512sum"

    # -- Verify integrity --
    # SHA-512 is always verified (mandatory — every Linux has sha512sum).
    # BLAKE3-256 + SHAKE256 are optional checksums.
    # They are verified only when the corresponding tool is available.
    msg2 "Verifying SHA512 checksum (required)..."
    (
        cd "${srcdir}" || return 1
        sha512sum --check "${asset}.sha512sum"
    )

    # Optional: BLAKE3-256 (fast, modern; upgraded from BLAKE2b-512 in
    # night-dragon-maintenance-0 to match the release pipeline). The
    # official b3sum CLI ships in extra/community repos or builds via
    # 'cargo install b3sum --locked'.
    if command -v b3sum >/dev/null 2>&1; then
        msg2 "Verifying BLAKE3 checksum (optional)..."
        curl "${curl_flags[@]}" \
            --output "${srcdir}/${asset}.b3sum" \
            "${url}.b3sum"
        (
            cd "${srcdir}" || return 1
            b3sum --check "${asset}.b3sum"
        )
    else
        msg2 "b3sum not found — skipping BLAKE3 verification (optional)"
    fi

    # Optional: SHAKE256 (quantum-resistant, NIST PQ standard, via Python)
    if command -v python3 >/dev/null 2>&1; then
        msg2 "Verifying SHAKE256 checksum (optional, quantum-resistant)..."
        curl "${curl_flags[@]}" \
            --output "${srcdir}/${asset}.shake256" \
            "${url}.shake256"
        (
            cd "${srcdir}" || return 1
            COMPUTED=$(python3 -c "
import hashlib
data = open('${asset}', 'rb').read()
print(hashlib.shake_256(data).hexdigest(64))
")
            EXPECTED=$(awk '{print $1}' "${asset}.shake256")
            [ "${COMPUTED}" = "${EXPECTED}" ] || {
                error "SHAKE256 verification FAILED"
                return 1
            }
            msg2 "SHAKE256 verification OK"
        )
    else
        msg2 "python3 not found — skipping SHAKE256 verification (optional)"
    fi

    # -- Extract (normalize archive layout) --
    # Older releases nested files under a subdirectory (e.g.
    # cosmostrix-1.1.1-stable.1-linux-amd64-v3/); newer releases are flat.
    # Artifact naming uses the tag (e.g. cosmostrix-v2.1.0-linux-amd64-v3-musl.tar.gz).
    # Detect and strip the leading directory if present so package() always
    # finds files at ${srcdir}/cosmostrix, ${srcdir}/LICENSE, etc.
    local top_entry
    top_entry="$(bsdtar --list --file "${srcdir}/${asset}" | head -1)"

    if [[ "${top_entry}" == */ ]]; then
        msg2 "Detected nested archive layout, stripping leading directory"
        bsdtar \
            --extract \
            --file "${srcdir}/${asset}" \
            --directory "${srcdir}" \
            --strip-components=1
    else
        bsdtar \
            --extract \
            --file "${srcdir}/${asset}" \
            --directory "${srcdir}"
    fi
}

# ---------------------------------------------------------------------------
# package()
# ---------------------------------------------------------------------------
# Archive layout (guaranteed by release.yml):
#   /cosmostrix
#   /LICENSE
#   /README.md
# ---------------------------------------------------------------------------
# Clean install: only binary + license + docs. No config files are
# installed — cosmostrix ships sensible built-in defaults and generates
# a config on demand via `cosmostrix --dump-config`. Users who want a
# persistent config run: cosmostrix --dump-config > ~/.config/cosmostrix/config.toml
# ---------------------------------------------------------------------------
package() {
    install -Dm755 \
        "${srcdir}/cosmostrix" \
        "${pkgdir}/usr/bin/cosmostrix"

    if [[ -f "${srcdir}/LICENSE" ]]; then
        install -Dm644 \
            "${srcdir}/LICENSE" \
            "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
    fi

    if [[ -f "${srcdir}/README.md" ]]; then
        install -Dm644 \
            "${srcdir}/README.md" \
            "${pkgdir}/usr/share/doc/${pkgname}/README.md"
    fi
}