|
| 1 | +#!/bin/bash |
| 2 | +# bundle.sh - Assembles the macOS .app bundle for Backrest tray mode. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# ./build/darwin/bundle.sh [binary_path] [version] |
| 6 | +# |
| 7 | +# Arguments: |
| 8 | +# binary_path Path to the compiled backrest binary (default: ./backrest) |
| 9 | +# version Version string for the bundle (default: "unknown") |
| 10 | +# |
| 11 | +# Output: |
| 12 | +# Backrest.app/ in the current directory |
| 13 | + |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +BINARY="${1:-./backrest}" |
| 17 | +VERSION="${2:-unknown}" |
| 18 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 19 | +APP_DIR="Backrest.app" |
| 20 | + |
| 21 | +if [ ! -f "$BINARY" ]; then |
| 22 | + echo "Error: binary not found at $BINARY" |
| 23 | + echo "Build it first: go build -o backrest ./cmd/backrest/" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +# Clean previous bundle |
| 28 | +rm -rf "$APP_DIR" |
| 29 | + |
| 30 | +# Create bundle structure |
| 31 | +mkdir -p "$APP_DIR/Contents/MacOS" |
| 32 | +mkdir -p "$APP_DIR/Contents/Resources" |
| 33 | + |
| 34 | +# Copy binary |
| 35 | +cp "$BINARY" "$APP_DIR/Contents/MacOS/backrest" |
| 36 | +chmod +x "$APP_DIR/Contents/MacOS/backrest" |
| 37 | + |
| 38 | +# Generate Info.plist with version |
| 39 | +sed "s|__VERSION__|$VERSION|g" "$SCRIPT_DIR/Info.plist" > "$APP_DIR/Contents/Info.plist" |
| 40 | + |
| 41 | +# Generate .icns from the PNG icon |
| 42 | +ICON_PNG="$SCRIPT_DIR/icon.png" |
| 43 | +if [ -f "$ICON_PNG" ]; then |
| 44 | + ICONSET_DIR=$(mktemp -d)/backrest.iconset |
| 45 | + mkdir -p "$ICONSET_DIR" |
| 46 | + |
| 47 | + # Generate required icon sizes |
| 48 | + for size in 16 32 64 128 256 512; do |
| 49 | + sips -z $size $size "$ICON_PNG" --out "$ICONSET_DIR/icon_${size}x${size}.png" >/dev/null 2>&1 |
| 50 | + done |
| 51 | + # Retina variants |
| 52 | + for size in 16 32 128 256 512; do |
| 53 | + double=$((size * 2)) |
| 54 | + sips -z $double $double "$ICON_PNG" --out "$ICONSET_DIR/icon_${size}x${size}@2x.png" >/dev/null 2>&1 |
| 55 | + done |
| 56 | + |
| 57 | + iconutil -c icns -o "$APP_DIR/Contents/Resources/backrest.icns" "$ICONSET_DIR" 2>/dev/null || { |
| 58 | + echo "Warning: iconutil failed, bundling without .icns icon" |
| 59 | + } |
| 60 | + rm -rf "$(dirname "$ICONSET_DIR")" |
| 61 | +else |
| 62 | + echo "Warning: icon.png not found at $ICON_PNG, bundling without icon" |
| 63 | +fi |
| 64 | + |
| 65 | +# Ad-hoc sign so macOS shows "unverified developer" instead of "damaged" |
| 66 | +codesign --force --deep -s - "$APP_DIR" |
| 67 | + |
| 68 | +echo "Created $APP_DIR (version: $VERSION)" |
| 69 | +echo "To run: open $APP_DIR" |
0 commit comments