-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·120 lines (94 loc) · 3.25 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·120 lines (94 loc) · 3.25 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
#!/bin/bash
# Build BrowserRouter.app and create release DMG
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
APP_NAME="BrowserRouter"
BUILD_DIR="$PROJECT_DIR/build"
BUNDLE_DIR="$BUILD_DIR/$APP_NAME.app"
DMG_STAGING="$BUILD_DIR/dmg-staging"
DMG_BACKGROUND="$BUILD_DIR/dmg-background.png"
# Get version from argument or git tag
VERSION="${1:-$(git describe --tags --abbrev=0 2>/dev/null || echo "dev")}"
DMG_NAME="$APP_NAME-$VERSION.dmg"
DMG_TEMP="$BUILD_DIR/$APP_NAME-temp.dmg"
DMG_FINAL="$BUILD_DIR/$DMG_NAME"
# DMG window dimensions
DMG_WIDTH=540
DMG_HEIGHT=400
ICON_SIZE=80
APP_X=135
APP_Y=195
APPS_X=405
APPS_Y=195
echo "Building $APP_NAME $VERSION..."
cd "$PROJECT_DIR"
swift build -c release
echo "Creating app bundle..."
rm -rf "$BUNDLE_DIR"
mkdir -p "$BUNDLE_DIR/Contents/MacOS"
mkdir -p "$BUNDLE_DIR/Contents/Resources"
# Copy binary
cp ".build/release/$APP_NAME" "$BUNDLE_DIR/Contents/MacOS/"
# Copy Info.plist
cp "$PROJECT_DIR/$APP_NAME/Info.plist" "$BUNDLE_DIR/Contents/"
# Copy app icon
cp "$PROJECT_DIR/AppIcon.icns" "$BUNDLE_DIR/Contents/Resources/"
# Create PkgInfo
echo -n "APPL????" > "$BUNDLE_DIR/Contents/PkgInfo"
echo "Generating DMG background..."
swift "$SCRIPT_DIR/generate-dmg-background.swift" "$DMG_BACKGROUND"
echo "Creating DMG staging..."
rm -rf "$DMG_STAGING"
mkdir -p "$DMG_STAGING/.background"
cp -R "$BUNDLE_DIR" "$DMG_STAGING/"
cp "$DMG_BACKGROUND" "$DMG_STAGING/.background/background.png"
ln -s /Applications "$DMG_STAGING/Applications"
echo "Creating temporary DMG..."
rm -f "$DMG_TEMP" "$DMG_FINAL"
# Create read-write DMG
hdiutil create -volname "$APP_NAME" -srcfolder "$DMG_STAGING" -ov -format UDRW "$DMG_TEMP"
echo "Mounting DMG for customization..."
MOUNT_DIR=$(hdiutil attach -readwrite -noverify "$DMG_TEMP" | grep "/Volumes/$APP_NAME" | awk '{print $3}')
if [ -z "$MOUNT_DIR" ]; then
echo "Error: Failed to mount DMG"
exit 1
fi
echo "Customizing DMG window..."
# Use AppleScript to set window appearance
osascript <<EOF
tell application "Finder"
tell disk "$APP_NAME"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set bounds of container window to {100, 100, $((100 + DMG_WIDTH)), $((100 + DMG_HEIGHT))}
set viewOptions to the icon view options of container window
set arrangement of viewOptions to not arranged
set icon size of viewOptions to $ICON_SIZE
set background picture of viewOptions to file ".background:background.png"
set position of item "$APP_NAME.app" of container window to {$APP_X, $APP_Y}
set position of item "Applications" of container window to {$APPS_X, $APPS_Y}
close
open
update without registering applications
delay 1
end tell
end tell
EOF
# Make sure changes are written
sync
echo "Unmounting..."
hdiutil detach "$MOUNT_DIR" -force -quiet
sleep 2
echo "Converting to compressed DMG..."
hdiutil convert "$DMG_TEMP" -format UDZO -imagekey zlib-level=9 -o "$DMG_FINAL"
rm -f "$DMG_TEMP"
# Cleanup
rm -rf "$DMG_STAGING"
rm -f "$DMG_BACKGROUND"
rm -rf "$BUNDLE_DIR"
echo ""
echo "Done! Created $DMG_FINAL"
echo "Size: $(du -h "$DMG_FINAL" | cut -f1)"