From 5ac71b3251add35f2d8f8e122e0f875c1e70e29d Mon Sep 17 00:00:00 2001 From: RedThoroughbred <141598284+RedThoroughbred@users.noreply.github.com> Date: Wed, 15 Oct 2025 21:04:09 -0400 Subject: [PATCH 1/2] feat: automate entitlements setup for development - Add setup-entitlements.sh script to automatically configure app group identifiers - Update Justfile with 'setup-entitlements' and 'setup' commands - Improve README with streamlined setup instructions - Eliminate manual search/replace requirement for new contributors Features: - Automatically reads Team ID from Local.xcconfig - Updates all .entitlements files with correct group identifiers - Creates backups before making changes - Provides clear error messages and verification - Supports the new 'just setup' one-command workflow This removes the TODO item about manual entitlements configuration and makes the development setup process much smoother for new contributors. Before: Manual search/replace across multiple files After: Single command handles everything automatically --- Justfile | 11 ++++ README.md | 21 +++++-- scripts/setup-entitlements.sh | 114 ++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 5 deletions(-) create mode 100755 scripts/setup-entitlements.sh diff --git a/Justfile b/Justfile index 5f9e26974..204362967 100644 --- a/Justfile +++ b/Justfile @@ -4,10 +4,12 @@ # Default recipe - shows available commands default: @echo "BitChat macOS Build Commands:" + @echo " just setup - Complete setup (check + configure entitlements)" @echo " just run - Build and run the macOS app" @echo " just build - Build the macOS app only" @echo " just clean - Clean build artifacts and restore original files" @echo " just check - Check prerequisites" + @echo " just setup-entitlements - Configure entitlements for your Team ID" @echo "" @echo "Original files are preserved - modifications are temporary for builds only" @@ -18,6 +20,15 @@ check: @security find-identity -v -p codesigning | grep -q "Developer ID" || (echo "⚠️ No Developer ID found - code signing may fail" && exit 0) @echo "✅ All prerequisites met" +# Configure entitlements for your Team ID +setup-entitlements: + @echo "Configuring entitlements for your Team ID..." + @./scripts/setup-entitlements.sh + +# Complete setup process +setup: check setup-entitlements + @echo "🎉 Setup complete! Ready to build BitChat" + # Backup original files backup: @echo "Backing up original project configuration..." diff --git a/README.md b/README.md index 4e1056c91..de00db23a 100644 --- a/README.md +++ b/README.md @@ -105,17 +105,28 @@ For detailed protocol documentation, see the [Technical Whitepaper](WHITEPAPER.m - Clone the local configs: `cp Configs/Local.xcconfig.example Configs/Local.xcconfig` - Add your Developer Team ID into the newly created `Configs/Local.xcconfig` - Bundle ID would be set to `chat.bitchat.` (unless you set to something else) - - Entitlements need to be updated manually (TODO: Automate): - - Search and replace `group.chat.bitchat` with `group.` (e.g. `group.chat.bitchat.ABC123`) + - Configure entitlements: `just setup-entitlements` (automatically updates group identifiers) -### Option 2: Using `just` +### Option 2: Using `just` (Recommended for macOS) ```bash brew install just ``` -Want to try this on macos: `just run` will set it up and run from source. -Run `just clean` afterwards to restore things to original state for mobile app building and development. + Quick setup for macOS development: + ```bash + # Copy and configure your Team ID + cp Configs/Local.xcconfig.example Configs/Local.xcconfig + # Edit Local.xcconfig to add your DEVELOPMENT_TEAM ID + + # Automated setup (checks prerequisites + configures entitlements) + just setup + + # Build and run + just run + ``` + + Run `just clean` afterwards to restore things to original state for mobile app building and development. ## Localization diff --git a/scripts/setup-entitlements.sh b/scripts/setup-entitlements.sh new file mode 100755 index 000000000..a1937bfd1 --- /dev/null +++ b/scripts/setup-entitlements.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +# BitChat Entitlements Setup Script +# Automatically configures entitlements with the correct bundle ID + +set -e # Exit on any error + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +LOCAL_CONFIG="$PROJECT_ROOT/Configs/Local.xcconfig" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +echo -e "${BLUE}🔧 BitChat Entitlements Setup${NC}" +echo "==================================" + +# Check if Local.xcconfig exists +if [ ! -f "$LOCAL_CONFIG" ]; then + echo -e "${RED}❌ Local.xcconfig not found${NC}" + echo "Please copy Configs/Local.xcconfig.example to Configs/Local.xcconfig first" + echo "and add your DEVELOPMENT_TEAM ID" + exit 1 +fi + +# Extract the team ID from Local.xcconfig +TEAM_ID=$(grep "DEVELOPMENT_TEAM" "$LOCAL_CONFIG" | cut -d'=' -f2 | sed 's/[[:space:]]//g' | sed 's/\$(.*)//' | head -1) + +if [ -z "$TEAM_ID" ] || [ "$TEAM_ID" = "ABC123" ]; then + echo -e "${RED}❌ DEVELOPMENT_TEAM not configured${NC}" + echo "Please edit Configs/Local.xcconfig and set your Apple Developer Team ID" + echo "" + echo "Find your Team ID at:" + echo " Xcode → Preferences → Accounts → Apple ID → Team ID" + echo "" + echo "Then update Local.xcconfig:" + echo " DEVELOPMENT_TEAM = YOUR_TEAM_ID_HERE" + exit 1 +fi + +echo -e "${GREEN}✅ Found Team ID: $TEAM_ID${NC}" + +# Find all entitlements files +ENTITLEMENTS_FILES=$(find "$PROJECT_ROOT" -name "*.entitlements" -type f) + +if [ -z "$ENTITLEMENTS_FILES" ]; then + echo -e "${RED}❌ No entitlements files found${NC}" + exit 1 +fi + +echo -e "${BLUE}📝 Found entitlements files:${NC}" +for file in $ENTITLEMENTS_FILES; do + echo " $(basename "$file")" +done + +# Create backup directory if it doesn't exist +BACKUP_DIR="$PROJECT_ROOT/.entitlements-backup" +mkdir -p "$BACKUP_DIR" + +# Update each entitlements file +echo -e "${BLUE}🔄 Updating entitlements...${NC}" + +for file in $ENTITLEMENTS_FILES; do + filename=$(basename "$file") + echo -e " Processing ${YELLOW}$filename${NC}..." + + # Create backup + cp "$file" "$BACKUP_DIR/$filename.backup" + + # Check if file contains the generic group identifier + if grep -q "group.chat.bitchat" "$file" && ! grep -q "group.chat.bitchat.$TEAM_ID" "$file"; then + # Update the file + sed -i.tmp "s/group\.chat\.bitchat/group.chat.bitchat.$TEAM_ID/g" "$file" + rm "$file.tmp" + echo -e " ${GREEN}✅ Updated group identifier${NC}" + else + echo -e " ${YELLOW}⚠️ Already configured or no changes needed${NC}" + fi +done + +# Verify the changes +echo -e "${BLUE}🔍 Verifying changes...${NC}" +VERIFICATION_FAILED=false + +for file in $ENTITLEMENTS_FILES; do + filename=$(basename "$file") + if grep -q "group.chat.bitchat.$TEAM_ID" "$file"; then + echo -e " ${GREEN}✅ $filename${NC}: group.chat.bitchat.$TEAM_ID" + else + echo -e " ${RED}❌ $filename${NC}: Update failed" + VERIFICATION_FAILED=true + fi +done + +if [ "$VERIFICATION_FAILED" = true ]; then + echo -e "${RED}❌ Some files failed to update${NC}" + echo "Backups are available in .entitlements-backup/" + exit 1 +fi + +echo "" +echo -e "${GREEN}🎉 Entitlements setup complete!${NC}" +echo "" +echo -e "${BLUE}Next steps:${NC}" +echo " 1. Review the changes: git diff" +echo " 2. Test the build: just build" +echo " 3. If issues occur, restore from backups in .entitlements-backup/" +echo "" +echo -e "${YELLOW}Note:${NC} This script updated app group identifiers for your Team ID" +echo "This ensures your development build won't conflict with other versions" \ No newline at end of file From 4a4556fc00cae05a08f0d38122c3889060553320 Mon Sep 17 00:00:00 2001 From: RedThoroughbred <141598284+RedThoroughbred@users.noreply.github.com> Date: Fri, 17 Oct 2025 18:39:00 -0400 Subject: [PATCH 2/2] fix: handle re-runs with different Team IDs in entitlements script - Replace entire group.chat.bitchat.* pattern instead of just prefix - Prevents creating invalid identifiers like group.chat.bitchat.OLD.NEW - Properly handles both initial setup and Team ID changes - Add better status messages for each case Thanks to chatgpt-codex-connector bot for catching this issue! --- scripts/setup-entitlements.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/setup-entitlements.sh b/scripts/setup-entitlements.sh index a1937bfd1..7f17679db 100755 --- a/scripts/setup-entitlements.sh +++ b/scripts/setup-entitlements.sh @@ -71,14 +71,18 @@ for file in $ENTITLEMENTS_FILES; do # Create backup cp "$file" "$BACKUP_DIR/$filename.backup" - # Check if file contains the generic group identifier - if grep -q "group.chat.bitchat" "$file" && ! grep -q "group.chat.bitchat.$TEAM_ID" "$file"; then - # Update the file - sed -i.tmp "s/group\.chat\.bitchat/group.chat.bitchat.$TEAM_ID/g" "$file" + # Check if file needs updating + if grep -q "group.chat.bitchat.$TEAM_ID" "$file"; then + echo -e " ${YELLOW}⚠️ Already configured for Team ID: $TEAM_ID${NC}" + elif grep -q "group.chat.bitchat" "$file"; then + # Replace the entire group.chat.bitchat.* pattern (handles re-runs with different Team IDs) + sed -i.tmp "s/group\.chat\.bitchat\.[^<]*/group.chat.bitchat.$TEAM_ID/g" "$file" + # Also handle the base case without any Team ID suffix + sed -i.tmp "s/group\.chat\.bitchat