ceos-alpine-installer/lib/minimal/11_wiki.sh
John A. Hoeven 7488bb2199 Fix repo org: giovannino → ceos
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-12 01:39:02 +02:00

97 lines
3.8 KiB
Bash

#!/usr/bin/env bash
# Created by John A. Hoeven with the ethical assistance of Claude AI
# ---------------------------------------------------------------------------
# 11_wiki.sh
# ~/projects/ceos/alpine-installer/lib/minimal/11_wiki.sh
# Version: v0.0.1 | Status: DEVELOPMENT
# Target: Alpine Linux x86-64 (tinkerpad / ThinkPad T480)
# ---------------------------------------------------------------------------
# Minimal Tier subscript: wiki viewer — glow from CE repo.
# Downloads binary, verifies sha256 and GPG signature, installs to ~/.local/bin/.
# Gracefully skips if CE repo is unreachable or verification fails.
# TODO — Forgejo: update CE_REPO_HOST to https://git.jhoeven.net/ceos/ceos-alpine-installer/raw/branch/main/bin
# Defines install_minimal_wiki().
# ---------------------------------------------------------------------------
install_minimal_wiki_ce_repo() {
local CE_REPO_HOST="https://cervelloelettrico.it/bin"
local CE_REPO="${CE_REPO_HOST}/${ARCH}/alpine"
local INSTALL_DIR="${HOME}/.local/bin"
local TEMP_DIR
TEMP_DIR="$(mktemp -d /tmp/ce-glow-XXXXXX)"
mkdir -p "${INSTALL_DIR}"
if ! curl --silent --max-time 10 --output /dev/null "${CE_REPO}/glow"; then
log_warn "CE repo unreachable (${CE_REPO}) — skipping glow"
FAILED_PKGS+=("glow (CE repo unreachable)")
rm -rf "${TEMP_DIR}"
return 0
fi
log_info "Downloading glow, sha256, and sig from CE repo..."
local ok=1
curl --silent --max-time 30 -o "${TEMP_DIR}/glow" "${CE_REPO}/glow" || ok=0
curl --silent --max-time 10 -o "${TEMP_DIR}/glow.sha256" "${CE_REPO}/glow.sha256" || ok=0
curl --silent --max-time 10 -o "${TEMP_DIR}/glow.sig" "${CE_REPO}/glow.sig" || ok=0
if [[ "${ok}" -eq 0 ]]; then
log_warn "glow download incomplete — skipping install"
FAILED_PKGS+=("glow (download failed)")
rm -rf "${TEMP_DIR}"
return 0
fi
local expected actual
expected="$(awk '{print $1}' "${TEMP_DIR}/glow.sha256")"
actual="$(sha256sum "${TEMP_DIR}/glow" | awk '{print $1}')"
if [[ "${expected}" != "${actual}" ]]; then
log_warn "glow SHA256 mismatch — aborting (expected: ${expected}, got: ${actual})"
FAILED_PKGS+=("glow (sha256 mismatch)")
rm -rf "${TEMP_DIR}"
return 0
fi
log_info "glow SHA256 verified"
if command -v gpg >/dev/null 2>&1; then
if gpg --verify "${TEMP_DIR}/glow.sig" "${TEMP_DIR}/glow" >> "${LOG_FILE}" 2>&1; then
log_info "glow GPG signature verified"
else
log_warn "glow GPG verification failed — aborting install"
FAILED_PKGS+=("glow (gpg verify failed)")
rm -rf "${TEMP_DIR}"
return 0
fi
else
log_warn "gpg not available — proceeding with sha256-only verification"
fi
chmod +x "${TEMP_DIR}/glow"
cp "${TEMP_DIR}/glow" "${INSTALL_DIR}/glow"
rm -rf "${TEMP_DIR}"
run_test "glow installed" 'command -v glow >/dev/null 2>&1' warn
log_info "glow installed to ${INSTALL_DIR}/glow"
}
install_minimal_wiki() {
log_info "--- minimal/11_wiki: glow ---"
if [[ "${ARCH}" == "x86_64" ]]; then
# glow available in Alpine edge/testing for x86_64
ensure_testing_repo
install_pkg_testing "glow"
run_test "glow installed" 'command -v glow >/dev/null 2>&1' warn
else
# ARM: pull binary from CE repo (TODO: populate Forgejo bin/ tree per arch)
install_minimal_wiki_ce_repo
fi
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
SCRIPT_NAME="11_wiki"
source "${SCRIPT_DIR}/lib/ce-common.sh" || { echo "ERROR: ce-common.sh not found"; exit 1; }
check_not_root
install_minimal_wiki
print_summary
fi