#!/bin/bash

# We have left the hash exclamation mark in so that the script can be 
# executed from the command line if required.
# The script file is shown as executable by naming the file extension '.command'
# To make the file executable the file flag for execution must be set.
# This can be done on a terminal command line using the command
# 'chmod +x filename.command' to set the executable flag in the file properties.
# 
# This script gets the current basic development version of stellarium


echo "Add path to Qt5.5.0"

export PATH=~/Qt5.5.0/5.5/clang_64/bin:$PATH

echo "List full path"

echo $PATH

echo "Compile current Stellarium development source from the ~User/Developer directory"

cd ~/Developer

echo "Delete previous stellariumprv directory"

rm -r stellariumprv

echo "Rename last stellarium directory as stellariumprv"

mv stellarium stellariumprv

echo "Get latest stellarium source code from bzr"
# to get a specific version use eg - 'bzr branch lp:stellarium/0.13 stellarium'

bzr branch lp:stellarium stellarium

echo "Got source, now create new build directories under stellarium directory"

cd stellarium
mkdir -p builds/macosx
cd builds/macosx

echo "Run cmake .."

cmake ../..

echo "Run make, install and bundle for OS X"

make
make install

make mac_app

echo "Stellarium app should now be built"

# ~ is home directory starting point

echo "Now create Stellarium dmg and move to Uploads folder for sf.net."

cd ~/Uploads

echo "Delete previous temporary stellarium directory"

rm -r stellarium

echo "Create new stellarium directory"

mkdir stellarium

echo "Copy stellarium app to directory"

cp -r ~/Developer/stellarium/builds/macosx/Stellarium.app ~/Uploads/stellarium

echo "Create stellarium disc image with better compression"
echo "Amend dmg name to match version no."

hdiutil create -format UDBZ -srcfolder stellarium StellariumQT550-0.14.0.dmg

echo "Move disc image to StellariumSFnetFiles upload directory"

mv StellariumQT550-0.14.0.dmg StellariumSFnetFiles