Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final designed DMG #454

Closed
wants to merge 12 commits into from
69 changes: 52 additions & 17 deletions macosx/Makefile
Expand Up @@ -33,12 +33,12 @@ NMAP_UPDATE_STAGING_DIR = nmap-update

JHBUILD_PREFIX=$(HOME)/gtk/inst
export JHBUILD_PREFIX
# MACPORTS_PREFIX is still here because of nmap-update, which needs
# libsvn and libapr, which jhbuild doesn't support yet.
MACPORTS_PREFIX=$(HOME)/macports-10.8
PREFIX = /usr/local

PACKAGEMAKER = /Developer/usr/bin/packagemaker
README_FILE = README.md
COPYING_FILE = COPYING
3RD_P_LIC_FILE = 3rd-party-licenses.txt
LICENSES_FILE = licenses

EXTRA_DIST = README.md ../COPYING ../docs/3rd-party-licenses.txt ../docs/licenses

Expand Down Expand Up @@ -70,15 +70,53 @@ CFLAGS += $(UNIVERSAL_CFLAGS)
CXXFLAGS += $(UNIVERSAL_CXXFLAGS)
LDFLAGS += $(UNIVERSAL_LDFLAGS)

MAC_FLAGS = -lsasl2 -liconv -framework CoreFoundation -framework Security

# Jhbuild static libraries
PYTHON = $(JHBUILD_PREFIX)/bin/python2.7
OPENSSL_STATIC = $(JHBUILD_PREFIX)/lib/libssl.a $(JHBUILD_PREFIX)/lib/libcrypto.a

$(IMAGE_NAME): path-check tool-checks $(IMAGE_STAGING_DIR)/$(PKG_NAME)
SVN_STATIC = $(JHBUILD_PREFIX)/lib/libsvn_client-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_wc-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_diff-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_delta-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_subr-1.a \
$(JHBUILD_PREFIX)/lib/libexpat.a \
$(JHBUILD_PREFIX)/lib/libsvn_ra-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_ra_svn-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_ra_local-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_fs-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_repos-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_fs_util-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_fs_fs-1.a \
$(JHBUILD_PREFIX)/lib/libsvn_fs_x-1.a \
$(JHBUILD_PREFIX)/lib/libintl.a \
$(JHBUILD_PREFIX)/lib/libsvn_ra_serf-1.a \
$(JHBUILD_PREFIX)/lib/libserf-1.a \
$(JHBUILD_PREFIX)/lib/libz.a \
$(JHBUILD_PREFIX)/lib/libsqlite3.a
APR_STATIC = $(JHBUILD_PREFIX)/lib/libapr-1.a \
$(JHBUILD_PREFIX)/lib/libaprutil-1.a \
$(JHBUILD_PREFIX)/lib/libapriconv-1.a

export ICON_SIZE=88
export FONT_SIZE=13
export MPKG_POS_X=110
export MPKG_POS_Y=170
export APPS_POS_X=110
export APPS_POS_Y=310
export README_POS_X=802
export README_POS_Y=180
export COPYING_POS_X=802
export COPYING_POS_Y=310
export THIRD_P_POS_X=802
export THIRD_P_POS_Y=440
export LICENSES_POS_X=670
export LICENSES_POS_Y=60

$(IMAGE_NAME): tool-checks $(IMAGE_STAGING_DIR)/$(PKG_NAME)
rm -f $@
hdiutil create -imagekey zlib-level=9 -srcfolder $(IMAGE_STAGING_DIR) $@

path-check:
if (echo $(PATH) | grep -F "$(MACPORTS_PREFIX)"); then false; else echo "Path is OK"; fi
./createdmg.sh $(IMAGE_STAGING_DIR) $(README_FILE) $(COPYING_FILE) $(3RD_P_LIC_FILE) $(LICENSES_FILE)
./check_test.sh $(README_FILE) $(COPYING_FILE) $(3RD_P_LIC_FILE) $(LICENSES_FILE)

tool-checks: have-$(CC) have-jhbuild have-gtk-mac-bundler

Expand Down Expand Up @@ -144,13 +182,10 @@ stage-nping: export-$(NPING_BUILD_DIR)
make -C $(NPING_BUILD_DIR) install-nping DESTDIR="`pwd`/$(NPING_STAGING_DIR)" OPENSSL_LIBS="$(OPENSSL_STATIC)"

