-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·149 lines (134 loc) · 4.63 KB
/
build.sh
File metadata and controls
executable file
·149 lines (134 loc) · 4.63 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
#!/bin/bash
# MacPersistenceChecker Build Script
# Creates a complete .app bundle ready for distribution
set -e
echo "=== MacPersistenceChecker Build Script ==="
echo ""
# Configuration
APP_NAME="MacPersistenceChecker"
VERSION="2.0.0"
BUNDLE_ID="com.pinperepette.MacPersistenceChecker"
MIN_MACOS="13.0"
# Directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$SCRIPT_DIR/.build"
APP_DIR="$SCRIPT_DIR/$APP_NAME.app"
CONTENTS_DIR="$APP_DIR/Contents"
MACOS_DIR="$CONTENTS_DIR/MacOS"
RESOURCES_DIR="$CONTENTS_DIR/Resources"
# Clean previous build
echo "[1/6] Cleaning previous build..."
rm -rf "$APP_DIR"
# Build release binary (universal: arm64 + x86_64) so the app runs natively
# on Apple Silicon (M1/M2/M3/M4) and Intel Macs without Rosetta.
# Set UNIVERSAL=0 to build only for the host architecture.
echo "[2/6] Building release binary..."
cd "$SCRIPT_DIR"
UNIVERSAL="${UNIVERSAL:-1}"
if [ "$UNIVERSAL" = "1" ]; then
echo " Building universal (arm64 + x86_64)..."
swift build -c release --triple arm64-apple-macosx${MIN_MACOS}
swift build -c release --triple x86_64-apple-macosx${MIN_MACOS}
mkdir -p "$BUILD_DIR/release"
lipo -create \
"$BUILD_DIR/arm64-apple-macosx/release/$APP_NAME" \
"$BUILD_DIR/x86_64-apple-macosx/release/$APP_NAME" \
-output "$BUILD_DIR/release/$APP_NAME"
echo " Architectures: $(lipo -archs "$BUILD_DIR/release/$APP_NAME")"
else
swift build -c release
fi
# Create app bundle structure
echo "[3/6] Creating app bundle structure..."
mkdir -p "$MACOS_DIR"
mkdir -p "$RESOURCES_DIR"
# Copy binary
cp "$BUILD_DIR/release/$APP_NAME" "$MACOS_DIR/"
# Copy icon
if [ -f "$SCRIPT_DIR/AppIcon.icns" ]; then
cp "$SCRIPT_DIR/AppIcon.icns" "$RESOURCES_DIR/"
echo " Icon: AppIcon.icns copied"
fi
# Copy SwiftPM resource bundle contents into the app Resources/ so that
# Bundle.main.url(forResource:) finds them at runtime (KnownVendors.json,
# AIPrompts/*.md, etc.). The arm64 build's resource bundle is identical to
# the x86_64 one, so we copy from whichever exists.
RESOURCE_BUNDLE_NAMES=(
"$BUILD_DIR/arm64-apple-macosx/release/${APP_NAME}_${APP_NAME}.bundle"
"$BUILD_DIR/x86_64-apple-macosx/release/${APP_NAME}_${APP_NAME}.bundle"
"$BUILD_DIR/release/${APP_NAME}_${APP_NAME}.bundle"
)
for bundle in "${RESOURCE_BUNDLE_NAMES[@]}"; do
if [ -d "$bundle" ]; then
cp -R "$bundle"/* "$RESOURCES_DIR/" 2>/dev/null || true
echo " Resources: copied from $(basename "$(dirname "$bundle")")/"
break
fi
done
# Create Info.plist
echo "[4/6] Creating Info.plist..."
cat > "$CONTENTS_DIR/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$APP_NAME</string>
<key>CFBundleIdentifier</key>
<string>$BUNDLE_ID</string>
<key>CFBundleName</key>
<string>$APP_NAME</string>
<key>CFBundleDisplayName</key>
<string>Mac Persistence Checker</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$VERSION</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$MIN_MACOS</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2024 Pinperepette. All rights reserved.</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
</dict>
</plist>
EOF
# Create entitlements
echo "[5/6] Creating entitlements and signing..."
cat > /tmp/entitlements.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.automation.apple-events</key>
<true/>
</dict>
</plist>
EOF
# Remove quarantine and sign
xattr -cr "$APP_DIR"
codesign --force --deep --sign - --entitlements /tmp/entitlements.plist "$APP_DIR"
# Done
echo "[6/6] Build complete!"
echo ""
echo "=== Build Summary ==="
echo "App: $APP_DIR"
echo "Version: $VERSION"
echo "Size: $(du -sh "$APP_DIR" | cut -f1)"
echo ""
echo "To install, run:"
echo " cp -r $APP_NAME.app /Applications/"
echo ""
echo "Or drag $APP_NAME.app to your Applications folder."