#!/bin/sh

plat=`uname`



v1=$(<mosaic/_version.py)
ver=`echo $v1 | cut -d= -f2 | cut -d\" -f2`
read -d '' info1 <<-"EOF"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleIdentifier</key>
	<string>MOSAIC</string>
	<key>CFBundleShortVersionString</key>
	<string>
EOF
read -d '' info2 <<-"EOF"
	</string>
	<key>CFBundleExecutable</key>
	<string>MacOS/MOSAIC</string>
	<key>CFBundleName</key>
	<string>MOSAIC</string>
	<key>NSHighResolutionCapable</key>
	<string>True</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleDisplayName</key>
	<string>MOSAIC</string>
	<key>CFBundleIconFile</key>
	<string>icon.icns</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>LSBackgroundOnly</key>
	<true/>
</dict>
</plist>
EOF
infoplist="$info1$ver$info2"

cd pyinstaller
rm -rf dist/* build/*
pyinstaller mosaic.spec

if [ $plat == 'Darwin' ]; then
	sh ../.scripts/create_osx_icons.sh
	mv icon.icns dist/MOSAIC.app/Contents/Resources
	echo ${infoplist}>dist/MOSAIC.app/Contents/Info.plist
	cd dist
	hdiutil create ./mosaic-${ver}.dmg -srcfolder MOSAIC.app -ov
	mv ./mosaic-${ver}.dmg ../../dist/
else
	cd dist
	zip mosaic-x64-${ver}.zip MOSAIC.exe
	mv ./mosaic-x64-${ver}.zip ../../dist/
fi

cd ../..

