Repository navigation
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·144 lines (125 loc) · 4.86 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·144 lines (125 loc) · 4.86 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
#!/bin/bash
set -e
BINARY_NAME="Fazm" # Package.swift target — binary paths, pkill, CFBundleExecutable
APP_NAME="Fazm Dev"
BUNDLE_ID="com.fazm.desktop-dev"
BUILD_DIR="build"
APP_BUNDLE="$BUILD_DIR/$APP_NAME.app"
BACKEND_DIR="$(dirname "$0")/Backend"
BACKEND_PID=""
TUNNEL_PID=""
TUNNEL_URL="https://fazm-dev.m13v.com"
# Cleanup function to stop backend and tunnel on exit
cleanup() {
if [ -n "$TUNNEL_PID" ] && kill -0 "$TUNNEL_PID" 2>/dev/null; then
echo "Stopping tunnel (PID: $TUNNEL_PID)..."
kill "$TUNNEL_PID" 2>/dev/null || true
fi
if [ -n "$BACKEND_PID" ] && kill -0 "$BACKEND_PID" 2>/dev/null; then
echo "Stopping backend (PID: $BACKEND_PID)..."
kill "$BACKEND_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT
# Kill existing instances
pkill "$BINARY_NAME" 2>/dev/null || true
pkill -f "cloudflared.*fazm-dev" 2>/dev/null || true
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
# Start Cloudflare tunnel
echo "Starting Cloudflare tunnel..."
cloudflared tunnel run fazm-dev &
TUNNEL_PID=$!
sleep 2
# Start backend
echo "Starting backend..."
cd "$BACKEND_DIR"
if [ ! -d "venv" ]; then
echo "Creating Python virtual environment..."
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
else
source venv/bin/activate
fi
python main.py &
BACKEND_PID=$!
cd - > /dev/null
# Wait for backend to be ready
echo "Waiting for backend to start..."
for i in {1..30}; do
if curl -s http://localhost:8080 > /dev/null 2>&1; then
echo "Backend is ready!"
break
fi
if ! kill -0 "$BACKEND_PID" 2>/dev/null; then
echo "Backend failed to start"
exit 1
fi
sleep 0.5
done
# Build debug
swift build -c debug --package-path Desktop
# Clean old app bundles from build dir
rm -rf "$BUILD_DIR/Omi Computer.app" "$BUILD_DIR/Omi Beta.app" "$BUILD_DIR/Fazm.app" 2>/dev/null
# Create app bundle
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"
# Copy binary
cp "Desktop/.build/debug/$BINARY_NAME" "$APP_BUNDLE/Contents/MacOS/$BINARY_NAME"
# Copy and fix Info.plist
cp Desktop/Info.plist "$APP_BUNDLE/Contents/Info.plist"
/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 :CFBundleURLTypes:0:CFBundleURLSchemes:0 fazm-dev" "$APP_BUNDLE/Contents/Info.plist"
# Copy GoogleService-Info.plist for Firebase
cp Desktop/Sources/GoogleService-Info.plist "$APP_BUNDLE/Contents/Resources/"
# Copy resource bundle (contains app assets like herologo.png, omi-with-rope-no-padding.webp, etc.)
SWIFT_BUILD_DIR="Desktop/.build/debug"
if [ -d "$SWIFT_BUILD_DIR/Fazm_Fazm.bundle" ]; then
cp -R "$SWIFT_BUILD_DIR/Fazm_Fazm.bundle" "$APP_BUNDLE/Contents/Resources/"
echo "Copied resource bundle"
else
echo "Warning: Resource bundle not found at $SWIFT_BUILD_DIR/Fazm_Fazm.bundle"
fi
# Copy .env.app (app runtime secrets only) and add API URL
if [ -f ".env.app" ]; then
cp .env.app "$APP_BUNDLE/Contents/Resources/.env"
else
touch "$APP_BUNDLE/Contents/Resources/.env"
fi
# Set API URL to tunnel for development (overrides production default)
echo "FAZM_API_URL=$TUNNEL_URL" >> "$APP_BUNDLE/Contents/Resources/.env"
echo "Using backend: $TUNNEL_URL"
# Copy app icon
cp -f fazm_icon.icns "$APP_BUNDLE/Contents/Resources/FazmIcon.icns"
# Create PkgInfo
echo -n "APPL????" > "$APP_BUNDLE/Contents/PkgInfo"
# Sign app with a stable identity so TCC permissions persist across rebuilds.
# Auto-detect: Developer ID > Apple Development > ad-hoc fallback.
SIGN_IDENTITY="${FAZM_SIGN_IDENTITY:-}"
if [ -z "$SIGN_IDENTITY" ]; then
SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | sed 's/.*"\(.*\)"/\1/')
if [ -z "$SIGN_IDENTITY" ]; then
SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep "Apple Development" | head -1 | sed 's/.*"\(.*\)"/\1/')
fi
fi
if [ -n "$SIGN_IDENTITY" ]; then
echo "Signing with: $SIGN_IDENTITY"
codesign --force --options runtime --entitlements Desktop/Fazm.entitlements --sign "$SIGN_IDENTITY" "$APP_BUNDLE"
else
echo "Warning: No signing identity found. Using ad-hoc (permissions will reset each build)."
codesign --force --deep --sign - "$APP_BUNDLE"
fi
echo "Dev build complete: $APP_BUNDLE"
echo ""
echo "=== Services Running ==="
echo "Backend: http://localhost:8080 (PID: $BACKEND_PID)"
echo "Tunnel: $TUNNEL_URL (PID: $TUNNEL_PID)"
echo "========================"
echo ""
open "$APP_BUNDLE"
# Wait for backend process (keeps script running and shows logs)
echo "Press Ctrl+C to stop..."
wait "$BACKEND_PID"