Initial commit with OTS hook
This commit is contained in:
commit
392ee723c3
3 changed files with 178 additions and 0 deletions
75
install-ots-hook.sh
Executable file
75
install-ots-hook.sh
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/bin/bash
|
||||
# install-ots-hook.sh - Install OpenTimestamp post-commit hook
|
||||
# Usage: install-ots-hook.sh [repository-path]
|
||||
|
||||
set -e
|
||||
|
||||
REPO_PATH="${1:-.}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
cd "$REPO_PATH"
|
||||
|
||||
# Verify we're in a git repository
|
||||
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
||||
echo "Error: not a git repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HOOKS_DIR="$(git rev-parse --git-dir)/hooks"
|
||||
POST_COMMIT_HOOK="$HOOKS_DIR/post-commit"
|
||||
|
||||
echo "Installing OpenTimestamp hook in: $REPO_PATH"
|
||||
|
||||
# Create the post-commit hook
|
||||
cat > "$POST_COMMIT_HOOK" << 'HOOK_SCRIPT'
|
||||
#!/bin/bash
|
||||
# Post-commit hook: generate OpenTimestamp proof for each commit
|
||||
|
||||
set -e
|
||||
|
||||
# Get the commit hash
|
||||
COMMIT_HASH=$(git rev-parse HEAD)
|
||||
|
||||
# Find the generate-proof.sh script
|
||||
# Try relative paths first, then check common locations
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
GENERATE_SCRIPT=""
|
||||
|
||||
# Check if generate-proof.sh is in the same directory as this hook
|
||||
if [ -f "$SCRIPT_DIR/generate-proof.sh" ]; then
|
||||
GENERATE_SCRIPT="$SCRIPT_DIR/generate-proof.sh"
|
||||
# Check in .git/hooks directory
|
||||
elif [ -f ".git/hooks/generate-proof.sh" ]; then
|
||||
GENERATE_SCRIPT=".git/hooks/generate-proof.sh"
|
||||
# Check in repository root
|
||||
elif [ -f "generate-proof.sh" ]; then
|
||||
GENERATE_SCRIPT="./generate-proof.sh"
|
||||
# Check if skill is installed globally (common OpenClaw path)
|
||||
elif [ -f "$HOME/.openclaw/workspace/skills/git-ots-hook/scripts/generate-proof.sh" ]; then
|
||||
GENERATE_SCRIPT="$HOME/.openclaw/workspace/skills/git-ots-hook/scripts/generate-proof.sh"
|
||||
else
|
||||
echo "Warning: generate-proof.sh not found, skipping OpenTimestamp proof" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Make sure the script is executable
|
||||
chmod +x "$GENERATE_SCRIPT"
|
||||
|
||||
# Generate the proof
|
||||
echo "[ots] Generating proof for commit: $COMMIT_HASH"
|
||||
"$GENERATE_SCRIPT" "$COMMIT_HASH"
|
||||
|
||||
echo "[ots] Proof generated successfully"
|
||||
HOOK_SCRIPT
|
||||
|
||||
# Make the hook executable
|
||||
chmod +x "$POST_COMMIT_HOOK"
|
||||
|
||||
echo "✓ Post-commit hook installed successfully"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Ensure generate-proof.sh is accessible (copy to repo root or install skill globally)"
|
||||
echo "2. Verify ots CLI or @opentimestamps/ots is installed"
|
||||
echo "3. Make a test commit to verify the hook works"
|
||||
echo ""
|
||||
echo "To uninstall, run: rm $POST_COMMIT_HOOK"
|
||||
Loading…
Add table
Add a link
Reference in a new issue