Linux>fgfs.sh

fgfs.sh

<-- LINUX

#!/bin/bash
## Script réalisé par Bertrand Perrier
# Ce script lance flightgear en plaçant l'avion sur un parking
# 04/03/17 : création
# 09/03/17 : maj

pathTS="/home/$USER/.fgfs/TerraSync"
pathRunFG="/home/$USER/fgfs/stable"
pathAircraft="/home/$USER/flightgear/aircraft"
pathScenery="/home/$USER/flightgear/Le_Mans/"
CallSign="fantasy7"


if [ -z "$1" ];
then
	echo "Utilisation : $BASH_SOURCE aircraft airport online(off/on) [OPTIONS] [verbose]"
	echo "exemple : $BASH_SOURCE 777-200er LFPC off verbose"
	echo "exemple : $BASH_SOURCE ls_ac to list aircraft"
fi

if [ "$1" = "ls_ac" ];
then
	echo "liste des avions installés"
	echo "----------------"
	$pathRunFG/run_fgfs.sh --fg-aircraft=$pathAircraft --show-aircraft
fi

if [ -n "$1" ] && [ "$1" != "ls_ac" ];
then
	if [ -z "$2" ];
	then
		echo "précisez l'OACI"
		echo "---------------"
	else
		
		aoci='echo "$2" | tr '[:lower:]' '[:upper:]'`
		aoci1=`echo ${aoci:0:1}`
		aoci2=`echo ${aoci:1:1}`
		aoci3=`echo ${aoci:2:1}`
		result=`cat $pathTS/Airports/$aoci1/$aoci2/$aoci3/$aoci.groundnet.xml | grep index=\"0\"`
		heading=`echo $heading | sed 's/heading=\"//' | sed 's/\"//'`

		lat1=`echo $result | awk -F" " '{ print $5}'`
		lat2=`echo $result | awk -F" " '{ print $6}'`
		lon1=`echo $result | awk -F" " '{ print $7}'`
		lon2=`echo $result | awk -F" " '{ print $8}'`
		heading=`echo $result | awk -F" " '{ print $9}'`
		lat1=`echo $lat1 | sed 's/\lat="N//'`
		lat1=`echo $lat1 | sed 's/\lat="S//'`
		lon1=`echo $lon1 | sed 's/\lon="E//'`
		lon1=`echo $lon1 | sed 's/\lon="O//'`
		lon2=`echo $lon2 | sed 's/\"//'`
		lat2=`echo $lat2 | sed 's/\"//'`

		# convertir lat et lon   N43 39.362820" lon="E7 12.151500"
		# x + y /60
		# 43,656047     7,202525
		lat=$(bc <<< "scale = 6; $lat1+($lat2/60)")
		lon=$(bc <<< "scale = 6; $lon1+($lon2/60)")

		# verbose
		if [ -n "$4" ]; then 
			echo ""
			echo "aoci   : $aoci"
			echo "parsed : $aoci1$aoci2$aoci3"
			echo ""
			echo "result"
			echo "------"
			echo $result
			echo "lat1 : $lat1"
			echo "lat2 : $lat2"
			echo "lon1 : $lon1"
			echo "lon2 : $lon2 "
			echo "heading : $heading"
			echo ""
			echo "decimal"
			echo "-------"
			echo "lat : $lat"
			echo "lon : $lon"
		fi
		echo "lancement de FlightGear"
		echo "-----------------------"
		if [ "$3" = "on" ];
		then
			echo "mode online"
			$pathRunFG/run_fgfs.sh --fg-aircraft=$pathAircraft --fg-scenery=$pathScenery --callsign=$CallSign --multiplay=out,10,mpserver01.flightgear.org,5000 --timeofday=noon --disable-ai-traffic --disable-random-objects --enable-terrasync --aircraft=$1 --lat=$lat --lon=$lon --heading=$heading
		else
			echo "mode offline"
			$pathRunFG/run_fgfs.sh --fg-aircraft=$pathAircraft --fg-scenery=$pathScenery --callsign=$CallSign --timeofday=noon --disable-ai-traffic --disable-random-objects --enable-terrasync --aircraft=$1 --lat=$lat --lon=$lon --heading=$heading
		fi
	fi
fi

<-- LINUX