Bash · 5294 bytes Raw Blame History
1 #!/bin/bash
2 # Sniffly macOS Packaging Script
3 # Creates a .app bundle and .dmg for distribution
4 #
5 # Usage: ./scripts/package-macos.sh
6
7 set -e # Exit on error
8
9 # Colors for output
10 GREEN='\033[0;32m'
11 BLUE='\033[0;34m'
12 RED='\033[0;31m'
13 NC='\033[0m' # No Color
14
15 echo -e "${BLUE}========================================${NC}"
16 echo -e "${BLUE} Sniffly macOS Packaging Script${NC}"
17 echo -e "${BLUE}========================================${NC}"
18
19 # Read version from VERSION file
20 if [ ! -f "VERSION" ]; then
21 echo -e "${RED}ERROR: VERSION file not found${NC}"
22 exit 1
23 fi
24
25 VERSION=$(cat VERSION)
26 echo -e "${GREEN}Version: ${VERSION}${NC}"
27
28 # Check if build exists
29 if [ ! -f "build/sniffly" ]; then
30 echo -e "${RED}ERROR: build/sniffly not found. Run 'meson compile -C build' first${NC}"
31 exit 1
32 fi
33
34 # Create app bundle structure
35 APP_NAME="Sniffly"
36 APP_BUNDLE="${APP_NAME}.app"
37 CONTENTS="${APP_BUNDLE}/Contents"
38 MACOS="${CONTENTS}/MacOS"
39 RESOURCES="${CONTENTS}/Resources"
40 FRAMEWORKS="${CONTENTS}/Frameworks"
41
42 echo -e "${BLUE}Step 1: Creating app bundle structure...${NC}"
43 rm -rf "${APP_BUNDLE}"
44 mkdir -p "${MACOS}"
45 mkdir -p "${RESOURCES}"
46 mkdir -p "${FRAMEWORKS}"
47
48 # Copy executable directly - no library bundling needed
49 echo -e "${BLUE}Step 2: Copying executable...${NC}"
50 cp build/sniffly "${MACOS}/sniffly"
51 chmod +x "${MACOS}/sniffly"
52
53 # Create Info.plist
54 echo -e "${BLUE}Step 3: Creating Info.plist...${NC}"
55 cat > "${CONTENTS}/Info.plist" << EOF
56 <?xml version="1.0" encoding="UTF-8"?>
57 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
58 <plist version="1.0">
59 <dict>
60 <key>CFBundleExecutable</key>
61 <string>sniffly</string>
62 <key>CFBundleIdentifier</key>
63 <string>org.fortrangoingonforty.sniffly</string>
64 <key>CFBundleName</key>
65 <string>${APP_NAME}</string>
66 <key>CFBundleDisplayName</key>
67 <string>${APP_NAME}</string>
68 <key>CFBundleVersion</key>
69 <string>${VERSION}</string>
70 <key>CFBundleShortVersionString</key>
71 <string>${VERSION}</string>
72 <key>CFBundlePackageType</key>
73 <string>APPL</string>
74 <key>CFBundleSignature</key>
75 <string>SNIF</string>
76 <key>CFBundleIconFile</key>
77 <string>sniffly</string>
78 <key>LSMinimumSystemVersion</key>
79 <string>11.0</string>
80 <key>NSHighResolutionCapable</key>
81 <true/>
82 <key>NSRequiresAquaSystemAppearance</key>
83 <false/>
84 <key>LSApplicationCategoryType</key>
85 <string>public.app-category.utilities</string>
86 <key>LSUIElement</key>
87 <false/>
88 <key>NSPrincipalClass</key>
89 <string>NSApplication</string>
90 </dict>
91 </plist>
92 EOF
93
94 # Check for icon file
95 echo -e "${BLUE}Step 4: Checking for icon...${NC}"
96 if [ -f "assets/sniffly.icns" ]; then
97 echo -e "${GREEN}Found icon file, copying...${NC}"
98 cp assets/sniffly.icns "${RESOURCES}/sniffly.icns"
99 else
100 echo -e "${RED}WARNING: No icon file found at assets/sniffly.icns${NC}"
101 echo -e "${RED} App will use default icon${NC}"
102 fi
103
104 # Bundle GTK4 libraries manually (simple approach)
105 echo -e "${BLUE}Step 5: Bundling GTK4 libraries...${NC}"
106 if [ -f "./scripts/simple-bundle.sh" ]; then
107 ./scripts/simple-bundle.sh
108 else
109 echo -e "${RED}ERROR: simple-bundle.sh not found${NC}"
110 exit 1
111 fi
112
113 # Create PkgInfo file
114 echo -e "${BLUE}Step 6: Creating PkgInfo...${NC}"
115 echo -n "APPLSNIF" > "${CONTENTS}/PkgInfo"
116
117 # Verify app bundle
118 echo -e "${BLUE}Step 7: Verifying app bundle...${NC}"
119 if [ -f "${MACOS}/sniffly" ] && [ -f "${CONTENTS}/Info.plist" ]; then
120 echo -e "${GREEN}✓ App bundle created successfully${NC}"
121 else
122 echo -e "${RED}ERROR: App bundle creation failed${NC}"
123 exit 1
124 fi
125
126 # Create DMG
127 echo -e "${BLUE}Step 8: Creating DMG...${NC}"
128 DMG_NAME="Sniffly-${VERSION}-macOS.dmg"
129 DMG_TEMP="dmg_temp"
130
131 rm -rf "${DMG_TEMP}"
132 mkdir -p "${DMG_TEMP}"
133
134 # Copy app bundle
135 cp -r "${APP_BUNDLE}" "${DMG_TEMP}/"
136
137 # Create symbolic link to Applications folder
138 ln -s /Applications "${DMG_TEMP}/Applications"
139
140 # Optional: Add background and custom window settings
141 # (requires additional tools like create-dmg)
142
143 # Create the DMG
144 echo -e "${GREEN}Creating ${DMG_NAME}...${NC}"
145 hdiutil create -volname "${APP_NAME}" \
146 -srcfolder "${DMG_TEMP}" \
147 -ov -format UDZO \
148 "${DMG_NAME}"
149
150 # Clean up
151 rm -rf "${DMG_TEMP}"
152
153 # Get DMG size
154 DMG_SIZE=$(du -h "${DMG_NAME}" | cut -f1)
155
156 echo -e "${GREEN}========================================${NC}"
157 echo -e "${GREEN}✓ Packaging complete!${NC}"
158 echo -e "${GREEN}========================================${NC}"
159 echo ""
160 echo -e "${BLUE}Output files:${NC}"
161 echo -e " App Bundle: ${APP_BUNDLE}"
162 echo -e " DMG: ${DMG_NAME} (${DMG_SIZE})"
163 echo ""
164 echo -e "${BLUE}Next steps:${NC}"
165 echo -e " 1. Test the app: open ${APP_BUNDLE}"
166 echo -e " 2. Test the DMG: open ${DMG_NAME}"
167 echo -e " 3. Upload ${DMG_NAME} to your distribution server"
168 echo ""
169
170 # Optional: Code signing check
171 if command -v codesign &> /dev/null; then
172 echo -e "${BLUE}Code Signing Status:${NC}"
173 codesign -dv "${APP_BUNDLE}" 2>&1 | grep -E "Signature|TeamIdentifier" || echo " Not signed"
174 echo ""
175 echo -e "${BLUE}To sign the app (requires Apple Developer account):${NC}"
176 echo -e ' codesign --deep --force --sign "Developer ID Application: Your Name" Sniffly.app'
177 echo ""
178 fi
179
180 echo -e "${GREEN}Done!${NC}"