47 lines
1.3 KiB
Bash
47 lines
1.3 KiB
Bash
|
|
#!/usr/bin/env bash
|
|||
|
|
set -euo pipefail
|
|||
|
|
|
|||
|
|
BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|||
|
|
target_input="${1:-}"
|
|||
|
|
if [[ -z "$target_input" ]]; then
|
|||
|
|
echo "Usage: $0 /chemin/vers/CodexPi-public" >&2
|
|||
|
|
exit 2
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
TARGET="$(realpath -m -- "$target_input")"
|
|||
|
|
case "$TARGET" in
|
|||
|
|
"$BASE"|"$BASE"/*)
|
|||
|
|
echo "Le dossier public doit être créé en dehors du dépôt privé." >&2
|
|||
|
|
exit 2
|
|||
|
|
;;
|
|||
|
|
esac
|
|||
|
|
if [[ -e "$TARGET" ]]; then
|
|||
|
|
echo "Refus d’écraser un chemin existant : $TARGET" >&2
|
|||
|
|
exit 2
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
cd "$BASE"
|
|||
|
|
"$BASE/scripts/check-secrets.sh" --worktree
|
|||
|
|
mkdir -p -- "$TARGET"
|
|||
|
|
cleanup() {
|
|||
|
|
if [[ "${completed:-0}" != 1 && -d "$TARGET" ]]; then
|
|||
|
|
find "$TARGET" -mindepth 1 -delete
|
|||
|
|
rmdir "$TARGET" 2>/dev/null || true
|
|||
|
|
fi
|
|||
|
|
}
|
|||
|
|
trap cleanup EXIT
|
|||
|
|
|
|||
|
|
git ls-files --cached --others --exclude-standard -z |
|
|||
|
|
while IFS= read -r -d '' path; do
|
|||
|
|
[[ -e "$path" || -L "$path" ]] && printf '%s\0' "$path"
|
|||
|
|
done |
|
|||
|
|
tar --null --files-from=- --create --file=- |
|
|||
|
|
tar --extract --file=- --directory="$TARGET"
|
|||
|
|
|
|||
|
|
git -C "$TARGET" init -b main >/dev/null
|
|||
|
|
git -C "$TARGET" config core.hooksPath .githooks
|
|||
|
|
"$TARGET/scripts/check-secrets.sh" --worktree
|
|||
|
|
completed=1
|
|||
|
|
echo "Copie publique prête : $TARGET"
|
|||
|
|
echo "Elle possède un nouvel historique Git vide et ne contient ni .env, ni data, ni ancien commit."
|