Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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..."
Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<team_id>` (unless you set to something else)
- Entitlements need to be updated manually (TODO: Automate):
- Search and replace `group.chat.bitchat` with `group.<your_bundle_id>` (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

Expand Down
114 changes: 114 additions & 0 deletions scripts/setup-entitlements.sh
Original file line number Diff line number Diff line change
@@ -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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace whole app-group value when Team ID changes

When the script is re-run after the entitlements already contain a previous Team ID, the sed command only replaces the group.chat.bitchat prefix, producing values like group.chat.bitchat.NEW.OLD. The subsequent verification still passes because it matches the group.chat.bitchat.NEW substring, yet the entitlements are now invalid and code signing for the new team will fail. Replace the entire group.chat.bitchat.* value (or remove the old suffix first) so subsequent runs with a different Team ID produce a clean identifier.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that! 👍

Fixed in 4a4556f - the script now properly replaces the entire group.chat.bitchat.* pattern, so re-running with a different Team ID will correctly update from group.chat.bitchat.OLD to group.chat.bitchat.NEW instead of creating an invalid group.chat.bitchat.OLD.NEW.

The fix handles both cases:

  • Initial setup: group.chat.bitchatgroup.chat.bitchat.ABC123
  • Team ID change: group.chat.bitchat.ABC123group.chat.bitchat.XYZ789

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"