...
|
...
|
@@ -0,0 +1,177 @@
|
|
1
|
+#!/bin/zsh
|
|
2
|
+
|
|
3
|
+#FGDIR=$HOME/scripts/flightgear
|
|
4
|
+#FGADDON=$HOME/.fgfs/flightgear-fgaddon
|
|
5
|
+function fgfs () {
|
|
6
|
+ local fgfs_source=$FGDIR/source
|
|
7
|
+ local fgfs_build=$FGDIR/build
|
|
8
|
+ local fgfs_install=$FGDIR/install
|
|
9
|
+ function update_fg () {
|
|
10
|
+ case $1 in
|
|
11
|
+ data)
|
|
12
|
+ svn up $FGADDON
|
|
13
|
+ ;;
|
|
14
|
+ source)
|
|
15
|
+ typeset -A control_system_data=(
|
|
16
|
+ git pull
|
|
17
|
+ svn up
|
|
18
|
+ )
|
|
19
|
+ for control_system update_command in ${(kv)control_system_data}; do
|
|
20
|
+ find $fgfs_source \
|
|
21
|
+ -maxdepth 2 \
|
|
22
|
+ -mindepth 1 \
|
|
23
|
+ -type d \
|
|
24
|
+ -name .${control_system} \
|
|
25
|
+ -printf "\n[ %h ]\n" \
|
|
26
|
+ -execdir ${control_system} ${update_command} \;
|
|
27
|
+ done
|
|
28
|
+ unset control_system_data control_system update_command
|
|
29
|
+ ;;
|
|
30
|
+ build)
|
|
31
|
+ local simultaneous=$(nproc)
|
|
32
|
+ local previously_installed=()
|
|
33
|
+ mkdir -p $fgfs_install
|
|
34
|
+
|
|
35
|
+ for component in $(<$fgfs_source/ordre); do
|
|
36
|
+# TODO: prendre en compte les cas sans cmake
|
|
37
|
+ title="*** $component:u ***"
|
|
38
|
+ printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
|
|
39
|
+
|
|
40
|
+ local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component")
|
|
41
|
+ [[ ${#previously_installed[@]} -gt 0 ]] \
|
|
42
|
+ && cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}})
|
|
43
|
+ cmake_options+=("-j$simultaneous")
|
|
44
|
+ test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific
|
|
45
|
+
|
|
46
|
+ mkdir -p $fgfs_build/$component
|
|
47
|
+ cd $fgfs_build/$component
|
|
48
|
+
|
|
49
|
+ echo cmake ${cmake_options[@]} $fgfs_source/$component
|
|
50
|
+
|
|
51
|
+ cmake ${cmake_options[@]} $fgfs_source/$component \
|
|
52
|
+ && make -j$simultaneous \
|
|
53
|
+ && make install \
|
|
54
|
+ || {
|
|
55
|
+ echo "erreur construction $component"
|
|
56
|
+ return
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ previously_installed+=($component)
|
|
60
|
+ cd -
|
|
61
|
+ done
|
|
62
|
+ unset component
|
|
63
|
+ ;;
|
|
64
|
+ esac
|
|
65
|
+ }
|
|
66
|
+ function ld_library_path () {
|
|
67
|
+# TODO: prendre en compte les éventuels caractères gênants comme "espace" ou ":" dans $FGDIR
|
|
68
|
+# TODO: ne pas surajouter si déjà présent dans LD_LIBRARY_PATH
|
|
69
|
+ print ${(j,:,):-$(ls -d $FGDIR/install/*/lib)}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}
|
|
70
|
+ }
|
|
71
|
+ local aircrafts="$FGADDON/Aircraft"
|
|
72
|
+ local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
|
|
73
|
+ local aircraft=
|
|
74
|
+ local airport=
|
|
75
|
+ if [[ -o BASH_REMATCH ]]; then
|
|
76
|
+ local bash_rematch_set=1
|
|
77
|
+ fi
|
|
78
|
+
|
|
79
|
+ for fgfs_arg in $@; do
|
|
80
|
+ if test ${fgfs_arg#--} = ${fgfs_arg}; then
|
|
81
|
+############ APPAREIL DANS FGADDON ?
|
|
82
|
+ if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then
|
|
83
|
+ fgfs_args+=("--aircraft=$fgfs_arg")
|
|
84
|
+ fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
|
|
85
|
+
|
|
86
|
+############ APPAREIL DANS FGDIR/source/fgdata ?
|
|
87
|
+ elif official_aircraft=$(find "$fgfs_source/fgdata/Aircraft" -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -printf "%h" -quit) && test -n "$official_aircraft"; then
|
|
88
|
+ fgfs_args+=("--aircraft=$fgfs_arg")
|
|
89
|
+ fgfs_args+=("--aircraft-dir=$official_aircraft")
|
|
90
|
+ unset official_aircraft
|
|
91
|
+
|
|
92
|
+############ SERVEUR MULTIPLAY ?
|
|
93
|
+ elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then
|
|
94
|
+ fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000")
|
|
95
|
+ test -z "$bash_rematch_set" && set +o BASH_REMATCH
|
|
96
|
+
|
|
97
|
+############ AEROPORT ?
|
|
98
|
+ else
|
|
99
|
+ local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
|
|
100
|
+ local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
|
|
101
|
+ local candidate_runway=${fgfs_arg#*+}; [[ $candidate_runway == $fgfs_arg ]] && unset candidate_runway
|
|
102
|
+ local terrafs=${candidate_airport#-}
|
|
103
|
+
|
|
104
|
+ if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then
|
|
105
|
+ candidate_airport=$terrafs
|
|
106
|
+ $HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d
|
|
107
|
+ fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d)
|
|
108
|
+ fgfs_args+=(--disable-terrasync)
|
|
109
|
+ local scenes_dir=$HOME/.fgfs/terrafs.d
|
|
110
|
+ else
|
|
111
|
+ fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync)
|
|
112
|
+ fgfs_args+=(--enable-terrasync)
|
|
113
|
+ local scenes_dir=$HOME/.fgfs/TerraSync
|
|
114
|
+ fi
|
|
115
|
+
|
|
116
|
+ local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
|
|
117
|
+ if [[ -a "${airport_data}.threshold.xml" ]]; then
|
|
118
|
+ fgfs_args+=(--airport=$candidate_airport)
|
|
119
|
+ if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then
|
|
120
|
+ if test $candidate_parking = '?'; then
|
|
121
|
+ echo "Parkings ${candidate_airport:u}:"
|
|
122
|
+ sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml
|
|
123
|
+ return
|
|
124
|
+ elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then
|
|
125
|
+ fgfs_args+=("--parking-id='$candidate_parking'")
|
|
126
|
+ fi
|
|
127
|
+ elif test -n "$candidate_runway"; then
|
|
128
|
+ if test $candidate_runway = '?'; then
|
|
129
|
+ echo "Runways ${candidate_airport:u}:"
|
|
130
|
+ sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml
|
|
131
|
+ return
|
|
132
|
+ elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then
|
|
133
|
+ fgfs_args+=("--runway=$candidate_runway")
|
|
134
|
+ fi
|
|
135
|
+ fi
|
|
136
|
+ fi
|
|
137
|
+ fi
|
|
138
|
+
|
|
139
|
+######## AUTRE OPTION
|
|
140
|
+ else
|
|
141
|
+ case $fgfs_arg in
|
|
142
|
+ --update(-data|-source|-build|))
|
|
143
|
+ for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
|
|
144
|
+ update_fg $up
|
|
145
|
+ done
|
|
146
|
+ unset up
|
|
147
|
+ return
|
|
148
|
+ ;;
|
|
149
|
+ --(show-aircraft|help))
|
|
150
|
+ typeset -A complement=(
|
|
151
|
+ --show-aircraft --fg-aircraft=$FGADDON/Aircraft
|
|
152
|
+ --help --verbose
|
|
153
|
+ )
|
|
154
|
+ export LD_LIBRARY_PATH=$(ld_library_path)
|
|
155
|
+ $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
|
|
156
|
+ unset complement
|
|
157
|
+ return
|
|
158
|
+ ;;
|
|
159
|
+ *)
|
|
160
|
+ fgfs_args+=($fgfs_arg);;
|
|
161
|
+ esac
|
|
162
|
+ fi
|
|
163
|
+ done
|
|
164
|
+ unset fgfs_arg
|
|
165
|
+# test -z "$aircraft" && echo "avion non trouvé" && return
|
|
166
|
+# test -z "$airport" && echo "aéroport inconnu" && return
|
|
167
|
+ export LD_LIBRARY_PATH=$(ld_library_path)
|
|
168
|
+
|
|
169
|
+ echo ${fgfs_args[@]}
|
|
170
|
+# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
|
|
171
|
+ primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
|
|
172
|
+
|
|
173
|
+ if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
|
|
174
|
+ fusermount -u $HOME/.fgfs/terrafs.d
|
|
175
|
+ fi
|
|
176
|
+ unset fgfs_args
|
|
177
|
+}
|