26 lines
598 B
Bash
26 lines
598 B
Bash
# Clone a git repo as a full mirror and pack it into a zip archive.
|
|
# Works on macOS (uses ditto for native compression).
|
|
|
|
set -euo pipefail
|
|
|
|
if [ $# -lt 1 ]; then
|
|
echo "Usage: $0 <git-repo-url> [output.zip]"
|
|
exit 1
|
|
fi
|
|
|
|
URL="$1"
|
|
OUT="${2:-repo.zip}"
|
|
WORK_DIR=".tmp_git_mirror"
|
|
|
|
cleanup() { rm -rf "$WORK_DIR"; }
|
|
trap cleanup EXIT
|
|
|
|
echo "[1/3] Cloning mirror of $URL ..."
|
|
git clone --mirror "$URL" "$WORK_DIR"
|
|
|
|
echo "[2/3] Creating $OUT with maximum compression ..."
|
|
ditto -c -k --seedy --rsrc --keepParent "$WORK_DIR" "$OUT"
|
|
|
|
SIZE=$(du -m "$OUT" | cut -f1)
|
|
echo "[3/3] Done: $OUT (${SIZE} MB)"
|