#!/bin/sh
releaseFolder=$(find ../ -path "*-Release" -type d)
fileName="${releaseFolder}/PA Calculator.app"
if [[ -e $fileName ]]; then
	rm -rf "PA Calculator.app"
	rm -rf "Install PA Calculator.app"
	rm -rf setup64bit.dmg
	cp -R "${fileName}" "PA Calculator.app"
	macdeployqt 'PA Calculator.app'
	VERSION=$(grep VERSION= "../source/PA_Calculator.pro" | awk -F= '{print $2;exit}')
	echo "verwendet Version $VERSION"
	DATE=$(date +%F)
	sed -i '' 's/<Version>.*<\/Version>/<Version>'"$VERSION"'<\/Version>/g' packages/com.dkmtech.pacalculator/meta/package.xml
	sed -i '' 's/<ReleaseDate>.*<\/ReleaseDate>/<ReleaseDate>'"$DATE"'<\/ReleaseDate>/g' packages/com.dkmtech.pacalculator/meta/package.xml
	rm -rf packages/com.dkmtech.pacalculator/data
	mkdir packages/com.dkmtech.pacalculator/data
	cp -R 'PA Calculator.app' 'packages/com.dkmtech.pacalculator/data/PA Calculator.app'
	binarycreator -c config/config_mac.xml -p packages 'Install PA Calculator'
	rm -rf 'PA Calculator.app'
	hdiutil create -srcfolder "Install PA Calculator.app" setup64bit.dmg
	rm -rf "Install PA Calculator.app"
	echo "Done"
else
	echo "Could not find PA Calculator.app. Please build it first!"
fi

