#!/bin/bash # Install Git hooks for Delphi Consulting Group Database System set -e echo "🔧 Installing Git hooks for enhanced security..." # Check if we're in a git repository if [ ! -d ".git" ]; then echo "❌ Error: Not in a Git repository root directory" echo " Please run this script from the project root where .git directory exists" exit 1 fi # Create hooks directory if it doesn't exist mkdir -p .git/hooks # Install pre-commit hook if [ -f ".git/hooks/pre-commit" ]; then echo "⚠️ Pre-commit hook already exists. Creating backup..." mv .git/hooks/pre-commit .git/hooks/pre-commit.backup fi # Create symlink to our pre-commit hook ln -sf ../../scripts/git-pre-commit-hook .git/hooks/pre-commit # Make sure it's executable chmod +x .git/hooks/pre-commit echo "✅ Pre-commit hook installed successfully!" echo "" echo "🛡️ Security features enabled:" echo " • Prevents committing .env files" echo " • Blocks database files and backups" echo " • Detects SSL certificates and keys" echo " • Warns about potential secrets in code" echo " • Checks for large files (potential data dumps)" echo "" echo "💡 The hook will run automatically before each commit." echo " To bypass (NOT recommended): git commit --no-verify" echo "" echo "🧪 Test the hook:" echo " 1. Try staging a .env file: touch .env && git add .env" echo " 2. Run: git commit -m 'test'" echo " 3. The commit should be blocked with a security warning" echo "" echo "✨ Your repository is now protected against accidental secret commits!"