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 |
|
ajout fonction pour lancemen...
|
53 | |
code rearrangement
|
54 |
# TODO: prendre en compte les cas sans cmake |
55 |
if test -r $fgfs_source/$component/CMakeLists.txt; then |
|
56 |
local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component") |
|
57 |
test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific |
|
58 |
if test ${#previously_installed[@]} -gt 0; then |
|
59 |
cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}}) |
|
60 |
cmake_options+=(${(j. .)${:--DCMAKE_INCLUDE_PATH=$fgfs_install/${^previously_installed}/include}}) |
|
61 |
fi |
|
62 |
cmake_options+=("-j$simultaneous") |
|
ajout fonction pour lancemen...
|
63 | |
some cosmetics
|
64 |
title="*** ${component:u}${branch:+ [$branch]} ***" |
65 |
printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}" |
|
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 |
} |
|
fix return to path
|
79 | |
80 |
cd - > /dev/null |
|
code rearrangement
|
81 |
fi |
ajout fonction pour lancemen...
|
82 | |
83 |
previously_installed+=($component) |
|
84 |
done |
|
85 |
unset component |
|
86 |
;; |
|
87 |
esac |
|
88 |
} |
|
89 |
function ld_library_path () { |
|
smarter use of IFS
|
90 |
local IFS=$'\n' |
fix multiple instances on LD...
|
91 |
for lib in $(ls -d $FGDIR/install/*/lib); do |
92 |
egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" |
|
93 |
done |
|
94 |
export LD_LIBRARY_PATH |
|
ajout fonction pour lancemen...
|
95 |
} |
96 |
local aircrafts="$FGADDON/Aircraft" |
|
97 |
local fgfs_args=("--fg-root=$FGDIR/source/fgdata") |
|
98 |
local aircraft= |
|
99 |
local airport= |
|
100 |
if [[ -o BASH_REMATCH ]]; then |
|
101 |
local bash_rematch_set=1 |
|
102 |
fi |
|
103 | ||
104 |
for fgfs_arg in $@; do |
|
105 |
if test ${fgfs_arg#--} = ${fgfs_arg}; then |
|
106 |
############ APPAREIL DANS FGADDON ? |
|
107 |
if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then |
|
108 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
109 |
fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft") |
|
110 | ||
111 |
############ APPAREIL DANS FGDIR/source/fgdata ? |
|
112 |
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 |
|
113 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
114 |
fgfs_args+=("--aircraft-dir=$official_aircraft") |
|
115 |
unset official_aircraft |
|
116 | ||
ajout de gestion de bdd pour...
|
117 |
############ APPAREIL DANS FGADDON ? |
118 |
elif which sqlite3 > /dev/null 2>&1 \ |
|
119 |
&& test -r $FGADDON/fgaddon.db \ |
|
allow installation of aircra...
|
120 |
&& test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}'") -gt 0; then |
121 |
local PS3='which aircraft ? (Ctrl-D to quit) ' |
|
122 |
local IFS=$'\n' |
|
123 |
select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]', |
|
124 |
aircrafts.name, |
|
125 |
hangars.name, |
|
126 |
date(aircrafts.date, 'unixepoch')) |
|
127 |
from aircrafts |
|
128 |
inner join setxml, hangars |
|
129 |
where |
|
130 |
aircrafts.hangar = hangars.id |
|
131 |
and |
|
132 |
setxml.variantof = aircrafts.id |
|
133 |
and |
|
134 |
setxml.file = '${fgfs_arg}' |
|
135 |
order by aircrafts.date desc"); do |
|
136 |
test -z "$ac" && continue |
|
137 |
read -q "REPLY?download ${${(@s/ /)ac}[1]} ? (y/N) " |
|
138 |
if test -n "$REPLY" && test ${REPLY:l} = "y"; then |
|
139 |
declare -A hangar |
|
140 |
eval $(sqlite3 $FGADDON/fgaddon.db <<< "select printf('hangar[type]=%s;hangar[url]=%s;', type, url) |
|
141 |
from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'") |
|
142 |
case ${hangar[type]} in |
|
143 |
git) |
|
144 |
git -C $FGADDON/Aircraft clone https://github.com/FGMEMBERS/${${(@s/ /)ac}[1]}.git;; |
|
145 |
svn) |
|
146 |
svn checkout ${hangar[url]}/${${(@s/ /)ac}[1]} $FGADDON/Aircraft/${${(@s/ /)ac}[1]};; |
|
147 |
esac |
|
148 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
149 |
fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft") |
|
150 |
unset -v hangar |
|
151 |
else |
|
152 |
echo "falling back to default" |
|
153 |
fi |
|
154 |
break |
|
155 |
done |
|
ajout de gestion de bdd pour...
|
156 | |
ajout fonction pour lancemen...
|
157 |
############ SERVEUR MULTIPLAY ? |
158 |
elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then |
|
159 |
fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000") |
|
fix some fgfs options
|
160 |
fgfs_args+=("--callsign=f-zakh") |
ajout fonction pour lancemen...
|
161 |
test -z "$bash_rematch_set" && set +o BASH_REMATCH |
162 | ||
ajout trace de vol
|
163 |
############ DEMANDE DE TRACE DE VOL ? |
164 |
elif [[ $fgfs_arg == "log" ]]; then |
|
165 |
# option construite plus tard avec nom de l'appareil |
|
166 |
local log_requested=1 |
|
167 | ||
ajout fonction pour lancemen...
|
168 |
############ AEROPORT ? |
169 |
else |
|
170 |
local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*} |
|
171 |
local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking |
|
172 |
local candidate_runway=${fgfs_arg#*+}; [[ $candidate_runway == $fgfs_arg ]] && unset candidate_runway |
|
173 |
local terrafs=${candidate_airport#-} |
|
174 | ||
175 |
if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then |
|
176 |
candidate_airport=$terrafs |
|
177 |
$HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d |
|
178 |
fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d) |
|
179 |
fgfs_args+=(--disable-terrasync) |
|
180 |
local scenes_dir=$HOME/.fgfs/terrafs.d |
|
181 |
else |
|
182 |
fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync) |
|
183 |
fgfs_args+=(--enable-terrasync) |
|
184 |
local scenes_dir=$HOME/.fgfs/TerraSync |
|
185 |
fi |
|
186 | ||
187 |
local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}" |
|
188 |
if [[ -a "${airport_data}.threshold.xml" ]]; then |
|
189 |
fgfs_args+=(--airport=$candidate_airport) |
|
190 |
if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then |
|
191 |
if test $candidate_parking = '?'; then |
|
192 |
echo "Parkings ${candidate_airport:u}:" |
|
193 |
sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml |
|
194 |
return |
|
195 |
elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then |
|
fix some fgfs options
|
196 |
fgfs_args+=("--parkpos='$candidate_parking'") |
ajout fonction pour lancemen...
|
197 |
fi |
198 |
elif test -n "$candidate_runway"; then |
|
199 |
if test $candidate_runway = '?'; then |
|
200 |
echo "Runways ${candidate_airport:u}:" |
|
201 |
sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml |
|
202 |
return |
|
203 |
elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then |
|
204 |
fgfs_args+=("--runway=$candidate_runway") |
|
205 |
fi |
|
206 |
fi |
|
207 |
fi |
|
208 |
fi |
|
209 | ||
210 |
######## AUTRE OPTION |
|
211 |
else |
|
212 |
case $fgfs_arg in |
|
code rearrangement
|
213 |
--update(-data|-source|-build|)) |
214 |
if test -z "$2" || test ! -r $fgfs_source/.$2; then |
|
215 |
echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>" |
|
216 |
echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.} |
|
217 |
return 1 |
|
218 |
fi |
|
219 |
for component in $(<$fgfs_source/.$2); do |
|
220 |
if ! test -d $fgfs_source/$component; then |
|
221 |
echo component $component not found |
|
222 |
return 1 |
|
223 |
fi |
|
224 |
done |
|
225 |
typeset -A control_system_data=( |
|
226 |
git pull |
|
227 |
svn up |
|
228 |
) |
|
ajout fonction pour lancemen...
|
229 |
for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do |
make possible to compile dif...
|
230 |
update_fg $up ${2:-flightgear} |
ajout fonction pour lancemen...
|
231 |
done |
code rearrangement
|
232 |
unset control_system_data control_system update_command up |
233 |
return |
|
234 |
;; |
|
add RSS reader for FG code
|
235 |
--update-(fgaddon|check|rss)) |
code rearrangement
|
236 |
update_fg ${fgfs_arg#--update-} |
ajout fonction pour lancemen...
|
237 |
return |
238 |
;; |
|
239 |
--(show-aircraft|help)) |
|
ajout trace de vol
|
240 |
local -A complement=( |
ajout fonction pour lancemen...
|
241 |
--show-aircraft --fg-aircraft=$FGADDON/Aircraft |
242 |
--help --verbose |
|
243 |
) |
|
fix multiple instances on LD...
|
244 |
ld_library_path |
ajout fonction pour lancemen...
|
245 |
$FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager |
246 |
return |
|
247 |
;; |
|
add --show-thumbnail
|
248 |
--show-thumbnail) |
249 |
local PS3='which aircraft ? (Ctrl-D to quit) ' |
|
250 |
local IFS=$'\n' |
|
251 |
select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]', |
|
252 |
aircrafts.name, |
|
253 |
hangars.name, |
|
254 |
date(aircrafts.date, 'unixepoch')) |
|
255 |
from aircrafts |
|
256 |
inner join setxml, hangars |
|
257 |
where |
|
258 |
aircrafts.hangar = hangars.id |
|
259 |
and |
|
260 |
setxml.variantof = aircrafts.id |
|
261 |
and ( |
|
262 |
setxml.file like '%$2%' |
|
263 |
or |
|
264 |
aircrafts.name like '%$2%' |
|
265 |
) |
|
266 |
order by aircrafts.date desc"); do |
|
267 |
test -z "$ac" && continue |
|
268 |
local url=$(sqlite3 $FGADDON/fgaddon.db <<< "select printf('%s/${${(@s/ /)ac}[1]}', url) |
|
269 |
from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'") |
|
270 |
if test ${${(@s/ /)ac}[2]:1:-1} = 'FGMEMBERS'; then |
|
271 |
url="https://raw.githubusercontent.com/FGMEMBERS/${${(@s/ /)ac}[1]}/master" |
|
272 |
fi |
|
273 |
if wget --quiet --spider "$url/thumbnail.jpg"; then |
|
274 |
curl -s "$url/thumbnail.jpg" \ |
|
275 |
| convert - -resize '200%' -normalize -sharpen '0.0x1.0' - \ |
|
276 |
| display |
|
277 |
else |
|
278 |
echo "can't find or get thumbnail for ${${(@s/ /)ac}[1]} (${${(@s/ /)ac}[2]:1:-1}'s hangar)" |
|
279 |
fi |
|
280 |
done |
|
281 |
return |
|
282 |
;; |
|
add --search and --mp-list o...
|
283 |
--search) |
284 |
command -v sqlite3 > /dev/null || return |
|
some cosmetics
|
285 |
sqlite3 $FGADDON/fgaddon.db <<< "select printf('[%s, %s] %s (%s): %s ', |
286 |
hangars.name, |
|
287 |
date(aircrafts.date, 'unixepoch'), |
|
288 |
setxml.file, |
|
289 |
setxml.\`/sim/flight-model\`, |
|
290 |
setxml.\`/sim/description\`) |
|
291 |
from setxml |
|
292 |
inner join aircrafts, hangars |
|
293 |
where |
|
294 |
aircrafts.hangar = hangars.id |
|
295 |
and |
|
296 |
setxml.variantof = aircrafts.id |
|
297 |
and ( |
|
298 |
setxml.file like '%$2%' |
|
299 |
or |
|
300 |
aircrafts.name like '%$2%' |
|
301 |
) |
|
302 |
order by aircrafts.date desc" |
|
add --search and --mp-list o...
|
303 |
return |
304 |
;; |
|
305 |
--mp-list) |
|
306 |
local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX) |
|
307 |
declare -A installed_model fgaddon_model unknown_model |
|
308 |
local ac_name= |
|
309 |
telnet mpserver01.flightgear.org 5001 2>/dev/null > $mplist |
|
print number of online pilot...
|
310 |
grep 'pilot(s) online' $mplist |
311 |
echo |
|
show connected pilots for ea...
|
312 |
local IFS=$'\n' |
313 |
for model in $(awk '/@/{a[$NF]++}END{for (i in a) printf("%s (%i)\n", i, a[i])}' $mplist); do |
|
314 |
if test -r $FGADDON/${model% *} \ |
|
315 |
-o -r $FGDIR/source/fgdata/${model% *}; then |
|
316 | ||
317 |
((++installed_model[${${(s:/:)model}[2]} ${model#* }])) |
|
318 | ||
319 |
elif test -r $FGDIR/source/fgdata/AI/${model% *}; then |
|
320 | ||
321 |
((++installed_model[*${${(s:/:)model}[2]} ${model#* }])) |
|
322 | ||
separation AI/real models, a...
|
323 |
elif test -n "$(command -v sqlite3)" -a -r $FGADDON/fgaddon.db; then |
add --search and --mp-list o...
|
324 |
ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select printf("%s/%s", aircrafts.name, setxml.file) |
325 |
from aircrafts |
|
326 |
inner join setxml |
|
327 |
where aircrafts.id = setxml.variantof |
|
show connected pilots for ea...
|
328 |
and setxml.`/sim/model/path` = "'${model% *}'" |
add --search and --mp-list o...
|
329 |
limit 1') |
330 |
if test -n "$ac_name"; then |
|
show connected pilots for ea...
|
331 |
((++fgaddon_model[${ac_name} ${model#* }])) |
add --search and --mp-list o...
|
332 |
else |
show connected pilots for ea...
|
333 |
((++unknown_model[${model}])) |
add --search and --mp-list o...
|
334 |
fi |
show connected pilots for ea...
|
335 | |
separation AI/real models, a...
|
336 |
else |
show connected pilots for ea...
|
337 |
((++unknown_model[${model}])) |
add --search and --mp-list o...
|
338 |
fi |
339 |
done |
|
340 |
if test ${#installed_model[@]} -gt 0; then |
|
improve output
|
341 |
echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist |
improve mplist output
|
342 |
echo -e "${#installed_model[@]} models installed (*AI model only):\n$(column -c$(tput cols) $mplist)\n" |
add --search and --mp-list o...
|
343 |
fi |
344 |
if test ${#fgaddon_model[@]} -gt 0; then |
|
improve output
|
345 |
echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist |
improve mplist output
|
346 |
echo -e "${#fgaddon_model[@]} models available in FGADDON:\n$(column -c$(tput cols) $mplist)\n" |
add --search and --mp-list o...
|
347 |
fi |
348 |
if test ${#unknown_model[@]} -gt 0; then |
|
improve output
|
349 |
echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist |
improve mplist output
|
350 |
echo -e "${#unknown_model[@]} unknown models:\n$(column -c$(tput cols) $mplist)" |
add --search and --mp-list o...
|
351 |
fi |
352 |
unset installed_model unknown_model fgaddon_model |
|
353 |
rm $mplist |
|
354 |
return |
|
355 |
;; |
|
ajout fonction pour lancemen...
|
356 |
*) |
357 |
fgfs_args+=($fgfs_arg);; |
|
358 |
esac |
|
359 |
fi |
|
360 |
done |
|
361 |
unset fgfs_arg |
|
ajout trace de vol
|
362 |
if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then |
ajout trace de vol (2)
|
363 |
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
|
364 |
fi |
365 | ||
fix multiple instances on LD...
|
366 |
ld_library_path |
ajout fonction pour lancemen...
|
367 | |
improve options output
|
368 |
fgfsrc=$HOME/.fgfs/fgfsrc |
369 |
echo ${fgfs_args[@]//$HOME/\$HOME} $(test -r $fgfsrc && egrep -v '^\s*(#|$)' $fgfsrc | tr '\n' ' ') |
|
ajout fonction pour lancemen...
|
370 |
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ? |
371 |
primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]} |
|
372 |
|
|
373 |
if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then |
|
374 |
fusermount -u $HOME/.fgfs/terrafs.d |
|
375 |
fi |
|
376 |
unset fgfs_args |
|
377 |
} |