|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Colors for output |
| 5 | +RED='\033[0;31m' |
| 6 | +GREEN='\033[0;32m' |
| 7 | +YELLOW='\033[1;33m' |
| 8 | +NC='\033[0m' # No Color |
| 9 | + |
| 10 | +echo -e "${GREEN}========================================${NC}" |
| 11 | +echo -e "${GREEN} HyPrism macOS Build Script (Local)${NC}" |
| 12 | +echo -e "${GREEN}========================================${NC}" |
| 13 | + |
| 14 | +# Get the script directory and project root |
| 15 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 16 | +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" |
| 17 | + |
| 18 | +cd "$PROJECT_ROOT" |
| 19 | + |
| 20 | +# Detect architecture |
| 21 | +ARCH=$(uname -m) |
| 22 | +if [ "$ARCH" = "arm64" ]; then |
| 23 | + RID="osx-arm64" |
| 24 | + ARCH_NAME="arm64" |
| 25 | +else |
| 26 | + RID="osx-x64" |
| 27 | + ARCH_NAME="x64" |
| 28 | +fi |
| 29 | + |
| 30 | +echo -e "${YELLOW}Building for macOS ${ARCH_NAME}...${NC}" |
| 31 | + |
| 32 | +# Build frontend |
| 33 | +echo -e "${YELLOW}Building frontend...${NC}" |
| 34 | +cd frontend |
| 35 | +npm ci |
| 36 | +npm run build |
| 37 | +cd .. |
| 38 | + |
| 39 | +# Build .NET app |
| 40 | +echo -e "${YELLOW}Building .NET application...${NC}" |
| 41 | +dotnet publish ./HyPrism.csproj -c Release -r "$RID" --self-contained true -o "artifacts/$RID" |
| 42 | + |
| 43 | +# Create app bundle |
| 44 | +echo -e "${YELLOW}Creating macOS app bundle...${NC}" |
| 45 | +APP_NAME="HyPrism.app" |
| 46 | +APP_PATH="artifacts/$APP_NAME" |
| 47 | + |
| 48 | +rm -rf "$APP_PATH" |
| 49 | +mkdir -p "$APP_PATH/Contents/MacOS" |
| 50 | +mkdir -p "$APP_PATH/Contents/Resources" |
| 51 | + |
| 52 | +# Copy all files from publish output |
| 53 | +cp -R "artifacts/$RID/"* "$APP_PATH/Contents/MacOS/" |
| 54 | + |
| 55 | +# Copy resources |
| 56 | +if [ -d "$APP_PATH/Contents/MacOS/wwwroot" ]; then |
| 57 | + cp -R "$APP_PATH/Contents/MacOS/wwwroot" "$APP_PATH/Contents/Resources/" |
| 58 | +fi |
| 59 | +if [ -f "$APP_PATH/Contents/MacOS/jre.json" ]; then |
| 60 | + cp "$APP_PATH/Contents/MacOS/jre.json" "$APP_PATH/Contents/Resources/" |
| 61 | +fi |
| 62 | +if [ -d "$APP_PATH/Contents/MacOS/assets" ]; then |
| 63 | + cp -R "$APP_PATH/Contents/MacOS/assets" "$APP_PATH/Contents/Resources/" |
| 64 | +fi |
| 65 | + |
| 66 | +# Copy Info.plist and icon |
| 67 | +cp packaging/macos/Info.plist "$APP_PATH/Contents/" |
| 68 | +cp packaging/macos/hyprism-macos.icns "$APP_PATH/Contents/Resources/" |
| 69 | + |
| 70 | +# Set executable permission |
| 71 | +chmod +x "$APP_PATH/Contents/MacOS/HyPrism" |
| 72 | + |
| 73 | +# Create PkgInfo |
| 74 | +echo "APPL????" > "$APP_PATH/Contents/PkgInfo" |
| 75 | + |
| 76 | +# Sign the app locally (ad-hoc signing) |
| 77 | +echo -e "${YELLOW}Signing app bundle (ad-hoc)...${NC}" |
| 78 | +codesign --force --deep --sign - "$APP_PATH" || echo -e "${YELLOW}Warning: Codesign failed, continuing anyway${NC}" |
| 79 | + |
| 80 | +# Create DMG |
| 81 | +echo -e "${YELLOW}Creating DMG...${NC}" |
| 82 | +DMG_NAME="HyPrism-macos-${ARCH_NAME}.dmg" |
| 83 | +DMG_PATH="artifacts/$DMG_NAME" |
| 84 | +DMG_STAGING="artifacts/dmg-staging" |
| 85 | + |
| 86 | +rm -rf "$DMG_STAGING" |
| 87 | +rm -f "$DMG_PATH" |
| 88 | +rm -f "artifacts/HyPrism-rw.dmg" |
| 89 | +mkdir -p "$DMG_STAGING" |
| 90 | + |
| 91 | +# Copy app to staging |
| 92 | +cp -R "$APP_PATH" "$DMG_STAGING/" |
| 93 | + |
| 94 | +# Create Applications symlink |
| 95 | +ln -s /Applications "$DMG_STAGING/Applications" |
| 96 | + |
| 97 | +# Create the "Fix Permissions" command file |
| 98 | +cat > "$DMG_STAGING/Fix Permissions.command" << 'EOF' |
| 99 | +#!/bin/bash |
| 100 | +# This script removes quarantine attributes from HyPrism |
| 101 | +# Run this if macOS says the app is damaged or can't be opened |
| 102 | +
|
| 103 | +APP_PATH="$(dirname "$0")/HyPrism.app" |
| 104 | +
|
| 105 | +echo "================================" |
| 106 | +echo " HyPrism - Fix Permissions" |
| 107 | +echo "================================" |
| 108 | +echo "" |
| 109 | +echo "Removing quarantine attributes..." |
| 110 | +xattr -cr "$APP_PATH" |
| 111 | +
|
| 112 | +echo "" |
| 113 | +echo "✓ Done! You can now open HyPrism.app" |
| 114 | +echo "" |
| 115 | +echo "Press any key to close..." |
| 116 | +read -n 1 -s |
| 117 | +EOF |
| 118 | +chmod +x "$DMG_STAGING/Fix Permissions.command" |
| 119 | + |
| 120 | +# Use specific background image |
| 121 | +echo -e "${YELLOW}Setting up DMG background...${NC}" |
| 122 | +SELECTED_BG="$PROJECT_ROOT/packaging/macos/dmg-background.jpg" |
| 123 | +BG_EXT="jpg" |
| 124 | + |
| 125 | +if [ -f "$SELECTED_BG" ]; then |
| 126 | + BG_FILENAME=$(basename "$SELECTED_BG") |
| 127 | + echo -e "${GREEN}Using background: $BG_FILENAME${NC}" |
| 128 | + |
| 129 | + # Create .background directory and copy the background |
| 130 | + mkdir -p "$DMG_STAGING/.background" |
| 131 | + cp "$SELECTED_BG" "$DMG_STAGING/.background/background.$BG_EXT" |
| 132 | +else |
| 133 | + echo -e "${RED}Background image not found: $SELECTED_BG${NC}" |
| 134 | + SELECTED_BG="" |
| 135 | + BG_EXT="" |
| 136 | +fi |
| 137 | + |
| 138 | +# Create a temporary read-write DMG |
| 139 | +echo -e "${YELLOW}Creating temporary DMG...${NC}" |
| 140 | +hdiutil create -volname "HyPrism" -srcfolder "$DMG_STAGING" -ov -format UDRW -fs HFS+ "artifacts/HyPrism-rw.dmg" |
| 141 | + |
| 142 | +# Mount the DMG |
| 143 | +echo -e "${YELLOW}Mounting DMG for customization...${NC}" |
| 144 | +MOUNT_POINT=$(hdiutil attach -readwrite -noverify -noautoopen "artifacts/HyPrism-rw.dmg" | grep "/Volumes/HyPrism" | sed 's/.*\(\/Volumes\/.*\)/\1/') |
| 145 | + |
| 146 | +if [ -z "$MOUNT_POINT" ]; then |
| 147 | + echo -e "${RED}Failed to mount DMG${NC}" |
| 148 | + exit 1 |
| 149 | +fi |
| 150 | + |
| 151 | +echo -e "${GREEN}Mounted at: $MOUNT_POINT${NC}" |
| 152 | + |
| 153 | +# Give the system time to settle |
| 154 | +sleep 2 |
| 155 | + |
| 156 | +# Set custom icon positions and window settings |
| 157 | +echo -e "${YELLOW}Configuring DMG appearance...${NC}" |
| 158 | + |
| 159 | +# Create AppleScript to set up the DMG |
| 160 | +cat > /tmp/dmg_setup.applescript << APPLESCRIPT |
| 161 | +tell application "Finder" |
| 162 | + tell disk "HyPrism" |
| 163 | + open |
| 164 | + set current view of container window to icon view |
| 165 | + set toolbar visible of container window to false |
| 166 | + set statusbar visible of container window to false |
| 167 | + set the bounds of container window to {400, 200, 1040, 680} |
| 168 | + set viewOptions to the icon view options of container window |
| 169 | + set arrangement of viewOptions to not arranged |
| 170 | + set icon size of viewOptions to 128 |
| 171 | + set text size of viewOptions to 13 |
| 172 | + set label position of viewOptions to bottom |
| 173 | + set shows icon preview of viewOptions to true |
| 174 | +APPLESCRIPT |
| 175 | +
|
| 176 | +# Add background picture if available |
| 177 | +if [ -n "$SELECTED_BG" ] && [ -f "$MOUNT_POINT/.background/background.$BG_EXT" ]; then |
| 178 | + cat >> /tmp/dmg_setup.applescript << APPLESCRIPT |
| 179 | + set background picture of viewOptions to file ".background:background.$BG_EXT" |
| 180 | + delay 1 |
| 181 | +APPLESCRIPT |
| 182 | +fi |
| 183 | +
|
| 184 | +# Position items |
| 185 | +cat >> /tmp/dmg_setup.applescript << APPLESCRIPT |
| 186 | + set position of item "HyPrism.app" of container window to {120, 220} |
| 187 | + set position of item "Applications" of container window to {500, 220} |
| 188 | + set position of item "Fix Permissions.command" of container window to {310, 400} |
| 189 | + close |
| 190 | + open |
| 191 | + update without registering applications |
| 192 | + delay 5 |
| 193 | + end tell |
| 194 | +end tell |
| 195 | +APPLESCRIPT |
| 196 | +
|
| 197 | +# Run the AppleScript |
| 198 | +osascript /tmp/dmg_setup.applescript |
| 199 | +
|
| 200 | +# Wait for changes to take effect |
| 201 | +sleep 3 |
| 202 | +
|
| 203 | +# Make sure .DS_Store is written |
| 204 | +sync |
| 205 | +
|
| 206 | +# Unmount |
| 207 | +echo -e "${YELLOW}Unmounting DMG...${NC}" |
| 208 | +hdiutil detach "$MOUNT_POINT" -force || true |
| 209 | +sleep 2 |
| 210 | +
|
| 211 | +# Convert to compressed read-only DMG |
| 212 | +echo -e "${YELLOW}Compressing DMG...${NC}" |
| 213 | +hdiutil convert "artifacts/HyPrism-rw.dmg" -format UDZO -imagekey zlib-level=9 -o "$DMG_PATH" |
| 214 | +
|
| 215 | +# Clean up |
| 216 | +rm -f "artifacts/HyPrism-rw.dmg" |
| 217 | +rm -f /tmp/dmg_setup.applescript |
| 218 | +rm -rf "$DMG_STAGING" |
| 219 | +
|
| 220 | +echo "" |
| 221 | +echo -e "${GREEN}========================================${NC}" |
| 222 | +echo -e "${GREEN} Build Complete!${NC}" |
| 223 | +echo -e "${GREEN}========================================${NC}" |
| 224 | +echo "" |
| 225 | +echo -e "App Bundle: ${YELLOW}$APP_PATH${NC}" |
| 226 | +echo -e "DMG: ${YELLOW}$DMG_PATH${NC}" |
| 227 | +echo "" |
| 228 | +echo -e "${GREEN}To install:${NC}" |
| 229 | +echo "1. Open the DMG file" |
| 230 | +echo "2. Run 'Fix Permissions (Run First).command'" |
| 231 | +echo "3. Drag HyPrism.app to Applications" |
0 commit comments