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 |
} |
|
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") |
|
fix won't start on freshly d...
|
125 |
fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft") |
ajout de gestion de bdd pour...
|
126 |
else |
127 |
echo "aircraft $fgfs_arg isn't installed" |
|
128 |
return |
|
129 |
fi |
|
130 | ||
ajout fonction pour lancemen...
|
131 |
############ SERVEUR MULTIPLAY ? |
132 |
elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then |
|
133 |
fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000") |
|
fix some fgfs options
|
134 |
fgfs_args+=("--callsign=f-zakh") |
ajout fonction pour lancemen...
|
135 |
test -z "$bash_rematch_set" && set +o BASH_REMATCH |
136 | ||
ajout trace de vol
|
137 |
############ DEMANDE DE TRACE DE VOL ? |
138 |
elif [[ $fgfs_arg == "log" ]]; then |
|
139 |
# option construite plus tard avec nom de l'appareil |
|
140 |
local log_requested=1 |
|
141 | ||
ajout fonction pour lancemen...
|
142 |
############ AEROPORT ? |
143 |
else |
|
144 |
local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*} |
|
145 |
local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking |
|
146 |
local candidate_runway=${fgfs_arg#*+}; [[ $candidate_runway == $fgfs_arg ]] && unset candidate_runway |
|
147 |
local terrafs=${candidate_airport#-} |
|
148 | ||
149 |
if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then |
|
150 |
candidate_airport=$terrafs |
|
151 |
$HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d |
|
152 |
fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d) |
|
153 |
fgfs_args+=(--disable-terrasync) |
|
154 |
local scenes_dir=$HOME/.fgfs/terrafs.d |
|
155 |
else |
|
156 |
fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync) |
|
157 |
fgfs_args+=(--enable-terrasync) |
|
158 |
local scenes_dir=$HOME/.fgfs/TerraSync |
|
159 |
fi |
|
160 | ||
161 |
local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}" |
|
162 |
if [[ -a "${airport_data}.threshold.xml" ]]; then |
|
163 |
fgfs_args+=(--airport=$candidate_airport) |
|
164 |
if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then |
|
165 |
if test $candidate_parking = '?'; then |
|
166 |
echo "Parkings ${candidate_airport:u}:" |
|
167 |
sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml |
|
168 |
return |
|
169 |
elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then |
|
fix some fgfs options
|
170 |
fgfs_args+=("--parkpos='$candidate_parking'") |
ajout fonction pour lancemen...
|
171 |
fi |
172 |
elif test -n "$candidate_runway"; then |
|
173 |
if test $candidate_runway = '?'; then |
|
174 |
echo "Runways ${candidate_airport:u}:" |
|
175 |
sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml |
|
176 |
return |
|
177 |
elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then |
|
178 |
fgfs_args+=("--runway=$candidate_runway") |
|
179 |
fi |
|
180 |
fi |
|
181 |
fi |
|
182 |
fi |
|
183 | ||
184 |
######## AUTRE OPTION |
|
185 |
else |
|
186 |
case $fgfs_arg in |
|
code rearrangement
|
187 |
--update(-data|-source|-build|)) |
188 |
if test -z "$2" || test ! -r $fgfs_source/.$2; then |
|
189 |
echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>" |
|
190 |
echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.} |
|
191 |
return 1 |
|
192 |
fi |
|
193 |
for component in $(<$fgfs_source/.$2); do |
|
194 |
if ! test -d $fgfs_source/$component; then |
|
195 |
echo component $component not found |
|
196 |
return 1 |
|
197 |
fi |
|
198 |
done |
|
199 |
typeset -A control_system_data=( |
|
200 |
git pull |
|
201 |
svn up |
|
202 |
) |
|
ajout fonction pour lancemen...
|
203 |
for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do |
make possible to compile dif...
|
204 |
update_fg $up ${2:-flightgear} |
ajout fonction pour lancemen...
|
205 |
done |
code rearrangement
|
206 |
unset control_system_data control_system update_command up |
207 |
return |
|
208 |
;; |
|
add RSS reader for FG code
|
209 |
--update-(fgaddon|check|rss)) |
code rearrangement
|
210 |
update_fg ${fgfs_arg#--update-} |
ajout fonction pour lancemen...
|
211 |
return |
212 |
;; |
|
213 |
--(show-aircraft|help)) |
|
ajout trace de vol
|
214 |
local -A complement=( |
ajout fonction pour lancemen...
|
215 |
--show-aircraft --fg-aircraft=$FGADDON/Aircraft |
216 |
--help --verbose |
|
217 |
) |
|
fix multiple instances on LD...
|
218 |
ld_library_path |
ajout fonction pour lancemen...
|
219 |
$FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager |
220 |
return |
|
221 |
;; |
|
add --show-thumbnail
|
222 |
--show-thumbnail) |
223 |
local PS3='which aircraft ? (Ctrl-D to quit) ' |
|
224 |
local IFS=$'\n' |
|
225 |
select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]', |
|
226 |
aircrafts.name, |
|
227 |
hangars.name, |
|
228 |
date(aircrafts.date, 'unixepoch')) |
|
229 |
from aircrafts |
|
230 |
inner join setxml, hangars |
|
231 |
where |
|
232 |
aircrafts.hangar = hangars.id |
|
233 |
and |
|
234 |
setxml.variantof = aircrafts.id |
|
235 |
and ( |
|
236 |
setxml.file like '%$2%' |
|
237 |
or |
|
238 |
aircrafts.name like '%$2%' |
|
239 |
) |
|
240 |
order by aircrafts.date desc"); do |
|
241 |
test -z "$ac" && continue |
|
242 |
local url=$(sqlite3 $FGADDON/fgaddon.db <<< "select printf('%s/${${(@s/ /)ac}[1]}', url) |
|
243 |
from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'") |
|
244 |
if test ${${(@s/ /)ac}[2]:1:-1} = 'FGMEMBERS'; then |
|
245 |
url="https://raw.githubusercontent.com/FGMEMBERS/${${(@s/ /)ac}[1]}/master" |
|
246 |
fi |
|
247 |
if wget --quiet --spider "$url/thumbnail.jpg"; then |
|
248 |
curl -s "$url/thumbnail.jpg" \ |
|
249 |
| convert - -resize '200%' -normalize -sharpen '0.0x1.0' - \ |
|
250 |
| display |
|
251 |
else |
|
252 |
echo "can't find or get thumbnail for ${${(@s/ /)ac}[1]} (${${(@s/ /)ac}[2]:1:-1}'s hangar)" |
|
253 |
fi |
|
254 |
done |
|
255 |
return |
|
256 |
;; |
|
add --search and --mp-list o...
|
257 |
--search) |
258 |
command -v sqlite3 > /dev/null || return |
|
some cosmetics
|
259 |
sqlite3 $FGADDON/fgaddon.db <<< "select printf('[%s, %s] %s (%s): %s ', |
260 |
hangars.name, |
|
261 |
date(aircrafts.date, 'unixepoch'), |
|
262 |
setxml.file, |
|
263 |
setxml.\`/sim/flight-model\`, |
|
264 |
setxml.\`/sim/description\`) |
|
265 |
from setxml |
|
266 |
inner join aircrafts, hangars |
|
267 |
where |
|
268 |
aircrafts.hangar = hangars.id |
|
269 |
and |
|
270 |
setxml.variantof = aircrafts.id |
|
271 |
and ( |
|
272 |
setxml.file like '%$2%' |
|
273 |
or |
|
274 |
aircrafts.name like '%$2%' |
|
275 |
) |
|
276 |
order by aircrafts.date desc" |
|
add --search and --mp-list o...
|
277 |
return |
278 |
;; |
|
279 |
--mp-list) |
|
280 |
local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX) |
|
281 |
declare -A installed_model fgaddon_model unknown_model |
|
282 |
local ac_name= |
|
283 |
telnet mpserver01.flightgear.org 5001 2>/dev/null > $mplist |
|
print number of online pilot...
|
284 |
grep 'pilot(s) online' $mplist |
285 |
echo |
|
show connected pilots for ea...
|
286 |
local IFS=$'\n' |
287 |
for model in $(awk '/@/{a[$NF]++}END{for (i in a) printf("%s (%i)\n", i, a[i])}' $mplist); do |
|
288 |
if test -r $FGADDON/${model% *} \ |
|
289 |
-o -r $FGDIR/source/fgdata/${model% *}; then |
|
290 | ||
291 |
((++installed_model[${${(s:/:)model}[2]} ${model#* }])) |
|
292 | ||
293 |
elif test -r $FGDIR/source/fgdata/AI/${model% *}; then |
|
294 | ||
295 |
((++installed_model[*${${(s:/:)model}[2]} ${model#* }])) |
|
296 | ||
separation AI/real models, a...
|
297 |
elif test -n "$(command -v sqlite3)" -a -r $FGADDON/fgaddon.db; then |
add --search and --mp-list o...
|
298 |
ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select printf("%s/%s", aircrafts.name, setxml.file) |
299 |
from aircrafts |
|
300 |
inner join setxml |
|
301 |
where aircrafts.id = setxml.variantof |
|
show connected pilots for ea...
|
302 |
and setxml.`/sim/model/path` = "'${model% *}'" |
add --search and --mp-list o...
|
303 |
limit 1') |
304 |
if test -n "$ac_name"; then |
|
show connected pilots for ea...
|
305 |
((++fgaddon_model[${ac_name} ${model#* }])) |
add --search and --mp-list o...
|
306 |
else |
show connected pilots for ea...
|
307 |
((++unknown_model[${model}])) |
add --search and --mp-list o...
|
308 |
fi |
show connected pilots for ea...
|
309 | |
separation AI/real models, a...
|
310 |
else |
show connected pilots for ea...
|
311 |
((++unknown_model[${model}])) |
add --search and --mp-list o...
|
312 |
fi |
313 |
done |
|
314 |
if test ${#installed_model[@]} -gt 0; then |
|
improve output
|
315 |
echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist |
improve mplist output
|
316 |
echo -e "${#installed_model[@]} models installed (*AI model only):\n$(column -c$(tput cols) $mplist)\n" |
add --search and --mp-list o...
|
317 |
fi |
318 |
if test ${#fgaddon_model[@]} -gt 0; then |
|
improve output
|
319 |
echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist |
improve mplist output
|
320 |
echo -e "${#fgaddon_model[@]} models available in FGADDON:\n$(column -c$(tput cols) $mplist)\n" |
add --search and --mp-list o...
|
321 |
fi |
322 |
if test ${#unknown_model[@]} -gt 0; then |
|
improve output
|
323 |
echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist |
improve mplist output
|
324 |
echo -e "${#unknown_model[@]} unknown models:\n$(column -c$(tput cols) $mplist)" |
add --search and --mp-list o...
|
325 |
fi |
326 |
unset installed_model unknown_model fgaddon_model |
|
327 |
rm $mplist |
|
328 |
return |
|
329 |
;; |
|
ajout fonction pour lancemen...
|
330 |
*) |
331 |
fgfs_args+=($fgfs_arg);; |
|
332 |
esac |
|
333 |
fi |
|
334 |
done |
|
335 |
unset fgfs_arg |
|
ajout trace de vol
|
336 |
if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then |
ajout trace de vol (2)
|
337 |
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
|
338 |
fi |
339 | ||
fix multiple instances on LD...
|
340 |
ld_library_path |
ajout fonction pour lancemen...
|
341 | |
342 |
echo ${fgfs_args[@]} |
|
343 |
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ? |
|
344 |
primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]} |
|
345 |
|
|
346 |
if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then |
|
347 |
fusermount -u $HOME/.fgfs/terrafs.d |
|
348 |
fi |
|
349 |
unset fgfs_args |
|
350 |
} |