Bash · 4878 bytes Raw Blame History
1 #!/bin/bash
2 # Sniffly macOS Packaging Script - Fixed for GTK4 resources
3 # Creates a fully standalone .app bundle and .dmg
4
5 set -e
6
7 GREEN='\033[0;32m'
8 BLUE='\033[0;34m'
9 RED='\033[0;31m'
10 NC='\033[0m'
11
12 echo -e "${BLUE}========================================${NC}"
13 echo -e "${BLUE} Sniffly macOS Packaging (Fixed)${NC}"
14 echo -e "${BLUE}========================================${NC}"
15
16 # Read version
17 VERSION=$(cat VERSION)
18 echo -e "${GREEN}Version: ${VERSION}${NC}"
19
20 # Check build
21 if [ ! -f "build/sniffly" ]; then
22 echo -e "${RED}ERROR: build/sniffly not found${NC}"
23 exit 1
24 fi
25
26 # Clean old bundle
27 APP_NAME="Sniffly"
28 APP_BUNDLE="${APP_NAME}.app"
29 rm -rf "${APP_BUNDLE}"
30
31 # Create structure
32 CONTENTS="${APP_BUNDLE}/Contents"
33 MACOS="${CONTENTS}/MacOS"
34 RESOURCES="${CONTENTS}/Resources"
35 FRAMEWORKS="${CONTENTS}/Frameworks"
36
37 echo -e "${BLUE}Step 1: Creating bundle structure...${NC}"
38 mkdir -p "${MACOS}"
39 mkdir -p "${RESOURCES}"
40 mkdir -p "${FRAMEWORKS}"
41
42 # Copy binary (rename to -bin, we'll create a launcher)
43 echo -e "${BLUE}Step 2: Copying executable...${NC}"
44 cp build/sniffly "${MACOS}/sniffly-bin"
45 chmod +x "${MACOS}/sniffly-bin"
46
47 # Create launcher script
48 echo -e "${BLUE}Step 3: Creating launcher script...${NC}"
49 cat > "${MACOS}/sniffly" << 'EOF'
50 #!/bin/bash
51 # Sniffly launcher - sets up GTK4 environment
52
53 # Get the app bundle path
54 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55 BUNDLE_DIR="$(dirname "$(dirname "$DIR")")"
56 RESOURCES_DIR="${BUNDLE_DIR}/Contents/Resources"
57
58 # Set GTK4 environment variables
59 export GSETTINGS_SCHEMA_DIR="${RESOURCES_DIR}/share/glib-2.0/schemas"
60 export GTK_DATA_PREFIX="${RESOURCES_DIR}"
61 export GTK_EXE_PREFIX="${RESOURCES_DIR}"
62 export GTK_PATH="${RESOURCES_DIR}"
63 export XDG_DATA_DIRS="${RESOURCES_DIR}/share:${XDG_DATA_DIRS:-}"
64
65 # Run the actual binary with all arguments
66 exec "${DIR}/sniffly-bin" "$@"
67 EOF
68 chmod +x "${MACOS}/sniffly"
69
70 # Create Info.plist
71 echo -e "${BLUE}Step 4: Creating Info.plist...${NC}"
72 cat > "${CONTENTS}/Info.plist" << EOF
73 <?xml version="1.0" encoding="UTF-8"?>
74 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
75 <plist version="1.0">
76 <dict>
77 <key>CFBundleExecutable</key>
78 <string>sniffly</string>
79 <key>CFBundleIdentifier</key>
80 <string>org.fortrangoingonforty.sniffly</string>
81 <key>CFBundleName</key>
82 <string>${APP_NAME}</string>
83 <key>CFBundleDisplayName</key>
84 <string>${APP_NAME}</string>
85 <key>CFBundleVersion</key>
86 <string>${VERSION}</string>
87 <key>CFBundleShortVersionString</key>
88 <string>${VERSION}</string>
89 <key>CFBundlePackageType</key>
90 <string>APPL</string>
91 <key>CFBundleSignature</key>
92 <string>SNIF</string>
93 <key>CFBundleIconFile</key>
94 <string>sniffly</string>
95 <key>LSMinimumSystemVersion</key>
96 <string>11.0</string>
97 <key>NSHighResolutionCapable</key>
98 <true/>
99 <key>NSRequiresAquaSystemAppearance</key>
100 <false/>
101 <key>LSApplicationCategoryType</key>
102 <string>public.app-category.utilities</string>
103 </dict>
104 </plist>
105 EOF
106
107 # Bundle GTK4 resources
108 echo -e "${BLUE}Step 5: Bundling GTK4 resources...${NC}"
109 mkdir -p "${RESOURCES}/share/glib-2.0/schemas"
110 mkdir -p "${RESOURCES}/share/gtk-4.0"
111
112 # Copy GLib schemas
113 if [ -d "/opt/homebrew/share/glib-2.0/schemas" ]; then
114 echo " Copying GLib schemas..."
115 cp -r /opt/homebrew/share/glib-2.0/schemas/* "${RESOURCES}/share/glib-2.0/schemas/"
116 fi
117
118 # Copy GTK4 data
119 if [ -d "/opt/homebrew/share/gtk-4.0" ]; then
120 echo " Copying GTK4 data..."
121 cp -r /opt/homebrew/share/gtk-4.0/* "${RESOURCES}/share/gtk-4.0/"
122 fi
123
124 # Bundle libraries
125 echo -e "${BLUE}Step 6: Bundling libraries...${NC}"
126 ./scripts/bundle-libs.sh
127
128 # Create PkgInfo
129 echo -n "APPLSNIF" > "${CONTENTS}/PkgInfo"
130
131 # Verify
132 echo -e "${BLUE}Step 7: Verifying bundle...${NC}"
133 if [ -f "${MACOS}/sniffly" ] && [ -f "${MACOS}/sniffly-bin" ]; then
134 echo -e "${GREEN}✓ App bundle created successfully${NC}"
135 else
136 echo -e "${RED}ERROR: Bundle creation failed${NC}"
137 exit 1
138 fi
139
140 # Create DMG
141 echo -e "${BLUE}Step 8: Creating DMG...${NC}"
142 DMG_NAME="Sniffly-${VERSION}-macOS.dmg"
143 DMG_TEMP="dmg_temp"
144
145 rm -rf "${DMG_TEMP}"
146 mkdir -p "${DMG_TEMP}"
147 cp -r "${APP_BUNDLE}" "${DMG_TEMP}/"
148 ln -s /Applications "${DMG_TEMP}/Applications"
149
150 hdiutil create -volname "${APP_NAME}" \
151 -srcfolder "${DMG_TEMP}" \
152 -ov -format UDZO \
153 "${DMG_NAME}"
154
155 rm -rf "${DMG_TEMP}"
156
157 DMG_SIZE=$(du -h "${DMG_NAME}" | cut -f1)
158
159 echo -e "${GREEN}========================================${NC}"
160 echo -e "${GREEN}✓ Packaging complete!${NC}"
161 echo -e "${GREEN}========================================${NC}"
162 echo ""
163 echo -e "${BLUE}Output files:${NC}"
164 echo -e " App Bundle: ${APP_BUNDLE}"
165 echo -e " DMG: ${DMG_NAME} (${DMG_SIZE})"
166 echo ""
167 echo -e "${BLUE}Next steps:${NC}"
168 echo -e " 1. Test: open ${APP_BUNDLE}"
169 echo -e " 2. Test DMG: open ${DMG_NAME}"
170 echo ""