2015-10-01 13:05:28 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-04-22 13:02:09 -07:00
|
|
|
SHOULD_SIGN=$1
|
|
|
|
if [ "$SHOULD_SIGN" ]
|
|
|
|
then
|
|
|
|
echo "Will sign the APP"
|
|
|
|
fi
|
|
|
|
|
2015-10-01 13:05:28 -07:00
|
|
|
# by Andy Maloney
|
|
|
|
# http://asmaloney.com/2013/07/howto/packaging-a-mac-os-x-application-using-a-dmg/
|
|
|
|
|
|
|
|
# make sure we are in the correct dir when we double-click a .command file
|
|
|
|
dir=${0%/*}
|
|
|
|
if [ -d "$dir" ]; then
|
|
|
|
cd "$dir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set up your app name, architecture, and background image file name
|
2015-12-10 12:54:56 -08:00
|
|
|
APP_NAME="Copay"
|
2015-10-01 13:05:28 -07:00
|
|
|
DMG_BACKGROUND_IMG="Background.png"
|
|
|
|
|
2015-12-11 10:06:43 -08:00
|
|
|
PATH_NAME="Copay/osx64/"
|
2015-10-01 13:05:28 -07:00
|
|
|
# you should not need to change these
|
|
|
|
APP_EXE="${PATH_NAME}${APP_NAME}.app/Contents/MacOS/nwjs"
|
|
|
|
|
2015-12-11 10:06:43 -08:00
|
|
|
VOL_NAME="${APP_NAME}-osx"
|
2015-10-01 13:05:28 -07:00
|
|
|
DMG_TMP="${VOL_NAME}-temp.dmg"
|
|
|
|
DMG_FINAL="${VOL_NAME}.dmg"
|
|
|
|
STAGING_DIR="tmp"
|
|
|
|
|
|
|
|
# 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 "${PATH_NAME}${APP_NAME}.app" "${STAGING_DIR}"
|
|
|
|
# ... cp anything else you want in the DMG - documentation, etc.
|
|
|
|
|
|
|
|
pushd "${STAGING_DIR}"
|
|
|
|
|
|
|
|
popd
|
|
|
|
|
2015-10-08 12:42:39 -07:00
|
|
|
# Fix size to 150MB
|
|
|
|
SIZE=150
|
2015-10-01 13:05:28 -07:00
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error: Cannot compute size of staging dir"
|
|
|
|
exit
|
2016-04-22 13:02:09 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Sign Code (MATIAS)
|
|
|
|
if [ $SHOULD_SIGN ]
|
|
|
|
then
|
|
|
|
echo "Signing Copay DMG"
|
|
|
|
|
|
|
|
export IDENTITY="3rd Party Mac Developer Application: BitPay, Inc. (884JRH5R93)"
|
|
|
|
|
|
|
|
# not need for 'out of app store' distribution (?)
|
|
|
|
# export PARENT_PLIST=parent.plist
|
|
|
|
# export CHILD_PLIST=child.plist
|
|
|
|
export APP_PATH=${STAGING_DIR}/${APP_NAME}.app
|
|
|
|
|
|
|
|
codesign --deep -s "${IDENTITY}" $APP_PATH"/Contents/Frameworks/nwjs Helper.app" && echo "Sign 1"
|
|
|
|
codesign --deep -s "${IDENTITY}" $APP_PATH"/Contents/Frameworks/nwjs Helper EH.app" && echo "Sign 2"
|
|
|
|
codesign --deep -s "${IDENTITY}" $APP_PATH"/Contents/Frameworks/nwjs Helper NP.app" && echo "Sign 3"
|
|
|
|
codesign --deep -s "${IDENTITY}" $APP_PATH && echo "Sign 4"
|
|
|
|
echo "Signing Done"
|
|
|
|
|
2015-10-01 13:05:28 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# create the temp DMG file
|
|
|
|
hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \
|
2015-10-08 12:42:39 -07:00
|
|
|
-fsargs "-c c=64,a=16,e=16" -format UDRW -megabytes ${SIZE} "${DMG_TMP}"
|
2015-10-01 13:05:28 -07:00
|
|
|
|
|
|
|
echo "Created DMG: ${DMG_TMP}"
|
|
|
|
|
|
|
|
# mount it and save the device
|
|
|
|
DEVICE=$(hdiutil attach -readwrite -noverify "${DMG_TMP}" | \
|
|
|
|
egrep '^/dev/' | sed 1q | awk '{print $1}')
|
|
|
|
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# add a link to the Applications dir
|
|
|
|
echo "Add link to /Applications"
|
|
|
|
pushd /Volumes/"${VOL_NAME}"
|
|
|
|
ln -s /Applications
|
|
|
|
popd
|
|
|
|
|
|
|
|
# add a background image
|
|
|
|
mkdir /Volumes/"${VOL_NAME}"/.background
|
|
|
|
cp "${DMG_BACKGROUND_IMG}" /Volumes/"${VOL_NAME}"/.background/
|
|
|
|
|
|
|
|
# tell the Finder to resize the window, set the background,
|
|
|
|
# change the icon size, place the icons in the right position, etc.
|
|
|
|
echo '
|
|
|
|
tell application "Finder"
|
|
|
|
tell disk "'${VOL_NAME}'"
|
|
|
|
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, 920, 440}
|
|
|
|
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 file ".background:'${DMG_BACKGROUND_IMG}'"
|
|
|
|
set position of item "'${APP_NAME}'.app" of container window to {160, 205}
|
|
|
|
set position of item "Applications" of container window to {360, 205}
|
|
|
|
close
|
|
|
|
open
|
|
|
|
update without registering applications
|
|
|
|
delay 2
|
|
|
|
end tell
|
|
|
|
end tell
|
|
|
|
' | osascript
|
|
|
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
# unmount it
|
|
|
|
hdiutil detach "${DEVICE}"
|
|
|
|
|
|
|
|
# now make the final image a compressed disk image
|
|
|
|
echo "Creating compressed image"
|
|
|
|
hdiutil convert "${DMG_TMP}" -format UDZO -imagekey zlib-level=9 -o "${DMG_FINAL}"
|
|
|
|
|
|
|
|
# clean up
|
|
|
|
rm -rf "${DMG_TMP}"
|
|
|
|
rm -rf "${STAGING_DIR}"
|
|
|
|
|
|
|
|
echo 'Done.'
|
|
|
|
|
|
|
|
exit
|