ajout fonction pour lancemen...
|
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 |
|
ajout de gestion de bdd pour...
|
11 |
fgaddon) |
12 |
DB=$FGADDON/fgaddon.db $HOME/.fgfs/fgaddon |
|
code rearrangement
|
13 |
;; |
14 |
check) |
|
15 |
test -r $HOME/.fgfs/jenkins-status && bash $HOME/.fgfs/jenkins-status |
|
16 |
;; |
|
add RSS reader for FG code
|
17 |
rss) |
18 |
test -r $HOME/.fgfs/fgcoderss && bash $HOME/.fgfs/fgcoderss |
|
19 |
;; |
|
ajout fonction pour lancemen...
|
20 |
data) |
ajout de gestion de bdd pour...
|
21 |
for control_system update_command in ${(kv)control_system_data}; do |
22 |
find $FGADDON \ |
|
23 |
-maxdepth 3 \ |
|
24 |
-mindepth 1 \ |
|
25 |
-type d \ |
|
26 |
-name .${control_system} \ |
|
27 |
-printf "\n[ %h ]\n" \ |
|
28 |
-execdir ${control_system} ${update_command} \; |
|
29 |
done |
|
ajout fonction pour lancemen...
|
30 |
;; |
31 |
source) |
|
code rearrangement
|
32 |
for component in $(<$fgfs_source/.$2); do |
33 |
for control_system update_command in ${(kv)control_system_data}; do |
|
34 |
find $fgfs_source/$component \ |
|
35 |
-maxdepth 1 \ |
|
36 |
-type d \ |
|
37 |
-name .${control_system} \ |
|
38 |
-printf "\n[ %h ]\n" \ |
|
39 |
-execdir ${control_system} ${update_command} \; |
|
40 |
done |
|
ajout fonction pour lancemen...
|
41 |
done |
42 |
;; |
|
43 |
build) |
|
44 |
local simultaneous=$(nproc) |
|
45 |
local previously_installed=() |
|
46 |
mkdir -p $fgfs_install |
|
make possible to compile dif...
|
47 |
for component in $(<$fgfs_source/.$2); do |
code rearrangement
|
48 |
if test -d $fgfs_source/$component/.git; then |
49 |
local branch=$(git -C $fgfs_source/$component name-rev --name-only --no-undefined --always HEAD) |
|
50 |
elif test -d $fgfs_source/${component}/.svn; then |
|
51 |
local branch=${${(s:/:)$(svn info --show-item relative-url $fgfs_source/$component)}[2]} |
|
52 |
fi |
|
53 |
title="*** ${component:u}${branch:+ [$branch]} ***" |
|
ajout fonction pour lancemen...
|
54 |
printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}" |
55 | ||
code rearrangement
|
56 |
# TODO: prendre en compte les cas sans cmake |
57 |
if test -r $fgfs_source/$component/CMakeLists.txt; then |
|
58 |
local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component") |
|
59 |
test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific |
|
60 |
if test ${#previously_installed[@]} -gt 0; then |
|
61 |
cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}}) |
|
62 |
cmake_options+=(${(j. .)${:--DCMAKE_INCLUDE_PATH=$fgfs_install/${^previously_installed}/include}}) |
|
63 |
fi |
|
64 |
cmake_options+=("-j$simultaneous") |
|
ajout fonction pour lancemen...
|
65 | |
code rearrangement
|
66 |
mkdir -p $fgfs_build/$component |
67 |
cd $fgfs_build/$component |
|
ajout fonction pour lancemen...
|
68 | |
code rearrangement
|
69 |
echo cmake ${cmake_options[@]} $fgfs_source/$component |
70 | ||
71 |
cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \ |
|
72 |
&& make -j$simultaneous > /dev/null \ |
|
73 |
&& make install \ |
|
74 |
|| { |
|
75 |
echo "erreur construction $component" |
|
76 |
cd $FGDIR |
|
77 |
return |
|
78 |
} |
|
79 |
fi |
|
ajout fonction pour lancemen...
|
80 | |
81 |
previously_installed+=($component) |
|
82 |
cd - |
|
83 |
done |
|
84 |
unset component |
|
85 |
;; |
|
86 |
esac |
|
87 |
} |
|
88 |
function ld_library_path () { |
|
smarter use of IFS
|
89 |
local IFS=$'\n' |
fix multiple instances on LD...
|
90 |
for lib in $(ls -d $FGDIR/install/*/lib); do |
91 |
egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" |
|
92 |
done |
|
93 |
export LD_LIBRARY_PATH |
|
ajout fonction pour lancemen...
|
94 |
} |
95 |
local aircrafts="$FGADDON/Aircraft" |
|
96 |
local fgfs_args=("--fg-root=$FGDIR/source/fgdata") |
|
97 |
local aircraft= |
|
98 |
local airport= |
|
99 |
if [[ -o BASH_REMATCH ]]; then |
|
100 |
local bash_rematch_set=1 |
|
101 |
fi |
|
102 | ||
103 |
for fgfs_arg in $@; do |
|
104 |
if test ${fgfs_arg#--} = ${fgfs_arg}; then |
|
105 |
############ APPAREIL DANS FGADDON ? |
|
106 |
if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then |
|
107 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
108 |
fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft") |
|
109 | ||
110 |
############ APPAREIL DANS FGDIR/source/fgdata ? |
|
111 |
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 |
|
112 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
113 |
fgfs_args+=("--aircraft-dir=$official_aircraft") |
|
114 |
unset official_aircraft |
|
115 | ||
ajout de gestion de bdd pour...
|
116 |
############ APPAREIL DANS FGADDON ? |
117 |
elif which sqlite3 > /dev/null 2>&1 \ |
|
118 |
&& test -r $FGADDON/fgaddon.db \ |
|
remove -set.xml from filenam...
|
119 |
&& test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}'") -eq 1; then |
ré-écriture complète
|
120 |
model=$(sqlite3 $FGADDON/fgaddon.db <<< "select name from aircrafts inner join setxml on aircrafts.id = setxml.variantof where setxml.file is '${fgfs_arg}'") |
ajout de gestion de bdd pour...
|
121 |
read -q "REPLY?download $model ? (y/N) " |
122 |
if test -n "$REPLY" && test ${REPLY:l} = "y"; then |
|
123 |
svn co https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft/$model $FGADDON/Aircraft/$model |
|
124 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
125 |
else |
|
126 |
echo "aircraft $fgfs_arg isn't installed" |
|
127 |
return |
|
128 |
fi |
|
129 | ||
ajout fonction pour lancemen...
|
130 |
############ SERVEUR MULTIPLAY ? |
131 |
elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then |
|
132 |
fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000") |
|
fix some fgfs options
|
133 |
fgfs_args+=("--callsign=f-zakh") |
ajout fonction pour lancemen...
|
134 |
test -z "$bash_rematch_set" && set +o BASH_REMATCH |
135 | ||
ajout trace de vol
|
136 |
############ DEMANDE DE TRACE DE VOL ? |
137 |
elif [[ $fgfs_arg == "log" ]]; then |
|
138 |
# option construite plus tard avec nom de l'appareil |
|
139 |
local log_requested=1 |
|
140 | ||
ajout fonction pour lancemen...
|
141 |
############ AEROPORT ? |
142 |
else |
|
143 |
local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*} |
|
144 |
local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking |
|
145 |
local candidate_runway=${fgfs_arg#*+}; [[ $candidate_runway == $fgfs_arg ]] && unset candidate_runway |
|
146 |
local terrafs=${candidate_airport#-} |
|
147 | ||
148 |
if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then |
|
149 |
candidate_airport=$terrafs |
|
150 |
$HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d |
|
151 |
fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d) |
|
152 |
fgfs_args+=(--disable-terrasync) |
|
153 |
local scenes_dir=$HOME/.fgfs/terrafs.d |
|
154 |
else |
|
155 |
fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync) |
|
156 |
fgfs_args+=(--enable-terrasync) |
|
157 |
local scenes_dir=$HOME/.fgfs/TerraSync |
|
158 |
fi |
|
159 | ||
160 |
local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}" |
|
161 |
if [[ -a "${airport_data}.threshold.xml" ]]; then |
|
162 |
fgfs_args+=(--airport=$candidate_airport) |
|
163 |
if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then |
|
164 |
if test $candidate_parking = '?'; then |
|
165 |
echo "Parkings ${candidate_airport:u}:" |
|
166 |
sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml |
|
167 |
return |
|
168 |
elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then |
|
fix some fgfs options
|
169 |
fgfs_args+=("--parkpos='$candidate_parking'") |
ajout fonction pour lancemen...
|
170 |
fi |
171 |
elif test -n "$candidate_runway"; then |
|
172 |
if test $candidate_runway = '?'; then |
|
173 |
echo "Runways ${candidate_airport:u}:" |
|
174 |
sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml |
|
175 |
return |
|
176 |
elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then |
|
177 |
fgfs_args+=("--runway=$candidate_runway") |
|
178 |
fi |
|
179 |
fi |
|
180 |
fi |
|
181 |
fi |
|
182 | ||
183 |
######## AUTRE OPTION |
|
184 |
else |
|
185 |
case $fgfs_arg in |
|
code rearrangement
|
186 |
--update(-data|-source|-build|)) |
187 |
if test -z "$2" || test ! -r $fgfs_source/.$2; then |
|
188 |
echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>" |
|
189 |
echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.} |
|
190 |
return 1 |
|
191 |
fi |
|
192 |
for component in $(<$fgfs_source/.$2); do |
|
193 |
if ! test -d $fgfs_source/$component; then |
|
194 |
echo component $component not found |
|
195 |
return 1 |
|
196 |
fi |
|
197 |
done |
|
198 |
typeset -A control_system_data=( |
|
199 |
git pull |
|
200 |
svn up |
|
201 |
) |
|
ajout fonction pour lancemen...
|
202 |
for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do |
make possible to compile dif...
|
203 |
update_fg $up ${2:-flightgear} |
ajout fonction pour lancemen...
|
204 |
done |
code rearrangement
|
205 |
unset control_system_data control_system update_command up |
206 |
return |
|
207 |
;; |
|
add RSS reader for FG code
|
208 |
--update-(fgaddon|check|rss)) |
code rearrangement
|
209 |
update_fg ${fgfs_arg#--update-} |
ajout fonction pour lancemen...
|
210 |
return |
211 |
;; |
|
212 |
--(show-aircraft|help)) |
|
ajout trace de vol
|
213 |
local -A complement=( |
ajout fonction pour lancemen...
|
214 |
--show-aircraft --fg-aircraft=$FGADDON/Aircraft |
215 |
--help --verbose |
|
216 |
) |
|
fix multiple instances on LD...
|
217 |
ld_library_path |
ajout fonction pour lancemen...
|
218 |
$FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager |
219 |
return |
|
220 |
;; |
|
add --search and --mp-list o...
|
221 |
--search) |
222 |
command -v sqlite3 > /dev/null || return |
|
223 |
sqlite3 $FGADDON/fgaddon.db <<< "select file from setxml where file like '%$2%'" |
|
224 |
return |
|
225 |
;; |
|
226 |
--mp-list) |
|
227 |
local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX) |
|
228 |
declare -A installed_model fgaddon_model unknown_model |
|
229 |
local ac_name= |
|
230 |
telnet mpserver01.flightgear.org 5001 2>/dev/null > $mplist |
|
print number of online pilot...
|
231 |
grep 'pilot(s) online' $mplist |
232 |
echo |
|
add --search and --mp-list o...
|
233 |
for model in $(awk '/@/{a[$NF]++}END{for (i in a) print i}' $mplist); do |
234 |
if test -r $FGADDON/$model \ |
|
separation AI/real models, a...
|
235 |
-o -r $FGDIR/source/fgdata/$model; then |
add --search and --mp-list o...
|
236 |
installed_model[${${(s:/:)model}[2]}]=1 |
separation AI/real models, a...
|
237 |
elif test -r $FGDIR/source/fgdata/AI/$model; then |
238 |
installed_model[*${${(s:/:)model}[2]}]=1 |
|
239 |
elif test -n "$(command -v sqlite3)" -a -r $FGADDON/fgaddon.db; then |
|
add --search and --mp-list o...
|
240 |
ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select printf("%s/%s", aircrafts.name, setxml.file) |
241 |
from aircrafts |
|
242 |
inner join setxml |
|
243 |
where aircrafts.id = setxml.variantof |
|
244 |
and setxml.`/sim/model/path` = "'$model'" |
|
245 |
limit 1') |
|
246 |
if test -n "$ac_name"; then |
|
247 |
fgaddon_model[${ac_name}]=1 |
|
248 |
else |
|
249 |
unknown_model[${model}]=1 |
|
250 |
fi |
|
separation AI/real models, a...
|
251 |
else |
252 |
unknown_model[${model}]=1 |
|
add --search and --mp-list o...
|
253 |
fi |
254 |
done |
|
255 |
if test ${#installed_model[@]} -gt 0; then |
|
improve output
|
256 |
echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist |
improve mplist output
|
257 |
echo -e "${#installed_model[@]} models installed (*AI model only):\n$(column -c$(tput cols) $mplist)\n" |
add --search and --mp-list o...
|
258 |
fi |
259 |
if test ${#fgaddon_model[@]} -gt 0; then |
|
improve output
|
260 |
echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist |
improve mplist output
|
261 |
echo -e "${#fgaddon_model[@]} models available in FGADDON:\n$(column -c$(tput cols) $mplist)\n" |
add --search and --mp-list o...
|
262 |
fi |
263 |
if test ${#unknown_model[@]} -gt 0; then |
|
improve output
|
264 |
echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist |
improve mplist output
|
265 |
echo -e "${#unknown_model[@]} unknown models:\n$(column -c$(tput cols) $mplist)" |
add --search and --mp-list o...
|
266 |
fi |
267 |
unset installed_model unknown_model fgaddon_model |
|
268 |
rm $mplist |
|
269 |
return |
|
270 |
;; |
|
ajout fonction pour lancemen...
|
271 |
*) |
272 |
fgfs_args+=($fgfs_arg);; |
|
273 |
esac |
|
274 |
fi |
|
275 |
done |
|
276 |
unset fgfs_arg |
|
ajout trace de vol
|
277 |
if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then |
ajout trace de vol (2)
|
278 |
fgfs_args+=(--igc=file,out,1,$(date +%Y%m%d-%H%M-${${${fgfs_args[(r)--aircraft=*]}#--aircraft=}:-$(sed -rn 's|^.+aircraft>(.+)</aircraft.+$|\1|p' $FGDIR/source/fgdata/defaults.xml)}.igc)) |
ajout trace de vol
|
279 |
fi |
280 | ||
fix multiple instances on LD...
|
281 |
ld_library_path |
ajout fonction pour lancemen...
|
282 | |
283 |
echo ${fgfs_args[@]} |
|
284 |
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ? |
|
285 |
primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]} |
|
286 |
|
|
287 |
if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then |
|
288 |
fusermount -u $HOME/.fgfs/terrafs.d |
|
289 |
fi |
|
290 |
unset fgfs_args |
|
291 |
} |