70 lines
2 KiB
Bash
Executable file
70 lines
2 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
|
|
#
|
|
# Available versions: see `.archive/*.tar.zst`
|
|
#
|
|
# If the archive is an LFS pointer (small file, ~130B) rather than the real
|
|
# tarball, this script will git-lfs-pull it on demand so a fresh clone with
|
|
# GIT_LFS_SKIP_SMUDGE=1 doesn't need to pre-fetch 34G of archives.
|
|
|
|
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 — run scripts/build-archives.sh on apricot first)"
|
|
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"
|