#!/bin/bash
############################################
# Script for reading the DTB Server and DTB Master versions from registry
# Usage: ./dtb-versions DTBMASTER_REGKEY or ./ dtb-versions DTBSERVER_REGKEY
#
# rpm69 - adapted wine command for new wine + display usage information
############################################

#Import common definitions
. /opt/dtb/bin/_common_definitions

# Evaluate parameters: if the number of parameters is less than 1 or is not b or r then print out the help.
if [ $# -lt 1 ] || [ !"$1" == "DTBMASTER_REGKEY" ] || [ !"$1" == "DTBSERVER_REGKEY" ]; then
    logger -t $CMD -p ERROR -s "Usage: $0 <DTBMASTER_REGKEY|DTBSERVER_REGKEY> "
    exit
fi
	
rm -rf $DUMMY_REGISTRY_FILE
touch $DUMMY_REGISTRY_FILE
chmod -R 777 $DUMMY_REGISTRY_FILE

#Get the DTBNetzConfig version from the registry
REGENTRY=$1
	#plog "Executing: sudo -u $DTB_USER WINEDEBUG=fixme-all,err-ole,-rpc WINEARCH=win32 WINEPREFIX=$DTB_WORKINGDIR DISPLAY=:$XDISPLAYNR.0 $WINE_BIN regedit /S /E $DUMMY_REGISTRY_FILE \"${!REGENTRY}\""
	sudo -u $DTB_USER WINEDEBUG=fixme-all,err-ole,-rpc \
				WINEARCH=win32 \
				WINEPREFIX=$DTB_WORKINGDIR \
				DISPLAY=:$XDISPLAYNR.0 \
				$WINE_BIN regedit /S /E $DUMMY_REGISTRY_FILE "${!REGENTRY}" &>/dev/null

while read line; do
  if [[ $line == *\"Version\"* ]]; then
	Version="$line"
	break
  fi	
done <$DUMMY_REGISTRY_FILE

rm -rf $DUMMY_REGISTRY_FILE

echo $Version








