zarya/state/collect_state.sh
2026-10-25 18:23:02 +03:00

68 lines
2.3 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -uo pipefail
ZARYA_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
STATE_DIR="${ZARYA_DIR}/state"
SNAPSHOTS_DIR="${STATE_DIR}/snapshots"
TARGET="${1:-all}"
MODULES=(
"00_workstation.sh"
"01_pve.sh"
"02_vps.sh"
"03_vyos.sh"
"04_tier0.sh"
"05_k8s.sh"
)
mkdir -p "${SNAPSHOTS_DIR}"
generate_header() {
local mod_name="$1"
local timestamp branch short_hash commit_msg
timestamp=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
branch=$(git -C "${ATLAS_DIR:-$HOME/Projects/atlas}" branch --show-current 2>/dev/null || echo "unknown")
short_hash=$(git -C "${ATLAS_DIR:-$HOME/Projects/atlas}" rev-parse --short HEAD 2>/dev/null || echo "none")
commit_msg=$(git -C "${ATLAS_DIR:-$HOME/Projects/atlas}" log -1 --format='%s' 2>/dev/null || echo "none")
cat <<EOF
# Sovereign C2 Runtime: ${mod_name}
**Срез:** ${timestamp} | **Git:** ${branch}@${short_hash} ("${commit_msg}")
EOF
}
run_single_module() {
local mod="$1"
local mod_name="${mod%.sh}"
local script="${STATE_DIR}/${mod}"
local out_file="${SNAPSHOTS_DIR}/${mod_name}.md"
local tmp_file="${out_file}.tmp"
echo " -> Сбор модуля: ${mod_name}..."
generate_header "${mod_name}" > "${tmp_file}"
if [[ -x "${script}" ]]; then
"${script}" >> "${tmp_file}" 2>&1
else
bash "${script}" >> "${tmp_file}" 2>&1
fi
mv "${tmp_file}" "${out_file}"
}
if [[ "${TARGET}" == "all" ]]; then
echo "==> Сбор полного аудита Sovereign C2 в ${SNAPSHOTS_DIR}..."
for mod in "${MODULES[@]}"; do
run_single_module "${mod}"
done
echo "✔ Все модули телеметрии успешно сохранены."
else
case "${TARGET}" in
00_workstation|workstation|host) run_single_module "00_workstation.sh" ;;
01_pve|pve) run_single_module "01_pve.sh" ;;
02_vps|vps) run_single_module "02_vps.sh" ;;
03_vyos|vyos|net) run_single_module "03_vyos.sh" ;;
04_tier0|tier0) run_single_module "04_tier0.sh" ;;
05_k8s|k8s|talos) run_single_module "05_k8s.sh" ;;
*)
echo "Неизвестный модуль: ${TARGET}"
exit 1
;;
esac
fi