-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild-local-prod.sh
More file actions
executable file
·188 lines (156 loc) · 8.1 KB
/
build-local-prod.sh
File metadata and controls
executable file
·188 lines (156 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
set -e
###############################################################################
# BUILD LOCAL PRODUCTION VERSION FOR TESTING
# Builds with production bundle ID but doesn't release or notarize
# This script mirrors reset-and-run.sh cleanup but uses production bundle ID
###############################################################################
BINARY_NAME="Fazm" # Package.swift target — binary paths, pkill, CFBundleExecutable
APP_NAME="Fazm"
BUNDLE_ID="com.fazm.app"
BUNDLE_ID_DEV="com.fazm.desktop-dev"
BUILD_DIR="build"
APP_BUNDLE="$BUILD_DIR/$APP_NAME.app"
APP_PATH="/Applications/$APP_NAME.app"
SIGN_IDENTITY="${FAZM_SIGN_IDENTITY:-$(security find-identity -v -p codesigning | grep 'Developer ID Application' | head -1 | sed 's/.*"\(.*\)"/\1/')}"
VERSION="0.0.0-local"
echo "=============================================="
echo " Building Local Production Version"
echo " Bundle ID: $BUNDLE_ID"
echo "=============================================="
echo ""
# Kill existing app
echo "[1/7] Stopping existing app..."
pkill -f "$BINARY_NAME" 2>/dev/null || true
pkill -f "Fazm" 2>/dev/null || true
sleep 1
# =============================================================================
# STEP 2: RESET TCC PERMISSIONS (before deleting apps!)
# =============================================================================
echo "[2/7] Resetting TCC permissions..."
# Reset BOTH bundle IDs to handle switching between dev and prod
tccutil reset All "$BUNDLE_ID" 2>/dev/null || true
tccutil reset All "$BUNDLE_ID_DEV" 2>/dev/null || true
# Belt-and-suspenders: Also clean user TCC database directly via sqlite3
# Note: System TCC database (Screen Recording) is SIP-protected - only tccutil can reset it
sqlite3 "$HOME/Library/Application Support/com.apple.TCC/TCC.db" "DELETE FROM access WHERE client LIKE '%com.fazm.app%' OR client LIKE '%com.omi.computer-macos%';" 2>/dev/null || true
sqlite3 "$HOME/Library/Application Support/com.apple.TCC/TCC.db" "DELETE FROM access WHERE client LIKE '%com.fazm.desktop%' OR client LIKE '%com.omi.desktop%';" 2>/dev/null || true
# =============================================================================
# STEP 3: CLEAN ALL CONFLICTING APP BUNDLES
# =============================================================================
echo "[3/7] Cleaning up conflicting bundles..."
# Main locations
rm -rf "$APP_PATH" 2>/dev/null || true
rm -rf "$APP_BUNDLE" 2>/dev/null || true
rm -rf "/Applications/Omi.app" "/Applications/Omi Computer.app" "/Applications/Omi Dev.app" "/Applications/Omi Beta.app" 2>/dev/null || true
rm -rf "/Applications/Fazm Dev.app" 2>/dev/null || true
rm -rf "$HOME/Desktop/Fazm.app" "$HOME/Downloads/Fazm.app" 2>/dev/null || true
# Xcode DerivedData (old builds with same bundle ID)
echo " Cleaning Xcode DerivedData..."
find "$HOME/Library/Developer/Xcode/DerivedData" \( -name "Fazm.app" -o -name "Fazm Dev.app" -o -name "Omi.app" -o -name "Omi Computer.app" -o -name "Omi Beta.app" -o -name "Omi Dev.app" \) -type d 2>/dev/null | while read app; do
echo " Removing: $app"
rm -rf "$app"
done
# DMG staging directories
echo " Cleaning DMG staging directories..."
rm -rf /private/tmp/fazm-dmg-staging-* /private/tmp/fazm-dmg-test-* /private/tmp/omi-dmg-staging-* /private/tmp/omi-dmg-test-* 2>/dev/null || true
# Apps in Trash (STILL registered in Launch Services!)
echo " Cleaning Fazm/Omi apps from Trash..."
find "$HOME/.Trash" -maxdepth 1 \( -name "*Fazm*" -o -name "*OMI*" -o -name "*Omi*" \) 2>/dev/null | while read item; do
if [ -e "$item" ]; then
echo " Removing: $item"
rm -rf "$item"
fi
done
# Eject mounted DMG volumes
echo " Ejecting mounted Fazm/Omi DMG volumes..."
for vol in /Volumes/Fazm* /Volumes/Omi* /Volumes/OMI* /Volumes/dmg.*; do
if [ -d "$vol" ] 2>/dev/null; then
echo " Ejecting: $vol"
diskutil eject "$vol" 2>/dev/null || hdiutil detach "$vol" 2>/dev/null || true
fi
done 2>/dev/null || true
# =============================================================================
# STEP 4: RESET LAUNCH SERVICES DATABASE
# =============================================================================
echo "[4/7] Resetting Launch Services database..."
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain user 2>/dev/null || true
# Build release
echo "[5/7] Building release binary..."
swift build -c release --package-path Desktop
# Create app bundle
echo "[6/7] Creating app bundle..."
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"
mkdir -p "$APP_BUNDLE/Contents/Frameworks"
BINARY_PATH=$(swift build -c release --package-path Desktop --show-bin-path)/"$BINARY_NAME"
cp "$BINARY_PATH" "$APP_BUNDLE/Contents/MacOS/$BINARY_NAME"
# Copy Sparkle framework
SPARKLE_FRAMEWORK="$(swift build -c release --package-path Desktop --show-bin-path)/Sparkle.framework"
if [ -d "$SPARKLE_FRAMEWORK" ]; then
cp -R "$SPARKLE_FRAMEWORK" "$APP_BUNDLE/Contents/Frameworks/"
fi
# Add rpath for Sparkle
install_name_tool -add_rpath "@executable_path/../Frameworks" "$APP_BUNDLE/Contents/MacOS/$BINARY_NAME" 2>/dev/null || true
# Copy resources
cp Desktop/Info.plist "$APP_BUNDLE/Contents/Info.plist"
cp Desktop/Sources/GoogleService-Info.plist "$APP_BUNDLE/Contents/Resources/"
# Copy resource bundle
SWIFT_BUILD_DIR=$(swift build -c release --package-path Desktop --show-bin-path)
if [ -d "$SWIFT_BUILD_DIR/Fazm_Fazm.bundle" ]; then
cp -R "$SWIFT_BUILD_DIR/Fazm_Fazm.bundle" "$APP_BUNDLE/Contents/Resources/"
fi
# Copy icon
cp fazm_icon.icns "$APP_BUNDLE/Contents/Resources/FazmIcon.icns" 2>/dev/null || true
# Copy .env.app
if [ -f ".env.app" ]; then
cp ".env.app" "$APP_BUNDLE/Contents/Resources/.env"
fi
# Update Info.plist with production bundle ID
/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable $BINARY_NAME" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $BUNDLE_ID" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleName $APP_NAME" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $APP_NAME" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" "$APP_BUNDLE/Contents/Info.plist" 2>/dev/null || \
/usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string $VERSION" "$APP_BUNDLE/Contents/Info.plist"
echo -n "APPL????" > "$APP_BUNDLE/Contents/PkgInfo"
# Strip extended attributes and sign
echo "[7/7] Signing app..."
xattr -cr "$APP_BUNDLE"
# Sign Sparkle components
SPARKLE_FW="$APP_BUNDLE/Contents/Frameworks/Sparkle.framework"
if [ -d "$SPARKLE_FW" ]; then
codesign --force --options runtime --sign "$SIGN_IDENTITY" \
"$SPARKLE_FW/Versions/B/XPCServices/Downloader.xpc" 2>/dev/null || true
codesign --force --options runtime --sign "$SIGN_IDENTITY" \
"$SPARKLE_FW/Versions/B/XPCServices/Installer.xpc" 2>/dev/null || true
codesign --force --options runtime --sign "$SIGN_IDENTITY" \
"$SPARKLE_FW/Versions/B/Autoupdate" 2>/dev/null || true
codesign --force --options runtime --sign "$SIGN_IDENTITY" \
"$SPARKLE_FW/Versions/B/Updater.app" 2>/dev/null || true
codesign --force --options runtime --sign "$SIGN_IDENTITY" "$SPARKLE_FW"
fi
# Sign main app with release entitlements
codesign --force --options runtime --entitlements Desktop/Fazm-Release.entitlements --sign "$SIGN_IDENTITY" "$APP_BUNDLE"
# Install to /Applications
echo ""
echo "Installing to /Applications..."
rm -rf "$APP_PATH"
ditto "$APP_BUNDLE" "$APP_PATH"
# Re-register with Launch Services
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$APP_PATH"
# Reset UserDefaults for fresh onboarding (both bundle IDs)
defaults delete "$BUNDLE_ID" 2>/dev/null || true
defaults delete "$BUNDLE_ID_DEV" 2>/dev/null || true
# Remove quarantine and launch
xattr -cr "$APP_PATH"
echo ""
echo "=============================================="
echo " Build Complete!"
echo "=============================================="
echo ""
echo "App installed: $APP_PATH"
echo "Bundle ID: $BUNDLE_ID"
echo ""
echo "Starting app..."
open "$APP_PATH"