This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
osx-create-dmg.sh.in
executable file
·90 lines (71 loc) · 3.58 KB
/
osx-create-dmg.sh.in
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
#!/bin/bash
set -ex
# Original by Andy Maloney
# http://asmaloney.com/2013/07/howto/packaging-a-mac-os-x-application-using-a-dmg/
# Changes specific to SCAP Workbench by Martin Preisler <mpreisle@redhat.com>
# set up your app name, version number, and background image file name
APP_NAME="scap-workbench"
VERSION="@SCAP_WORKBENCH_VERSION@"
DMG_BACKGROUND_IMG="@CMAKE_SOURCE_DIR@/osx-dmg-background.png"
# you should not need to change these
APP_EXE="@CMAKE_BINARY_DIR@/${APP_NAME}.app/Contents/MacOS/${APP_NAME}"
# make sure Qt frameworks are included
macdeployqt @CMAKE_BINARY_DIR@/${APP_NAME}.app
VOL_NAME="${APP_NAME}-${VERSION}" # volume name will be "SuperCoolApp-1.0.0"
DMG_TMP="${VOL_NAME}-temp.dmg"
DMG_FINAL="${VOL_NAME}.dmg" # final DMG name will be "SuperCoolApp-1.0.0.dmg"
STAGING_DIR="@CMAKE_BINARY_DIR@/OSX-DMG-TEMP" # we copy all our stuff into this dir
# Check the background image DPI and convert it if it isn't 72x72
_BACKGROUND_IMAGE_DPI_H=`sips -g dpiHeight ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'`
_BACKGROUND_IMAGE_DPI_W=`sips -g dpiWidth ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'`
if [ $(echo " $_BACKGROUND_IMAGE_DPI_H != 72.0 " | bc) -eq 1 -o $(echo " $_BACKGROUND_IMAGE_DPI_W != 72.0 " | bc) -eq 1 ]; then
echo "WARNING: The background image's DPI is not 72. This will result in distorted backgrounds on Mac OS X 10.7+."
echo " I will convert it to 72 DPI for you."
_DMG_BACKGROUND_TMP="${DMG_BACKGROUND_IMG%.*}"_dpifix."${DMG_BACKGROUND_IMG##*.}"
sips -s dpiWidth 72 -s dpiHeight 72 ${DMG_BACKGROUND_IMG} --out ${_DMG_BACKGROUND_TMP}
DMG_BACKGROUND_IMG="${_DMG_BACKGROUND_TMP}"
fi
# clear out any old data
rm -rf "${STAGING_DIR}" "${DMG_TMP}" "${DMG_FINAL}"
# copy over the stuff we want in the final disk image to our staging dir
mkdir -p "${STAGING_DIR}"
cp -rpf "${APP_NAME}.app" "${STAGING_DIR}"
# ... cp anything else you want in the DMG - documentation, etc.
pushd "${STAGING_DIR}"
# strip the executable
echo "Stripping ${APP_EXE}..."
strip -u -r "${APP_EXE}"
# compress the executable if we have upx in PATH
# UPX: http://upx.sourceforge.net/
if hash upx 2>/dev/null; then
echo "Compressing (UPX) ${APP_EXE}..."
upx -9 "${APP_EXE}"
fi
# ... perform any other stripping/compressing of libs and executables
popd
#------------- Updated section to support creating a dmg in macOS 10.13+ -------------#
# Changes made by Carlos Matos <cmatos@redhat.com
# Issues identified when trying to port CI from Travis to Github Actions. Using macOS 10.14+
# would cause the CI job to fail due to security enhancements made after High Sierra. This
# was essentially causing the original applescript to timeout after it's default 2 minute waiting
# period. After making several attempts to work around this issue - it became clear that this was
# going to take too much effort - if it even would work at all. I began looking at alternative
# solutions, which lead me to a couple of open source projects created by people who simply wanted
# to make the process of creating a dmg easier. After testing dmgbuild and appdmg, I settled with
# appdmg since it was easy to port our existing configuration to it.
cat << EOF > scapwb.json
{
"title": "SCAP Workbench",
"background": "${DMG_BACKGROUND_IMG}",
"format": "UDZO",
"window": { "position": { "x": 300, "y": 300 } },
"contents": [
{ "x": 360, "y": 225, "type": "link", "path": "/Applications" },
{ "x": 160, "y": 225, "type": "file", "path": "${STAGING_DIR}/${APP_NAME}.app" }
]
}
EOF
echo "Creating customized DMG image..."
appdmg scapwb.json ${DMG_FINAL}
echo 'Done.'
exit