Repository navigation
Expand file tree
/
Copy pathrelease-build.sh
More file actions
executable file
Β·311 lines (263 loc) Β· 10.8 KB
/
Copy pathrelease-build.sh
File metadata and controls
executable file
Β·311 lines (263 loc) Β· 10.8 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}π Starting Release Build Process${NC}"
echo "========================================="
# Check if .env file exists
if [ ! -f .env ]; then
echo -e "${RED}β Error: .env file not found${NC}"
echo "Please create a .env file with the following variables:"
echo " CSC_NAME=\"Developer ID Application: Your Name (TEAM_ID)\""
echo " APPLE_ID=\"your@email.com\""
echo " APPLE_APP_SPECIFIC_PASSWORD=\"xxxx-xxxx-xxxx-xxxx\""
echo " APPLE_TEAM_ID=\"YOUR_TEAM_ID\""
exit 1
fi
# Load environment variables
echo -e "${YELLOW}π Loading environment variables...${NC}"
source .env
# Check required environment variables for signing
if [ -z "$CSC_NAME" ]; then
echo -e "${RED}β Error: CSC_NAME not set in .env${NC}"
exit 1
fi
# Check required environment variables for notarization
NOTARIZE_ENABLED=true
if [ -z "$APPLE_APP_SPECIFIC_PASSWORD_PROFILE" ]; then
echo -e "${YELLOW}β οΈ Warning: APPLE_APP_SPECIFIC_PASSWORD_PROFILE not configured${NC}"
echo " Build will continue without notarization."
NOTARIZE_ENABLED=false
fi
# Clean previous builds
echo -e "${YELLOW}π§Ή Cleaning previous builds...${NC}"
rm -rf dist/
# Install dependencies if needed
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}π¦ Installing dependencies...${NC}"
npm install
fi
# Install electron-notarize if not present and notarization is enabled
if [ "$NOTARIZE_ENABLED" = true ] && [ ! -d "node_modules/@electron/notarize" ]; then
echo -e "${YELLOW}π¦ Installing @electron/notarize...${NC}"
npm install --save-dev @electron/notarize
fi
# Update electron-builder configuration for signing (disable built-in notarization)
echo -e "${YELLOW}π§ Configuring electron-builder for signing...${NC}"
node -e "
const fs = require('fs');
try {
const config = JSON.parse(fs.readFileSync('electron-builder.json', 'utf8'));
config.mac.hardenedRuntime = true;
config.mac.gatekeeperAssess = true;
// Disable built-in notarization - we'll do it manually
delete config.afterSign;
fs.writeFileSync('electron-builder.json', JSON.stringify(config, null, 2));
console.log('β
Configuration updated');
} catch (err) {
console.error('β Failed to parse electron-builder.json:', err.message);
process.exit(1);
}
"
# Build the application
echo -e "${BLUE}ποΈ Building application...${NC}"
echo "This may take several minutes..."
if npm run dist; then
echo -e "${GREEN}β
Build successful!${NC}"
else
echo -e "${RED}β Build failed${NC}"
exit 1
fi
# Find the built app
APP_PATH=$(find dist -name "*.app" -type d | head -n 1)
DMG_PATH=$(find dist -name "*.dmg" -type f | head -n 1)
if [ -z "$APP_PATH" ]; then
echo -e "${RED}β Error: Could not find built app${NC}"
exit 1
fi
# Apply hardened runtime to the built app
echo -e "${YELLOW}π Applying hardened runtime...${NC}"
# Sign all helper apps with hardened runtime
find "$APP_PATH" -name "*.app" -type d ! -path "$APP_PATH" | while read helper_app; do
codesign --force --deep --options runtime --entitlements build/entitlements.mac.plist --sign "$CSC_NAME" "$helper_app" 2>/dev/null
done
# Sign frameworks with hardened runtime
find "$APP_PATH" -name "*.framework" -type d | while read framework; do
codesign --force --deep --options runtime --entitlements build/entitlements.mac.plist --sign "$CSC_NAME" "$framework" 2>/dev/null
done
# Sign executables with hardened runtime
find "$APP_PATH" -type f -perm +111 ! -name "*.dylib" ! -name "*.so" 2>/dev/null | while read executable; do
if file "$executable" 2>/dev/null | grep -q "Mach-O"; then
codesign --force --options runtime --entitlements build/entitlements.mac.plist --sign "$CSC_NAME" "$executable" 2>/dev/null || true
fi
done
# Sign the main app with hardened runtime
codesign --force --deep --options runtime --entitlements build/entitlements.mac.plist --sign "$CSC_NAME" "$APP_PATH"
# Verify app code signature
echo -e "${YELLOW}π Verifying app code signature...${NC}"
if codesign --verify --deep --strict --verbose=2 "$APP_PATH" 2>&1; then
echo -e "${GREEN}β
App code signature verified${NC}"
# Verify hardened runtime
if codesign -dvvv "$APP_PATH" 2>&1 | grep -q "flags=.*runtime"; then
echo -e "${GREEN}β
Hardened runtime verified${NC}"
else
echo -e "${RED}β Hardened runtime not enabled${NC}"
exit 1
fi
else
echo -e "${RED}β App code signature verification failed${NC}"
exit 1
fi
# Re-create DMG with properly signed app (electron-builder's DMG loses hardened runtime)
if [ -n "$DMG_PATH" ]; then
echo -e "${YELLOW}π Re-creating DMG with signed app and installer layout...${NC}"
# Store original DMG path and create new path
ORIGINAL_DMG="$DMG_PATH"
FINAL_DMG="${DMG_PATH%.dmg}-signed.dmg"
TEMP_DIR="dist/dmg-temp"
TEMP_DMG="dist/temp.dmg"
# Remove old files if exist
rm -f "$FINAL_DMG"
rm -f "$TEMP_DMG"
# Create temporary directory for DMG contents
rm -rf "$TEMP_DIR"
mkdir -p "$TEMP_DIR"
# Copy the signed app to temp directory
echo " Copying signed app to temp directory..."
cp -R "$APP_PATH" "$TEMP_DIR/"
# Create symlink to Applications folder
echo " Creating Applications folder link..."
ln -s /Applications "$TEMP_DIR/Applications"
# Create a temporary DMG
echo " Creating DMG with installer layout..."
hdiutil create -volname "Viber" \
-srcfolder "$TEMP_DIR" \
-ov -format UDRW \
"$TEMP_DMG"
# Mount the temporary DMG
echo " Mounting temporary DMG..."
MOUNT_POINT=$(hdiutil attach -nobrowse "$TEMP_DMG" | grep "/Volumes" | awk '{print $3}')
# Set custom icon positions and window properties using AppleScript
echo " Setting DMG window properties..."
osascript <<EOF
tell application "Finder"
tell disk "Viber"
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 the bounds of container window to {400, 100, 900, 400}
set viewOptions to the icon view options of container window
set arrangement of viewOptions to not arranged
set icon size of viewOptions to 72
set background picture of viewOptions to POSIX file "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns"
set position of item "Viber.app" of container window to {125, 150}
set position of item "Applications" of container window to {375, 150}
close
open
update without registering applications
delay 2
end tell
end tell
EOF
# Unmount the DMG
echo " Unmounting temporary DMG..."
hdiutil detach "$MOUNT_POINT" -quiet
# Convert to compressed read-only DMG
echo " Converting to final DMG..."
hdiutil convert "$TEMP_DMG" -format UDZO -o "$FINAL_DMG"
# Sign the new DMG
echo -e "${YELLOW}βοΈ Signing DMG file...${NC}"
if codesign --force --sign "$CSC_NAME" "$FINAL_DMG"; then
echo -e "${GREEN}β
DMG signed successfully${NC}"
else
echo -e "${RED}β Failed to sign DMG${NC}"
exit 1
fi
# Verify DMG signature
echo -e "${YELLOW}π Verifying DMG signature...${NC}"
if codesign --verify --verbose=2 "$FINAL_DMG" 2>&1; then
echo -e "${GREEN}β
DMG signature verified${NC}"
else
echo -e "${RED}β DMG signature verification failed${NC}"
exit 1
fi
# Clean up
rm -rf "$TEMP_DIR"
rm -f "$TEMP_DMG"
rm -f "$ORIGINAL_DMG" # Remove the original DMG from electron-builder
# Update DMG_PATH to point to the new DMG
DMG_PATH="$FINAL_DMG"
fi
# Notarize the DMG using keychain profile
if [ "$NOTARIZE_ENABLED" = true ] && [ -n "$DMG_PATH" ]; then
echo -e "${BLUE}π Starting notarization process...${NC}"
echo "Submitting DMG for notarization..."
if xcrun notarytool submit "$DMG_PATH" --keychain-profile "$APPLE_APP_SPECIFIC_PASSWORD_PROFILE" --wait; then
echo -e "${GREEN}β
Notarization successful${NC}"
# Staple the notarization ticket to the DMG
echo -e "${YELLOW}π Stapling notarization ticket...${NC}"
if xcrun stapler staple "$DMG_PATH"; then
echo -e "${GREEN}β
Notarization ticket stapled${NC}"
else
echo -e "${RED}β Failed to staple notarization ticket${NC}"
fi
else
echo -e "${RED}β Notarization failed${NC}"
echo "You can check the notarization log for details"
fi
# Verify notarization
echo -e "${YELLOW}π Verifying notarization...${NC}"
if spctl -a -t open --context context:primary-signature -v "$DMG_PATH" 2>&1 | grep -q "accepted"; then
echo -e "${GREEN}β
DMG notarization verified${NC}"
else
echo -e "${YELLOW}β οΈ DMG notarization not verified${NC}"
fi
fi
# Display results
echo ""
echo -e "${GREEN}=========================================${NC}"
echo -e "${GREEN}π Release Build Complete!${NC}"
echo -e "${GREEN}=========================================${NC}"
echo ""
if [ -n "$DMG_PATH" ]; then
DMG_SIZE=$(du -h "$DMG_PATH" | cut -f1)
echo -e "${BLUE}π¦ DMG File:${NC} $DMG_PATH"
echo -e "${BLUE}π Size:${NC} $DMG_SIZE"
fi
echo -e "${BLUE}π± App:${NC} $APP_PATH"
echo -e "${BLUE}βοΈ Signed by:${NC} $CSC_NAME"
if [ "$NOTARIZE_ENABLED" = true ]; then
echo -e "${BLUE}π Notarized:${NC} Yes"
else
echo -e "${YELLOW}β οΈ Notarized:${NC} No (missing credentials)"
fi
echo ""
echo -e "${GREEN}Next steps:${NC}"
echo "1. Test the DMG on a different Mac"
echo "2. Upload to your distribution channel"
echo "3. Create a GitHub release (if applicable)"
# Restore electron-builder configuration
echo -e "${YELLOW}π§ Restoring electron-builder configuration...${NC}"
git checkout electron-builder.json 2>/dev/null || true
# Calculate and display SHA256 for Homebrew
if [ -n "$DMG_PATH" ] && [ -f "$DMG_PATH" ]; then
echo ""
echo -e "${BLUE}=========================================${NC}"
echo -e "${BLUE}πΊ Homebrew Distribution Info${NC}"
echo -e "${BLUE}=========================================${NC}"
DMG_SHA256=$(shasum -a 256 "$DMG_PATH" | awk '{print $1}')
DMG_FILENAME=$(basename "$DMG_PATH")
echo -e "${YELLOW}π Copy this for your Homebrew formula:${NC}"
echo ""
echo " url \"https://github.com/YOUR_USERNAME/YOUR_REPO/releases/download/vX.X.X/$DMG_FILENAME\""
echo " sha256 \"$DMG_SHA256\""
echo ""
echo -e "${GREEN}SHA256:${NC} $DMG_SHA256"
echo -e "${GREEN}File:${NC} $DMG_FILENAME"
echo ""
echo -e "${YELLOW}Note:${NC} Replace the URL with your actual GitHub release URL"
fi