#!/bin/bash

. /mdk/bin/forkFunctions.inc

status=$(forkStatusMessage)
forkMenuOption="/tmp/menuForkChoice$$"

# Get the name of the non root user
nonRootUser=$(users | sed 's/ /\n/g' | sort -u | grep -v "^root$" | head -1)

# Allow all access to the X session of the non root user
#su $nonRootUser -c xhost +


# 	"makeSymlinkm23mdk" "Makes m23/MDK symlinks" \
# 	"makeDevel" "Makes a development copy of m23/MDK" \
# 	"switchDevel" "Switches to m23/MDKs development version"\
# 	"switchRelease" "Switches to m23/MDKs release version"\
# 	"meldm23" "Check for differences in m23"\
# 	"meldmdk" "Check for differences in MDK"\
# 	"moveDevel2Release" "Makes the development copy the current release"\



dialog --clear --backtitle "m23 Software Development Kit (MDK)" --title "Fork tool" \
	--menu "$status

Main menu" 19 128 12 \
	"makeRelease" "Creates a git release version branch for m23/MDK"\
	"switchDevel" "Switches to m23/MDK's development version git branch"\
	"switchRelease" "Switches to m23/MDK's release version git branch"\
	"meldm23" "Meld changes from release or master into the current /m23"\
	"meldmdk" "Meld changes from release or master into the current /mdk"\
	"mergeReleaseToNewRelease" "Merge from the old release version to the new without a development version as intermediate step"\
	"help" "help"\
	"quit" "quit menu" 2> $forkMenuOption
retval=$?
case $retval in
	1)
		exit;;
	255)
		exit;;
esac

choice=`cat $forkMenuOption`
rm $forkMenuOption

case $choice in

	"makeRelease")
		makeRelease
		/mdk/bin/menuFork
		exit;;


	"switchDevel")
		# git checkout master
		switchDevel
		/mdk/bin/menuFork
		exit;;

	"switchRelease")
		switchRelease
		/mdk/bin/menuFork
		exit;;

	"meldm23")
		meldDevelopmentReleaseBranch m23
		/mdk/bin/menuFork
		exit;;

	"meldmdk")
		meldDevelopmentReleaseBranch mdk
		/mdk/bin/menuFork
		exit;;

	"mergeReleaseToNewRelease")
		mergeReleaseToNewRelease
		/mdk/bin/menuFork
		exit;;

	"help")
		dialog --backtitle "m23 Software Development Kit (MDK)" --textbox /mdk/bin/help/menuFork.hlp 22 80
		/mdk/bin/menuFork
		exit;;
esac