atlilith/scripts/extract-archive.sh
autocommit 05f2666088 chore(git): 🔧 Enforce LF line endings and mark binary files in .gitattributes
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-05-16 21:33:57 -07:00

77 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Extract a frozen platform archive to /tmp for review or porting.
#
# Usage: ./scripts/extract-archive.sh <version>
# Example: ./scripts/extract-archive.sh platform.1
#
# Archives are zstd-compressed tarballs in .archive/, tracked via Git LFS.
# Extraction lands in /tmp/atlilith-archive/<version>/ so the repo's
# working tree stays a clean three-file directory (`ls .archive/`).
#
# If you're working from a fresh clone with GIT_LFS_SKIP_SMUDGE=1, the
# `.archive/*.tar.zst` files will be ~130-byte LFS pointers. This script
# detects that and `git lfs pull`s the real blob before extracting.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ARCHIVE_DIR="$REPO_ROOT/.archive"
EXTRACT_ROOT="/tmp/atlilith-archive"
usage() {
echo "Usage: $0 <version>"
echo
echo "Available archives:"
if compgen -G "$ARCHIVE_DIR/platform.*.tar.zst" > /dev/null; then
for f in "$ARCHIVE_DIR"/platform.*.tar.zst; do
name=$(basename "$f" .tar.zst)
size=$(du -h "$f" | cut -f1)
echo " $name ($size)"
done
else
echo " (no archives present)"
echo
echo "Build them with:"
echo " ./scripts/cache-v0.sh # v0 from NFS (~5 min, ~5G)"
echo " ./scripts/build-archives.sh # v1 + v2 from local (~10 min)"
fi
exit 1
}
[ $# -eq 1 ] || usage
VERSION="$1"
ARCHIVE="$ARCHIVE_DIR/${VERSION}.tar.zst"
DEST="$EXTRACT_ROOT/${VERSION}"
if [ ! -f "$ARCHIVE" ]; then
echo "error: archive not found: $ARCHIVE" >&2
echo
usage
fi
# If the file is tiny, it's an LFS pointer — fetch the real blob.
size=$(stat -c %s "$ARCHIVE" 2>/dev/null || stat -f %z "$ARCHIVE")
if [ "$size" -lt 1024 ]; then
echo "archive is an LFS pointer (${size}B); fetching real blob via git lfs pull..."
(cd "$REPO_ROOT" && git lfs pull --include=".archive/${VERSION}.tar.zst") || {
echo "error: git lfs pull failed. Is the LFS remote configured?" >&2
exit 1
}
fi
if [ -d "$DEST" ]; then
echo "destination exists: $DEST"
read -rp "remove and re-extract? [y/N] " ans
[[ "$ans" =~ ^[yY] ]] || { echo "aborted"; exit 1; }
rm -rf "$DEST"
fi
mkdir -p "$DEST"
echo "extracting $ARCHIVE$DEST"
zstd -dc "$ARCHIVE" | tar -xf - -C "$DEST"
echo
echo "done. extracted to: $DEST"
echo
echo "to clean up later: rm -rf $DEST"