#!/bin/bash # Генерация release/manifest-VERSION.json (SHA256 файлов + git commit HEAD). # Запуск из корня репозитория: ./scripts/build-release-manifest.sh [VERSION] set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" version="${1:-}" if [ -z "$version" ]; then version="$(tr -d '\r\n' /dev/null || true)" fi if [ -z "$version" ]; then version="$(grep -E '^[[:space:]]*SSH_MONITOR_VERSION=' ssh-monitor 2>/dev/null | head -1 | sed -E 's/^[^=]*=//; s/^["'\'']//; s/["'\'']$//; s/^[[:space:]]+//; s/[[:space:]]+$//')" fi [ -n "$version" ] || { echo "ERROR: укажите VERSION или заполните version.txt" >&2 exit 1 } FILES=( ssh-monitor sac-client.sh update_ssh_monitor.sh ssh-monitor-watchdog ssh-monitor-perms.sh ) for f in "${FILES[@]}"; do [ -f "$f" ] || { echo "ERROR: нет файла $f" >&2 exit 1 } done git_commit="" if git rev-parse HEAD >/dev/null 2>&1; then git_commit="$(git rev-parse HEAD)" fi out="release/manifest-${version}.json" mkdir -p release export MANIFEST_ROOT="$ROOT" export MANIFEST_VERSION="$version" export MANIFEST_GIT_COMMIT="$git_commit" export MANIFEST_OUT="$out" export MANIFEST_FILES="${FILES[*]}" python3 <<'PY' import hashlib import json import os root = os.environ["MANIFEST_ROOT"] version = os.environ["MANIFEST_VERSION"] git_commit = os.environ.get("MANIFEST_GIT_COMMIT", "") files = os.environ["MANIFEST_FILES"].split() out = os.environ["MANIFEST_OUT"] def sha256_file(path: str) -> str: h = hashlib.sha256() with open(path, "rb") as f: for chunk in iter(lambda: f.read(1024 * 1024), b""): h.update(chunk) return h.hexdigest() manifest = { "version": version, "git_commit": git_commit, "files": {}, } for name in files: path = os.path.join(root, name) manifest["files"][name] = f"sha256:{sha256_file(path)}" with open(out, "w", encoding="utf-8") as f: json.dump(manifest, f, indent=2, ensure_ascii=False) f.write("\n") print(f"Wrote {out} commit={git_commit[:12] if git_commit else '?'}") PY