Repository navigation
Expand file tree
/
Copy pathbuild_dmg.sh
More file actions
executable file
·55 lines (43 loc) · 1.58 KB
/
Copy pathbuild_dmg.sh
File metadata and controls
executable file
·55 lines (43 loc) · 1.58 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
#!/bin/bash
# Set variables
APP_NAME="Click2Minimize"
APP_PATH="build/Build/Products/Release/$APP_NAME.app"
DMG_NAME="Click2Minimize.dmg"
DMG_PATH="dist/$DMG_NAME"
TEMP_DIR="temp_dmg_contents" # Temporary directory for DMG contents
CODE_SIGN_IDENTITY="${CODE_SIGN_IDENTITY:--}" # Use environment variable or fallback to ad-hoc
# Create the build directory if it doesn't exist
mkdir -p build
# Clean previous builds
xcodebuild clean -scheme "$APP_NAME" -derivedDataPath build
# Build a universal binary (arm64 + x86_64) — ONLY_ACTIVE_ARCH=NO forces both
# slices on Intel hosts that would otherwise produce x86_64-only.
if ! xcodebuild -scheme "$APP_NAME" -configuration Release -derivedDataPath build \
ARCHS="arm64 x86_64" ONLY_ACTIVE_ARCH=NO; then
echo "Build failed. Exiting."
exit 1
fi
# Code sign the app
if ! codesign --deep --force --verify --verbose --sign "$CODE_SIGN_IDENTITY" "$APP_PATH"; then
echo "Code signing failed. Exiting."
exit 1
fi
# Create the dist directory if it doesn't exist
mkdir -p dist
# Create a temporary folder for DMG contents
mkdir -p "$TEMP_DIR"
# Copy the app to the temporary folder
cp -R "$APP_PATH" "$TEMP_DIR/"
# Create an alias to the Applications folder
ln -s /Applications "$TEMP_DIR/Applications"
# Create a DMG file
hdiutil create "$DMG_PATH" -srcfolder "$TEMP_DIR" -format UDZO -volname "$APP_NAME"
# Clean up temporary files
rm -rf "$TEMP_DIR"
# Check if the DMG was created successfully
if [ -f "$DMG_PATH" ]; then
echo "DMG created successfully at $DMG_PATH"
else
echo "Failed to create DMG."
exit 1
fi