-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcreate-app-bundle.sh
More file actions
executable file
·204 lines (169 loc) · 7.67 KB
/
Copy pathcreate-app-bundle.sh
File metadata and controls
executable file
·204 lines (169 loc) · 7.67 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
set -e
echo "📦 Creating .app bundle..."
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC_DIR="$PROJECT_DIR/src"
APP_NAME="DroidProxy"
BUNDLE_ID="com.droidproxy.app"
BUILD_DIR="$SRC_DIR/.build/release"
APP_DIR="$PROJECT_DIR/$APP_NAME.app"
# Build the Swift executable first
echo -e "${BLUE}Building Swift executable (release)...${NC}"
cd "$SRC_DIR"
if [ -n "$TARGET_ARCH" ]; then
echo "Building for architecture: $TARGET_ARCH"
swift build -c release --arch "$TARGET_ARCH"
else
swift build -c release
fi
cd "$PROJECT_DIR"
echo -e "${GREEN}✅ Build complete${NC}"
# Create .app structure
echo -e "${BLUE}Creating .app bundle structure...${NC}"
rm -rf "$APP_DIR"
mkdir -p "$APP_DIR/Contents/MacOS"
mkdir -p "$APP_DIR/Contents/Resources"
mkdir -p "$APP_DIR/Contents/Frameworks"
# Copy executable
echo -e "${BLUE}Copying executable...${NC}"
cp "$BUILD_DIR/CLIProxyMenuBar" "$APP_DIR/Contents/MacOS/"
chmod +x "$APP_DIR/Contents/MacOS/CLIProxyMenuBar"
# Add rpath for Frameworks directory (needed for Sparkle)
install_name_tool -add_rpath "@loader_path/../Frameworks" "$APP_DIR/Contents/MacOS/CLIProxyMenuBar" 2>/dev/null || true
# Copy resources (copy contents, not the folder itself)
echo -e "${BLUE}Copying resources...${NC}"
# List what we're about to copy
echo "Resources to copy:"
ls -lh "$SRC_DIR/Sources/Resources/"
# Copy each file/directory from Resources/* directly to Contents/Resources/
# Exclude .swift files and other build artifacts
if [ -d "$SRC_DIR/Sources/Resources" ]; then
# Use a loop to copy each item to avoid nested Resources folder
for item in "$SRC_DIR/Sources/Resources/"*; do
if [ -e "$item" ]; then
# Skip if it's a Swift file or Package.swift
if [[ "$item" != *.swift ]]; then
cp -r "$item" "$APP_DIR/Contents/Resources/"
fi
fi
done
fi
# Verify critical files were copied
echo "Checking bundled resources:"
ls -lh "$APP_DIR/Contents/Resources/"
if [ ! -f "$APP_DIR/Contents/Resources/cli-proxy-api" ]; then
echo -e "${YELLOW}⚠️ WARNING: cli-proxy-api binary not found in bundle!${NC}"
echo "Looking for cli-proxy-api in source:"
find "$SRC_DIR/Sources/Resources" -name "cli-proxy-api" -ls
exit 1
fi
echo -e "${GREEN}✅ cli-proxy-api bundled: $(ls -lh "$APP_DIR/Contents/Resources/cli-proxy-api" | awk '{print $5}')${NC}"
# Copy app icon
if [ -f "$SRC_DIR/Sources/Resources/AppIcon.icns" ]; then
cp "$SRC_DIR/Sources/Resources/AppIcon.icns" "$APP_DIR/Contents/Resources/"
fi
# Copy Sparkle.framework
echo -e "${BLUE}Copying Sparkle.framework...${NC}"
SPARKLE_FRAMEWORK="$BUILD_DIR/Sparkle.framework"
if [ -d "$SPARKLE_FRAMEWORK" ]; then
cp -R "$SPARKLE_FRAMEWORK" "$APP_DIR/Contents/Frameworks/"
echo -e "${GREEN}✅ Sparkle.framework bundled${NC}"
else
echo -e "${YELLOW}⚠️ Sparkle.framework not found at $SPARKLE_FRAMEWORK${NC}"
fi
# Copy Info.plist and inject version
echo -e "${BLUE}Copying Info.plist...${NC}"
cp "$SRC_DIR/Info.plist" "$APP_DIR/Contents/"
# Inject version from git tag or environment variable
VERSION="${APP_VERSION:-}"
if [ -z "$VERSION" ]; then
# Try to get version from git tag
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "1.0.0")
# Remove 'v' prefix if present
VERSION="${VERSION#v}"
fi
# Extract build number from full git describe (e.g., v1.0.0-5-g1234567 -> 5, or just use commit count)
BUILD_NUMBER=$(git rev-list --count HEAD 2>/dev/null || echo "1")
echo -e "${BLUE}Setting version to: ${VERSION} (build ${BUILD_NUMBER})${NC}"
# Update Info.plist with version
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${VERSION}" "$APP_DIR/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${BUILD_NUMBER}" "$APP_DIR/Contents/Info.plist"
# Create PkgInfo
echo -e "${BLUE}Creating PkgInfo...${NC}"
echo -n "APPL????" > "$APP_DIR/Contents/PkgInfo"
# Sign the app with Developer ID if available, otherwise ad-hoc
echo -e "${BLUE}Signing app...${NC}"
CODESIGN_IDENTITY="${CODESIGN_IDENTITY:-}"
if [ -z "$CODESIGN_IDENTITY" ]; then
# Try to find Developer ID automatically
CODESIGN_IDENTITY=$(security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | sed 's/.*"\(.*\)"/\1/')
fi
if [ -n "$CODESIGN_IDENTITY" ]; then
echo -e "${GREEN}Signing with: $CODESIGN_IDENTITY${NC}"
# Clean up extended attributes and resource forks that prevent signing
xattr -cr "$APP_DIR"
# Remove any existing signatures first
codesign --remove-signature "$APP_DIR/Contents/MacOS/CLIProxyMenuBar" 2>/dev/null || true
# Sign the cli-proxy-api binary (required for notarization)
if [ -f "$APP_DIR/Contents/Resources/cli-proxy-api" ]; then
echo -e "${BLUE}Signing cli-proxy-api binary...${NC}"
# Use entitlements for the bundled binary
if [ -f "$PROJECT_DIR/entitlements.plist" ]; then
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp \
--entitlements "$PROJECT_DIR/entitlements.plist" \
"$APP_DIR/Contents/Resources/cli-proxy-api"
else
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp \
"$APP_DIR/Contents/Resources/cli-proxy-api"
fi
echo -e "${GREEN}✅ cli-proxy-api signed${NC}"
fi
# Sign Sparkle.framework (required for notarization)
if [ -d "$APP_DIR/Contents/Frameworks/Sparkle.framework" ]; then
echo -e "${BLUE}Signing Sparkle.framework...${NC}"
SPARKLE_FW="$APP_DIR/Contents/Frameworks/Sparkle.framework/Versions/B"
SPARKLE_ENTITLEMENTS="$PROJECT_DIR/sparkle-entitlements.plist"
# Sign XPC services with entitlements (deepest nested)
for xpc in "$SPARKLE_FW/XPCServices"/*.xpc; do
if [ -d "$xpc" ]; then
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp \
--entitlements "$SPARKLE_ENTITLEMENTS" "$xpc"
fi
done
# Sign Autoupdate with entitlements
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp \
--entitlements "$SPARKLE_ENTITLEMENTS" "$SPARKLE_FW/Autoupdate"
# Sign Updater.app with entitlements
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp \
--entitlements "$SPARKLE_ENTITLEMENTS" "$SPARKLE_FW/Updater.app"
# Sign the framework itself
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp \
"$APP_DIR/Contents/Frameworks/Sparkle.framework"
echo -e "${GREEN}✅ Sparkle.framework signed${NC}"
fi
# Sign the main executable with hardened runtime
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp "$APP_DIR/Contents/MacOS/CLIProxyMenuBar"
# Then sign the entire app bundle
codesign --force --sign "$CODESIGN_IDENTITY" --options runtime --timestamp "$APP_DIR"
echo -e "${GREEN}✅ Code signed successfully${NC}"
# Verify the signature
codesign --verify --deep --strict --verbose=2 "$APP_DIR" && echo -e "${GREEN}✅ Signature verified${NC}"
else
echo -e "${YELLOW}⚠️ No Developer ID found, using ad-hoc signature${NC}"
codesign --force --deep --sign - "$APP_DIR"
fi
echo -e "${GREEN}✅ App bundle created successfully!${NC}"
echo ""
echo -e "${GREEN}Location: $APP_DIR${NC}"
echo ""
echo "To install:"
echo " 1. Drag '$APP_NAME.app' to /Applications"
echo " 2. Double-click to launch"
echo ""
echo "To allow opening (if macOS blocks it):"
echo " Right-click > Open, then click 'Open' in the dialog"