-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-release.sh
More file actions
executable file
·187 lines (165 loc) · 8.12 KB
/
make-release.sh
File metadata and controls
executable file
·187 lines (165 loc) · 8.12 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
#!/bin/bash
# make-release.sh — Build and package HeyFoS.app for Apple Silicon (macOS 14+)
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
VERSION="1.0.0"
APP_NAME="HeyFoS"
BUNDLE_ID="com.heyfos.desktop"
RELEASE_DIR="$SCRIPT_DIR/release"
APP_BUNDLE="$RELEASE_DIR/$APP_NAME.app"
ZIP_NAME="${APP_NAME}-${VERSION}-arm64.zip"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " HeyFoS Desktop — Release Builder v$VERSION"
echo " Platform : macOS 14+ · Apple Silicon (arm64)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# ── 1. Check requirements ────────────────────────────────────────────────────
echo ""
echo "▸ Checking build requirements…"
if ! command -v swift &>/dev/null; then
echo " ✗ swift not found. Install Xcode or the Swift toolchain."
exit 1
fi
if ! brew list libraw &>/dev/null 2>&1; then
echo " ⚠ libraw not found via Homebrew. Installing…"
brew install libraw
fi
echo " ✓ Requirements met"
# ── 2. Build release binary ──────────────────────────────────────────────────
echo ""
echo "▸ Building HeyFoSApp (release · arm64)…"
swift build -c release --arch arm64 --product HeyFoS 2>&1 | \
grep -E "error:|warning:|Build complete|Compiling|Linking" | \
sed 's/^/ /'
BINARY_PATH="$SCRIPT_DIR/.build/release/$APP_NAME"
if [ ! -f "$BINARY_PATH" ]; then
echo " ✗ Build failed — binary not found at $BINARY_PATH"
exit 1
fi
echo " ✓ Binary built: $(du -sh "$BINARY_PATH" | cut -f1)"
# ── 3. Assemble .app bundle ──────────────────────────────────────────────────
echo ""
echo "▸ Assembling ${APP_NAME}.app bundle…"
rm -rf "$APP_BUNDLE"
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"
# Copy executable
cp "$BINARY_PATH" "$APP_BUNDLE/Contents/MacOS/$APP_NAME"
chmod +x "$APP_BUNDLE/Contents/MacOS/$APP_NAME"
# Write Info.plist
cat > "$APP_BUNDLE/Contents/Info.plist" <<PLIST
<?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>${APP_NAME}</string>
<key>CFBundlePackageType</key> <string>APPL</string>
<key>CFBundleShortVersionString</key> <string>${VERSION}</string>
<key>CFBundleVersion</key> <string>100</string>
<key>LSMinimumSystemVersion</key> <string>14.0</string>
<key>NSHighResolutionCapable</key> <true/>
<key>LSApplicationCategoryType</key> <string>public.app-category.photography</string>
<key>NSDocumentsFolderUsageDescription</key>
<string>HeyFoS needs access to your images to perform focus stacking.</string>
<key>NSDesktopFolderUsageDescription</key>
<string>HeyFoS saves the result to your Desktop by default.</string>
<key>NSDownloadsFolderUsageDescription</key>
<string>HeyFoS can load images from Downloads.</string>
<key>CFBundleSupportedPlatforms</key>
<array><string>MacOSX</string></array>
<key>NSPrincipalClass</key> <string>NSApplication</string>
</dict>
</plist>
PLIST
echo " ✓ Bundle structure created"
# ── 4. Bundle Homebrew dynamic libraries ─────────────────────────────────────
echo ""
echo "▸ Bundling dynamic libraries…"
FRAMEWORKS="$APP_BUNDLE/Contents/Frameworks"
mkdir -p "$FRAMEWORKS"
# Copy a Homebrew dylib and fix its install name + transitive deps.
bundle_dylib() {
local src="$1"
local name
name=$(basename "$src")
local dst="$FRAMEWORKS/$name"
[[ -f "$dst" ]] && return 0
cp "$src" "$dst"
chmod +w "$dst"
install_name_tool -id "@rpath/$name" "$dst"
while read -r raw_dep; do
local dep dep_name
dep=$(echo "$raw_dep" | awk '{print $1}')
[[ "$dep" == /opt/homebrew* ]] || continue
dep_name=$(basename "$dep")
bundle_dylib "$dep"
install_name_tool -change "$dep" "@rpath/$dep_name" "$dst"
done < <(otool -L "$dst" | tail -n +2)
}
bundle_dylib "$(brew --prefix libraw)/lib/libraw.24.dylib"
# Fix the main binary's Homebrew references
BIN="$APP_BUNDLE/Contents/MacOS/$APP_NAME"
while read -r raw_dep; do
dep=$(echo "$raw_dep" | awk '{print $1}')
[[ "$dep" == /opt/homebrew* ]] || continue
dep_name=$(basename "$dep")
install_name_tool -change "$dep" "@rpath/$dep_name" "$BIN"
echo " fixed: $dep → @rpath/$dep_name"
done < <(otool -L "$BIN" | tail -n +2)
install_name_tool -add_rpath "@executable_path/../Frameworks" "$BIN" 2>/dev/null || true
DYLIB_COUNT=$(ls "$FRAMEWORKS" | wc -l | tr -d ' ')
echo " ✓ Bundled ${DYLIB_COUNT} dylib(s): $(ls "$FRAMEWORKS" | tr '\n' ' ')"
REMAINING=$(otool -L "$BIN" | grep -c "/opt/homebrew" || true)
[[ "$REMAINING" -eq 0 ]] && echo " ✓ No Homebrew absolute paths remain in binary" || echo " ✗ WARNING: $REMAINING Homebrew path(s) still in binary!"
# ── 5. Ad-hoc code sign ──────────────────────────────────────────────────────
echo ""
echo "▸ Ad-hoc code signing (no notarization)…"
codesign --force --sign - --deep --timestamp=none "$APP_BUNDLE" 2>&1 | sed 's/^/ /'
echo " ✓ Signed"
# ── 6. Create ZIP ────────────────────────────────────────────────────────────
echo ""
echo "▸ Creating ${ZIP_NAME}…"
cd "$RELEASE_DIR"
rm -f "$ZIP_NAME"
zip -r --quiet "$ZIP_NAME" "${APP_NAME}.app"
ZIP_SIZE=$(du -sh "$ZIP_NAME" | cut -f1)
echo " ✓ Archive: release/$ZIP_NAME ($ZIP_SIZE)"
cd "$SCRIPT_DIR"
# ── 7. Generate index.html from template (never modifies the template) ───────
echo ""
echo "▸ Generating release/index.html from template…"
TEMPLATE="$RELEASE_DIR/index.html.template"
if [ ! -f "$TEMPLATE" ]; then
echo " ✗ Template not found at $TEMPLATE"
exit 1
fi
sed "s/__ZIP_NAME__/${ZIP_NAME}/g;s/__VERSION__/${VERSION}/g" \
"$TEMPLATE" > "$RELEASE_DIR/index.html"
echo " ✓ release/index.html generated (href → ${ZIP_NAME})"
# ── 8. Copy to frontend/build/release (static fallback) ─────────────────────
echo ""
echo "▸ Publishing to frontend/build/release/…"
FRONTEND_RELEASE="$SCRIPT_DIR/frontend/build/release"
mkdir -p "$FRONTEND_RELEASE"
cp "$RELEASE_DIR/$ZIP_NAME" "$FRONTEND_RELEASE/"
cp "$RELEASE_DIR/index.html" "$FRONTEND_RELEASE/"
echo " ✓ Files copied → frontend/build/release/"
# ── 9. Summary ───────────────────────────────────────────────────────────────
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Done! HeyFoS v${VERSION} is ready."
echo ""
echo " App bundle : release/${APP_NAME}.app"
echo " Download : release/${ZIP_NAME} (${ZIP_SIZE})"
echo " Download URL: https://heyfos.truyenthong.edu.vn/release/"
echo ""
echo " Installation instructions:"
echo " 1. Download ${ZIP_NAME}"
echo " 2. Double-click to extract → HeyFoS.app"
echo " 3. Move HeyFoS.app to /Applications"
echo " 4. Right-click → Open (first launch only — bypasses Gatekeeper)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"