stage-nmap-update: export-$(NMAP_UPDATE_BUILD_DIR)
cd $(NMAP_UPDATE_BUILD_DIR) && ./configure --without-zenmap --without-ncat --without-ndiff --without-nping --with-nmap-update --with-apr=$(MACPORTS_PREFIX) --with-subversion=$(MACPORTS_PREFIX) $(CONFIGURE_ARGS)
make -C $(NMAP_UPDATE_BUILD_DIR) build-nmap-update
cd $(NMAP_UPDATE_BUILD_DIR) && ./configure --without-zenmap --without-ncat --without-ndiff --without-nping --with-nmap-update --with-apr=$(JHBUILD_PREFIX) --with-subversion=$(JHBUILD_PREFIX) --with-serf=$(JHBUILD_PREFIX) --with-openssl=$(JHBUILD_PREFIX) $(CONFIGURE_ARGS)
make -C $(NMAP_UPDATE_BUILD_DIR) build-nmap-update APR_LIBS="$(APR_STATIC)" SVN_LIBS="$(SVN_STATIC)" OPENSSL_LIBS="$(OPENSSL_STATIC)" MAC_FLAGS="$(MAC_FLAGS)"
rm -rf $(NMAP_UPDATE_STAGING_DIR)
make -C $(NMAP_UPDATE_BUILD_DIR) install-nmap-update DESTDIR="`pwd`/$(NMAP_UPDATE_STAGING_DIR)"
install_name_tool -change "$(MACPORTS_PREFIX)/lib/libapr-1.0.dylib" "/usr/lib/libapr-1.0.dylib" "$(NMAP_UPDATE_STAGING_DIR)/usr/local/bin/nmap-update"
install_name_tool -change "$(MACPORTS_PREFIX)/lib/libsvn_client-1.0.dylib" "/usr/lib/libsvn_client-1.0.dylib" "$(NMAP_UPDATE_STAGING_DIR)/usr/local/bin/nmap-update"
install_name_tool -change "$(MACPORTS_PREFIX)/lib/libsvn_subr-1.0.dylib" "/usr/lib/libsvn_subr-1.0.dylib" "$(NMAP_UPDATE_STAGING_DIR)/usr/local/bin/nmap-update"
make -C $(NMAP_UPDATE_BUILD_DIR) install-nmap-update DESTDIR="`pwd`/$(NMAP_UPDATE_STAGING_DIR)" APR_LIBS="$(APR_STATIC)" SVN_LIBS="$(SVN_STATIC)" OPENSSL_LIBS="$(OPENSSL_STATIC)" MAC_FLAGS="$(MAC_FLAGS)"

# make-bundle.sh uses these to build its authorization wrapper.
export CC ARCHFLAGS CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
Expand Down Expand Up @@ -188,4 +223,4 @@ clean:
rm -f COPYING.formatted
rm -f $(IMAGE_NAME)

.PHONY: clean export-% stage-%
.PHONY: clean export-% stage-%
124 changes: 124 additions & 0 deletions macosx/check_test.sh
@@ -0,0 +1,124 @@
#!/bin/sh

export version=$(grep '^\#[ \t]*define[ \t]\+NMAP_VERSION' ../nmap.h | sed -e 's/.*"\(.*\)".*/\1/' -e 'q')
export title="nmap-${version}"
export disk="/Volumes/${title}"
export backgroundPictureName="nmap.png"
export finalDMGName="${title}.dmg"
export applicationName="${title}.mpkg"
RES="True"
NB_FILES=7

hdiutil attach ${finalDMGName}

# Try to list files in the Volume, if we can't, its because its not ready yet
# so we should sleep while its mounted before trying to check if everything is ok
stop=false
while [ "$stop" = false ]; do
test=`ls -l /Volumes/${title}/ | wc -l`
if [ "$test" -eq $NB_FILES ]; then
stop=true
fi
sleep 1
done

echo "\nDisk: ${disk}"
echo "Checking positions...\n"

export MPKG=`echo '
tell application "Finder"
set f to POSIX file "'${disk}'/'${applicationName}'" as alias
get properties of f
end tell
' | osascript | grep -o 'position:[0-9]*, [0-9]*' | awk -F':' '{ print $2 }'`

export README=`echo '
tell application "Finder"
set f to POSIX file "'${disk}'/'$1'" as alias
get properties of f
end tell
' | osascript | grep -o 'position:[0-9]*, [0-9]*' | awk -F':' '{ print $2 }'`

export COPYING=`echo '
tell application "Finder"
set f to POSIX file "'${disk}'/'$2'" as alias
get properties of f
end tell
' | osascript | grep -o 'position:[0-9]*, [0-9]*' | awk -F':' '{ print $2 }'`

export LICENSES_3RD=`echo '
tell application "Finder"
set f to POSIX file "'${disk}'/'$3'" as alias
get properties of f
end tell
' | osascript | grep -o 'position:[0-9]*, [0-9]*' | awk -F':' '{ print $2 }'`

export LICENSES=`echo '
tell application "Finder"
set f to POSIX file "'${disk}'/'$4'" as alias
get properties of f
end tell
' | osascript | grep -o 'position:[0-9]*, [0-9]*' | awk -F':' '{ print $2 }'`

