#!/usr/bin/env bash # Maintainer tool: refresh the pinned rule snapshot in packaging/rules-snapshot/. # NOT installed and NOT run on nodes. # # Cadence: MONTHLY. The refresh lands as a reviewed PR diff, the same review # surface as bumping the pinned release binary. This script is the ONLY way the # snapshot changes; never edit packaging/rules-snapshot/ by hand. # # Scope (R1): the YARA Forge "core" pack only (feed id yara-forge-core), bundled # as-is. IOC lists (malware-hashes, cert-pl-domains, spamhaus-drop, feodo-c2) # stay fetch-only until R3; easyprivacy is never bundled. To add a feed later, # append its id to FEEDS below; install_feed_snapshot is generic. # # Usage: scripts/refresh-rules-snapshot.sh [path/to/strawberry] set -euo pipefail FEEDS=(yara-forge-core) BIN="${1:-builddir/src/strawberry}" SNAP=packaging/rules-snapshot [ -x "$BIN" ] || { echo "strawberry binary not found: $BIN (build first)" >&2; exit 1; } [ -d packaging ] || { echo "run from the repository root" >&2; exit 1; } work=$(mktemp -d "${TMPDIR:-/var/tmp}/strawberry-snapshot.XXXXXX") conf="$work/strawberry.conf" { echo "feeds_dir=$work/feeds" echo "yara_rules_path=$work/local-rules" echo "control_socket_path=" echo "rule_auto_fetch=true" } > "$conf" mkdir -p "$work/local-rules" "$work/feeds" nice -n 19 "$BIN" --config "$conf" rules fetch --force new="$work/new" mkdir -p "$new" : > "$new/SNAPSHOT" for id in "${FEEDS[@]}"; do cur="$work/feeds/$id/current" [ -d "$cur" ] || { echo "feed $id was not fetched ($cur missing)" >&2; exit 1; } version=$(basename "$(readlink -f "$cur")") mkdir -p "$new/$id" for f in "$cur"/*.yar "$cur"/list.txt; do [ -f "$f" ] && command cp -f "$f" "$new/$id/$(basename "$f")" done dirsha=$(cd "$new/$id" && find . -type f | LC_ALL=C sort | xargs sha256sum | sha256sum | cut -d' ' -f1) echo "$id $version $dirsha" >> "$new/SNAPSHOT" done # Replace the snapshot contents (only the feeds we manage). mkdir -p "$SNAP" for id in "${FEEDS[@]}"; do [ -d "$SNAP/$id" ] && find "$SNAP/$id" -type f -delete mkdir -p "$SNAP/$id" command cp -f "$new/$id"/* "$SNAP/$id/" done command cp -f "$new/SNAPSHOT" "$SNAP/SNAPSHOT" (cd "$SNAP" && find . -type f ! -name MANIFEST.sha256 | LC_ALL=C sort | xargs sha256sum > MANIFEST.sha256) echo "snapshot refreshed:" cat "$SNAP/SNAPSHOT" echo "scratch dir (delete when done): $work" echo "review: git diff --stat $SNAP; open a PR."