Skip to main content

max / audiofiles

4.2 KB · 143 lines History Blame Raw
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5 PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
6 DIST_DIR="$SCRIPT_DIR"
7
8 # Parse flags
9 SKIP_NOTARIZE=false
10 for arg in "$@"; do
11 case "$arg" in
12 --skip-notarize) SKIP_NOTARIZE=true ;;
13 *) echo "Unknown flag: $arg"; echo "Usage: $0 [--skip-notarize]"; exit 1 ;;
14 esac
15 done
16
17 # Read version from Cargo.toml
18 VERSION=$(grep '^version' "$PROJECT_DIR/crates/audiofiles-app/Cargo.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/')
19 echo "Building AudioFiles v${VERSION}"
20
21 ARCH=$(uname -m)
22 APP_BUNDLE="$DIST_DIR/AudioFiles.app"
23 DMG_NAME="AudioFiles_${VERSION}_${ARCH}.dmg"
24 DMG_PATH="$DIST_DIR/$DMG_NAME"
25 SIGNING_IDENTITY="Developer ID Application: MAXWELL MORGAN JOHNSON (93C54W92UP)"
26 NOTARY_PROFILE="notarytool-profile"
27
28 # Step 1: Build release binary
29 echo "==> Building release binary..."
30 cd "$PROJECT_DIR"
31 cargo build --release -p audiofiles-app
32
33 # Step 2: Assemble app bundle
34 echo "==> Assembling app bundle..."
35 rm -rf "$APP_BUNDLE"
36 mkdir -p "$APP_BUNDLE/Contents/MacOS"
37 mkdir -p "$APP_BUNDLE/Contents/Resources"
38
39 cp "$PROJECT_DIR/target/release/audiofiles-app" "$APP_BUNDLE/Contents/MacOS/audiofiles-app"
40 cp "$PROJECT_DIR/crates/audiofiles-app/AppIcon.icns" "$APP_BUNDLE/Contents/Resources/AppIcon.icns"
41
42 # Patch Info.plist with current version
43 sed -e "s|<string>0\.[0-9]*\.[0-9]*</string><!-- CFBundleVersion -->|<string>${VERSION}</string><!-- CFBundleVersion -->|" \
44 "$DIST_DIR/Info.plist.template" > "$APP_BUNDLE/Contents/Info.plist" 2>/dev/null || true
45
46 # If template doesn't exist, write Info.plist directly with current version
47 if [ ! -f "$APP_BUNDLE/Contents/Info.plist" ] || [ ! -s "$APP_BUNDLE/Contents/Info.plist" ]; then
48 cat > "$APP_BUNDLE/Contents/Info.plist" << PLIST
49 <?xml version="1.0" encoding="UTF-8"?>
50 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
51 <plist version="1.0">
52 <dict>
53 <key>CFBundleName</key>
54 <string>AudioFiles</string>
55 <key>CFBundleIdentifier</key>
56 <string>com.audiofiles.app</string>
57 <key>CFBundleVersion</key>
58 <string>${VERSION}</string>
59 <key>CFBundleShortVersionString</key>
60 <string>${VERSION}</string>
61 <key>CFBundleExecutable</key>
62 <string>audiofiles-app</string>
63 <key>CFBundleIconFile</key>
64 <string>AppIcon</string>
65 <key>CFBundlePackageType</key>
66 <string>APPL</string>
67 <key>NSHighResolutionCapable</key>
68 <true/>
69 <key>CFBundleDocumentTypes</key>
70 <array>
71 <dict>
72 <key>CFBundleTypeName</key>
73 <string>Audio File</string>
74 <key>CFBundleTypeRole</key>
75 <string>Viewer</string>
76 <key>LSHandlerRank</key>
77 <string>Alternate</string>
78 <key>CFBundleTypeExtensions</key>
79 <array>
80 <string>wav</string>
81 <string>flac</string>
82 <string>mp3</string>
83 <string>ogg</string>
84 <string>aiff</string>
85 <string>aif</string>
86 </array>
87 </dict>
88 </array>
89 </dict>
90 </plist>
91 PLIST
92 fi
93
94 # Step 3: Code sign the app bundle
95 echo "==> Signing app bundle..."
96 codesign --deep --force --options runtime \
97 --sign "$SIGNING_IDENTITY" \
98 "$APP_BUNDLE"
99
100 echo "==> Verifying signature..."
101 codesign --verify --deep --strict "$APP_BUNDLE"
102
103 # Step 4: Create DMG
104 echo "==> Creating DMG..."
105 rm -f "$DMG_PATH"
106
107 DMG_STAGING="$DIST_DIR/.dmg-staging"
108 rm -rf "$DMG_STAGING"
109 mkdir -p "$DMG_STAGING"
110 cp -R "$APP_BUNDLE" "$DMG_STAGING/"
111 ln -s /Applications "$DMG_STAGING/Applications"
112
113 hdiutil create -volname "AudioFiles" \
114 -srcfolder "$DMG_STAGING" \
115 -ov -format UDZO \
116 "$DMG_PATH"
117
118 rm -rf "$DMG_STAGING"
119
120 # Step 5: Sign the DMG
121 echo "==> Signing DMG..."
122 codesign --force --sign "$SIGNING_IDENTITY" "$DMG_PATH"
123
124 if [ "$SKIP_NOTARIZE" = true ]; then
125 echo "==> Skipping notarization (--skip-notarize)"
126 echo ""
127 echo "Done: $DMG_PATH"
128 exit 0
129 fi
130
131 # Step 6: Notarize
132 echo "==> Notarizing DMG..."
133 xcrun notarytool submit "$DMG_PATH" \
134 --keychain-profile "$NOTARY_PROFILE" \
135 --wait
136
137 # Step 7: Staple
138 echo "==> Stapling notarization ticket..."
139 xcrun stapler staple "$DMG_PATH"
140
141 echo ""
142 echo "Done: $DMG_PATH"
143