if [ "$MPKG" = "$MPKG_POS_X, $MPKG_POS_Y" ]; then
echo "${applicationName}: OK"
else
echo "${applicationName}: Wrong"
RES="False"
fi;

if [ "$README" = "$README_POS_X, $README_POS_Y" ]; then
echo "README.md: OK"
else
echo "README.md: Wrong"
RES="False"
fi;

if [ "$COPYING" = "$COPYING_POS_X, $COPYING_POS_Y" ]; then
echo "COPYING: OK"
else
echo "COPYING: Wrong"
RES="False"
fi;

if [ "$LICENSES_3RD" = "$THIRD_P_POS_X, $THIRD_P_POS_Y" ]; then
echo "3rd-party-licenses.txt: OK"
else
echo "3rd-party-licenses.txt: Wrong"
RES="False"
fi;

if [ "$LICENSES" = "$LICENSES_POS_X, $LICENSES_POS_Y" ]; then
echo "licenses: OK"
else
echo "licenses: Wrong"
RES="False"
fi;

export BG=`echo '
tell application "Finder"
set f to POSIX file "'${disk}'/.background/'${backgroundPictureName}'" as alias
if exists file f then
return true
else
return false
end if
end tell
' | osascript`

if [ "$BG" = "true" ]; then
echo "\nBackground exists: Yes\n"
else
echo "\nBackground exists: No\n"
RES="False"
fi;

hdiutil detach ${disk}

if [ "$RES" = "True" ]; then
echo "\nTest passed?: Yes\n"
exit 0
else
echo "\nTest passed?: No\nThere are some errors that should be corrected\n"
exit 1
fi;
74 changes: 74 additions & 0 deletions macosx/createdmg.sh
@@ -0,0 +1,74 @@
#!/bin/sh

export source=$1
export version=$(grep '^\#[ \t]*define[ \t]\+NMAP_VERSION' ../nmap.h | sed -e 's/.*"\(.*\)".*/\1/' -e 'q')
export title="nmap-${version}"
export size=50000
export backgroundPictureName="nmap.png"
export finalDMGName="${title}.dmg"
export applicationName="${title}.mpkg"
NB_FILES=7

rm -rf ${source}/.background/${backgroundPictureName}
rm -rf ${source}/.background/
rm -rf pack.temp.dmg
rm -rf ${title}.dmg
rm -rf ${source}/Applications

# Copy the background image to the background of the image disk
mkdir ${source}/.background/
cp ${backgroundPictureName} ${source}/.background/
ln -s /Applications ${source}/

# Ensure that we have no virtual disk currently mounted
hdiutil detach /Volumes/${title}/ 2> /dev/null

hdiutil create -srcfolder "${source}" -volname "${title}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -ov -format UDRW -size ${size}k pack.temp.dmg

# Mount the disk image and store the device name
export device=$(hdiutil attach -readwrite -noverify -noautoopen "pack.temp.dmg" | egrep '^/dev/' | sed 1q | awk '{print $1}')

# Try to list files in the Volume, if we can't, its because its not ready yet
# so we should sleep while its mounted before trying to design it with Applescript
stop=false
while [ "$stop" = false ]; do
test=`ls -l /Volumes/${title}/ | wc -l`
if [ "$test" -eq $NB_FILES ]; then
stop=true
fi
sleep 1
done

# Applescript: design the virtual disk image we just mounted
echo '
tell application "Finder"
tell disk "'${title}'"
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 {100, 100, 1000, 660}
set theViewOptions to the icon view options of container window
set icon size of theViewOptions to '${ICON_SIZE}'
set text size of theViewOptions to '${FONT_SIZE}'
set arrangement of theViewOptions to not arranged
set background picture of theViewOptions to file ".background:'${backgroundPictureName}'"

set position of item "'${applicationName}'" of container window to {'${MPKG_POS_X}', '${MPKG_POS_Y}'}
set position of item "Applications" of container window to {'${APPS_POS_X}', '${APPS_POS_Y}'}
set position of item "'$2'" of container window to {'${README_POS_X}', '${README_POS_Y}'}
set position of item "'$3'" of container window to {'${COPYING_POS_X}', '${COPYING_POS_Y}'}
set position of item "'$4'" of container window to {'${THIRD_P_POS_X}', '${THIRD_P_POS_Y}'}
set position of item "'$5'" of container window to {'${LICENSES_POS_X}', '${LICENSES_POS_Y}'}

update without registering applications

close
end tell
end tell
' | osascript

hdiutil detach ${device}
hdiutil convert "pack.temp.dmg" -format UDZO -imagekey zlib-level=9 -o "${finalDMGName}"
rm -f pack.temp.dmg
Binary file added macosx/nmap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.