#!/usr/bin/env bash # Generate version lockfile for reproducible installations set -euo pipefail DOTFILES_DIR="$HOME/dotfiles" LOCKFILE="$DOTFILES_DIR/Brewfile.lock" TEMP_LOCK="/tmp/Brewfile.lock.new" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}Generating version lockfile...${NC}" # Create new lockfile cat > "$TEMP_LOCK" << EOF # Brewfile Lock - Version snapshot for reproducibility # Generated: $(date) # System: $(sw_vers -productVersion) EOF # Get versions of installed packages echo -e "${YELLOW}Capturing package versions...${NC}" echo "# Critical formulae" >> "$TEMP_LOCK" brew list --versions --formula | sort >> "$TEMP_LOCK" echo "" >> "$TEMP_LOCK" echo "# Casks" >> "$TEMP_LOCK" brew list --versions --cask | sort >> "$TEMP_LOCK" # Show differences if lockfile exists if [[ -f "$LOCKFILE" ]]; then echo -e "${YELLOW}Changes since last lock:${NC}" if ! diff "$LOCKFILE" "$TEMP_LOCK" > /dev/null; then diff "$LOCKFILE" "$TEMP_LOCK" || true else echo "No changes detected" fi fi # Replace lockfile mv "$TEMP_LOCK" "$LOCKFILE" echo -e "${GREEN}✅ Lockfile updated: $LOCKFILE${NC}" echo -e "${YELLOW}💡 Commit this file to track version changes${NC}"