scripts / flightgear / fgfs_function /
Newer Older
569 lines | 30.613kb
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
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
            fgaddon)
just cosmetic
Sébastien MARQUE authored on 2021-12-19
12
                test -r $HOME/.fgfs/fgaddon && DB="$FGADDON/fgaddon.db" bash $HOME/.fgfs/fgaddon
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
13
                ;;
14
            check)
15
                test -r $HOME/.fgfs/jenkins-status && bash $HOME/.fgfs/jenkins-status
16
                ;;
17
            rss)
18
                test -r $HOME/.fgfs/fgcoderss && bash $HOME/.fgfs/fgcoderss
19
                ;;
20
            data)
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
30
                ;;
31
            source)
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
41
                done
42
                ;;
43
            build)
44
                local simultaneous=$(nproc)
45
                local previously_installed=()
46
                mkdir -p $fgfs_install
47
                for component in $(<$fgfs_source/.$2); do
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

            
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")
63

            
64
                        title="*** ${component:u}${branch:+ [$branch]} ***"
65
                        printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
66
                        mkdir -p $fgfs_build/$component
67
                        cd $fgfs_build/$component
68

            
69
                        echo cmake ${cmake_options[@]//$HOME/\$HOME} ${fgfs_source/#$HOME/\$HOME}/$component
70

            
71
                        cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
72
                        && make -j$simultaneous > /dev/null \
73
                        && {
74
                            make install | grep --color=always -v '^-- Up-to-date:'
75
                        } \
76
                        || {
77
                            echo "erreur construction $component"
78
                            cd $FGDIR
79
                            return
80
                        }
81

            
82
                        cd - > /dev/null
83
                    fi
84

            
85
                    previously_installed+=($component)
86
                done
87
                unset component
88
                ;;
89
        esac
90
    }
91
    function ld_library_path () {
fixe problème avec bibliothè...
Sébastien MARQUE authored on 2022-03-02
92
        for component in $(<$fgfs_source/.flightgear); do
93
            if test -d $fgfs_install/$component/lib; then
94
                lib="$fgfs_install/$component/lib"
95
                egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
96
            fi
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
97
        done
98
        export LD_LIBRARY_PATH
99
    }
améliore la vérification de ...
Sébastien MARQUE authored on 2022-06-01
100
    function check_fgaddon () {
101
        if ! test -r $FGADDON/fgaddon.db; then
102
            echo "aircraft DB not found at $FGADDON/fgaddon.db"
103
            echo "please run $0 --update-fgaddon"
104
            return 1
105
        fi
106
        if ! command -v sqlite3 > /dev/null; then
107
            which sqlite3
108
            return 1
109
        fi
110
    }
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
111
    local aircrafts="$FGADDON/Aircraft"
112
    local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
113
    local aircraft=
114
    local airport=
115
    if [[ -o BASH_REMATCH ]]; then
116
        local bash_rematch_set=1
117
    fi
118

            
119
    for fgfs_arg in $@; do
120
        if test ${fgfs_arg#--} = ${fgfs_arg}; then
121
############ APPAREIL DANS FGADDON ?
122
            if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then
123
                fgfs_args+=("--aircraft=$fgfs_arg")
124
                fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
125

            
126
############ APPAREIL DANS FGDIR/source/fgdata ?
127
            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
128
                fgfs_args+=("--aircraft=$fgfs_arg")
129
                fgfs_args+=("--aircraft-dir=$official_aircraft")
130
                unset official_aircraft
131

            
132
############ APPAREIL DISPONIBLE DANS UN HANGAR CONNU ?
133
            elif which sqlite3 > /dev/null 2>&1 \
134
            && test -r $FGADDON/fgaddon.db \
135
            && test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}'") -gt 0; then
136
                local PS3='which aircraft ? '
137
                local IFS=$'\n'
138
                select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]',
139
                                                               aircrafts.name,
140
                                                               hangars.name,
141
                                                               date(aircrafts.date, 'unixepoch'))
142
                                                 from aircrafts
143
                                                 inner join setxml, hangars
144
                                                 where
145
                                                   aircrafts.hangar = hangars.id
146
                                                 and
147
                                                   setxml.variantof = aircrafts.id
148
                                                 and
149
                                                     setxml.file = '${fgfs_arg}'
150
                                                 order by aircrafts.date desc"); do
151
                    test -z "$ac" && continue
152
                    read -q "REPLY?download ${${(@s/ /)ac}[1]} ? (y/N) "
153
                    if test -n "$REPLY" && test ${REPLY:l} = "y"; then
154
                        declare -A hangar
155
                        eval $(sqlite3 $FGADDON/fgaddon.db <<< "select printf('hangar[type]=%s;hangar[url]=%s;', type, url)
156
                                                                from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
157
                        case ${hangar[type]} in
158
                            git)
159
                                git -C $FGADDON/Aircraft clone ${hangar[url]}/${${(@s/ /)ac}[1]}.git;;
160
                            svn)
161
                                svn checkout ${hangar[url]}/${${(@s/ /)ac}[1]} $FGADDON/Aircraft/${${(@s/ /)ac}[1]};;
162
                        esac
163
                        fgfs_args+=("--aircraft=$fgfs_arg")
164
                        fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
165
                        unset -v hangar
166
                    else
167
                        echo "falling back to default"
168
                    fi
169
                    break
170
                done
171

            
172
############ SERVEUR MULTIPLAY ?
173
            elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then
174
                fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000")
175
                fgfs_args+=("--callsign=f-zakh")
176
                test -z "$bash_rematch_set" && set +o BASH_REMATCH
177

            
178
############ DEMANDE DE TRACE DE VOL ?
179
            elif [[ $fgfs_arg == "log" ]]; then
180
                # option construite plus tard avec nom de l'appareil
181
                local log_requested=1
182

            
183
############ AEROPORT ?
184
            else 
185
                local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
186
                local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
187
                local candidate_runway=${fgfs_arg#*+};  [[ $candidate_runway  == $fgfs_arg ]] && unset candidate_runway
188
                local terrafs=${candidate_airport#-}
189

            
190
                if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then
191
                    candidate_airport=$terrafs
192
                    $HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d
193
                    fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d)
194
                    fgfs_args+=(--disable-terrasync)
195
                    local scenes_dir=$HOME/.fgfs/terrafs.d
196
                else
197
                    fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync)
198
                    fgfs_args+=(--enable-terrasync)
199
                    local scenes_dir=$HOME/.fgfs/TerraSync
200
                fi
201

            
202
                local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
203
                if ! test -r "${airport_data}.threshold.xml"; then
204
                    echo "airport ${candidate_airport:u} not found !"
205
                fi
206

            
207
                if test -n "$candidate_parking" && test "$candidate_parking" = '?'; then
208
                    if test -r "${airport_data}.groundnet.xml"; then
209
                        echo "Parkings ${candidate_airport:u}:"
210
                        sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" "${airport_data}.groundnet.xml"
211
                    else
212
                        echo "no information for parkings available on ${candidate_airport:u}"
213
                    fi
214
                    return
215
                elif test -n "$candidate_runway" && test "$candidate_runway" = '?'; then
216
                    if test -r "${airport_data}.threshold.xml"; then
217
                        echo "Runways ${candidate_airport:u}:"
218
                        sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' "${airport_data}.threshold.xml"
219
                    else
220
                        echo "no information for runways available on ${candidate_airport:u}"
221
                    fi
222
                    return
223
                fi
224

            
225
                if test -r "${airport_data}.threshold.xml"; then
226
                    fgfs_args+=(--airport=$candidate_airport)
227
                    if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then
228
                        if sed -rn "/<parkingList/,/parkingList>/p" "${airport_data}.groundnet.xml" | grep -q "name=\"${candidate_parking}\""; then
229
                            fgfs_args+=("--parkpos='$candidate_parking'")
230
                        else
231
                            echo "$candidate_parking isn't a valid parking position"
232
                        fi
233
                    elif test -n "$candidate_runway"; then
234
                        if grep -q "<rwy>${candidate_runway}</rwy>" "${airport_data}.threshold.xml"; then
235
                            fgfs_args+=("--runway=$candidate_runway")
236
                        else
237
                            echo "$candidate_runway isn't a valid runway"
238
                        fi
239
                    fi
240
                fi
241
            fi
242

            
243
######## AUTRE OPTION
244
        else
245
            case $fgfs_arg in
246
                --update(-data|-source|-build|))
247
                    if test ! -r $fgfs_source/.${2:-flightgear}; then
248
                        echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>"
249
                        echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.}
250
                        return 1
251
                    fi
252
                    for component in $(<$fgfs_source/.${2:-flightgear}); do
253
                        if ! test -d $fgfs_source/$component; then
254
                            echo component $component not found
255
                            return 1
256
                        fi
257
                    done
258
                    typeset -A control_system_data=(
259
                        git pull
260
                        svn up
261
                    )
262
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
263
                        update_fg $up ${2:-flightgear}
264
                    done
265
                    unset control_system_data control_system update_command up
266
                    return
267
                    ;;
268
                --update-(fgaddon|check|rss))
269
                    update_fg ${fgfs_arg#--update-}
270
                    return
271
                    ;;
272
                --(show-aircraft|help))
273
                    local -A complement=(
274
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
275
                        --help          --verbose
276
                    )
277
                    ld_library_path
278
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
279
                    return
280
                    ;;
281
                --info)
améliore la vérification de ...
Sébastien MARQUE authored on 2022-06-01
282
                    check_fgaddon || return 1
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
283
                    local IFS=$'\n'
284
                    function _info () {
285
                        local _info=$(sqlite3 $FGADDON/fgaddon.db <<< "select \`$1\`
286
                                                     from setxml
287
                                                     inner join aircrafts, hangars
288
                                                     where
289
                                                       aircrafts.hangar = hangars.id
290
                                                     and
291
                                                       setxml.variantof = aircrafts.id
292
                                                     and
293
                                                       setxml.file = '$file'
294
                                                     and
295
                                                       hangars.name = '${${(@s/ /)ac}[2]:1:-1}'")
296
                        if test -n "$_info"; then
297
                            printf "%s: %s\n" "$2" "$_info"
298
                        fi
299
                    }
improve aircraft selection f...
Sébastien MARQUE authored on 2022-01-16
300
                    local ac_list=($(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]',
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
301
                                                                   aircrafts.name,
302
                                                                   hangars.name,
303
                                                                   date(aircrafts.date, 'unixepoch'))
304
                                                     from aircrafts
305
                                                     inner join setxml, hangars
306
                                                     where
307
                                                       aircrafts.hangar = hangars.id
308
                                                     and
309
                                                       setxml.variantof = aircrafts.id
310
                                                     and
311
                                                         setxml.file = '$2'
improve aircraft selection f...
Sébastien MARQUE authored on 2022-01-16
312
                                                     order by aircrafts.date desc"))
313
                    if test ${#ac_list[@]} -gt 1; then
314
                        local PS3='which aircraft ? '
315
                        select ac in ${ac_list[@]}; do
316
                            test -z "$ac" && continue
317
                            break
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
318
                        done
improve aircraft selection f...
Sébastien MARQUE authored on 2022-01-16
319
                    elif test ${#ac_list[@]} -eq 1; then
320
                        ac=${ac_list[1]}
321
                    else
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
322
                        return
improve aircraft selection f...
Sébastien MARQUE authored on 2022-01-16
323
                    fi
324
                    local file=$2
325
                    _info /sim/description      "Short description"
326
                    _info /sim/long-description "Long description"
327
                    _info /sim/author           "Author(s)"
328
                    _info /sim/flight-model     "Flight model"
329
                    _info /sim/type             "Type"
330
                    echo Ratings
331
                    for r in FDM systems cockpit model; do
332
                        _info /sim/rating/$r "  $r"
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
333
                    done
334
                    return
335
                    ;;
336
                --show-thumbnail)
améliore la vérification de ...
Sébastien MARQUE authored on 2022-06-01
337
                    check_fgaddon || return 1
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
338
                    local PS3='which aircraft ? '
339
                    local IFS=$'\n'
improve aircraft selection f...
Sébastien MARQUE authored on 2022-01-16
340
                    local ac_list=($(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]',
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
341
                                                                   aircrafts.name,
342
                                                                   hangars.name,
343
                                                                   date(aircrafts.date, 'unixepoch'))
344
                                                     from aircrafts
345
                                                     inner join setxml, hangars
346
                                                     where
347
                                                       aircrafts.hangar = hangars.id
348
                                                     and
349
                                                       setxml.variantof = aircrafts.id
350
                                                     and (
351
                                                         setxml.file like '%$2%'
352
                                                       or
353
                                                         aircrafts.name like '%$2%'
354
                                                     )
improve aircraft selection f...
Sébastien MARQUE authored on 2022-01-16
355
                                                     order by aircrafts.date desc"))
356
                    if test ${#ac_list[@]} -gt 1; then
357
                        local PS3='which aircraft ? '
358
                        select ac in ${ac_list[@]}; do
359
                            test -z "$ac" && continue
360
                            break
361
                        done
362
                    elif test ${#ac_list[@]} -eq 1; then
363
                        ac=${ac_list[1]}
364
                    else
365
                        return
366
                    fi
367
                    local url=$(sqlite3 $FGADDON/fgaddon.db <<< "select printf('%s/${${(@s/ /)ac}[1]}', url)
368
                                                                 from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
369
                    if test ${${(@s/ /)ac}[2]:1:-1} = 'FGMEMBERS'; then
370
                        url="https://raw.githubusercontent.com/FGMEMBERS/${${(@s/ /)ac}[1]}/master"
371
                    fi
372
                    if wget --quiet --spider "$url/thumbnail.jpg"; then
373
                        curl -s "$url/thumbnail.jpg" \
374
                        | convert - -resize '200%' -normalize -sharpen '0.0x1.0' - \
375
                        | display
376
                    else
377
                        echo "can't find or get thumbnail for ${${(@s/ /)ac}[1]} (${${(@s/ /)ac}[2]:1:-1}'s hangar)"
378
                    fi
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
379
                    return
380
                    ;;
381
                --search)
améliore la vérification de ...
Sébastien MARQUE authored on 2022-06-01
382
                    check_fgaddon || return 1
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
383
                    sqlite3 $FGADDON/fgaddon.db <<< "select printf('[%s, %s] %s (%s): %s ',
384
                                                                   hangars.name,
385
                                                                   date(aircrafts.date, 'unixepoch'),
386
                                                                   setxml.file,
387
                                                                   setxml.\`/sim/flight-model\`,
388
                                                                   setxml.\`/sim/description\`)
389
                                                     from setxml
390
                                                     inner join aircrafts, hangars
391
                                                     where
392
                                                       aircrafts.hangar = hangars.id
393
                                                     and
394
                                                       setxml.variantof = aircrafts.id
395
                                                     and (
396
                                                         setxml.file like '%$2%'
397
                                                       or
398
                                                         aircrafts.name like '%$2%'
399
                                                     )
400
                                                     order by aircrafts.date desc"
401
                    return
402
                    ;;
403
                --mp-list)
404
                    local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX)
405
                    declare -A installed_model fgaddon_model unknown_model
406
                    local ac_name=
ajoute la possibilité de cho...
Sébastien MARQUE authored on 2022-06-02
407
                    local MPSERVER=${MPSERVER:-mpserver01.flightgear.org}
408
                    local MPPORT=${MPPORT:-5001}
409
                    echo data from $MPSERVER:$MPPORT
410
                    telnet $MPSERVER $MPPORT 2>/dev/null > $mplist
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
411
                    grep 'pilot(s) online' $mplist
412
                    echo
413
                    local IFS=$'\n'
414
                    for model in $(awk '/@/{a[$NF]++}END{for (i in a) printf("%s (%i)\n", i, a[i])}' $mplist); do
415
                        if test -r $FGADDON/${model% *} \
416
                             -o -r $FGDIR/source/fgdata/${model% *}; then
417

            
418
                            ((++installed_model[${${(s:/:)model}[2]} ${model#* }]))
419

            
420
                        elif test -r $FGDIR/source/fgdata/AI/${model% *}; then
421

            
422
                            ((++installed_model[*${${(s:/:)model}[2]} ${model#* }]))
423

            
424
                        elif test -n "$(command -v sqlite3)" -a -r $FGADDON/fgaddon.db; then
425
                            ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select     printf("%s/%s", aircrafts.name, setxml.file)
426
                                                                       from       aircrafts
427
                                                                       inner join setxml
428
                                                                       where      aircrafts.id = setxml.variantof
429
                                                                       and        setxml.`/sim/model/path` = "'${model% *}'"
430
                                                                       limit      1')
431
                            if test -n "$ac_name"; then
432
                                ((++fgaddon_model[${ac_name} ${model#* }]))
433
                            else
434
                                ((++unknown_model[${model}]))
435
                            fi
436

            
437
                        else
438
                            ((++unknown_model[${model}]))
439
                        fi
440
                    done
441
                    if test ${#installed_model[@]} -gt 0; then
442
                        echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist
443
                        echo -e "${#installed_model[@]} models installed (*AI model only):\n$(column -c$(tput cols) $mplist)\n"
444
                    fi
445
                    if test ${#fgaddon_model[@]} -gt 0; then
446
                        echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist
447
                        echo -e "${#fgaddon_model[@]} models available in FGADDON:\n$(column -c$(tput cols) $mplist)\n"
448
                    fi
449
                    if test ${#unknown_model[@]} -gt 0; then
450
                        echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist
451
                        echo -e "${#unknown_model[@]} unknown models:\n$(column -c$(tput cols) $mplist)"
452
                    fi
453
                    unset installed_model unknown_model fgaddon_model
454
                    rm $mplist
455
                    return
456
                    ;;
457
                --install)
améliore la vérification de ...
Sébastien MARQUE authored on 2022-06-01
458
                    check_fgaddon || return 1
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
459
                    local PS3='which aircraft ? '
460
                    local IFS=$'\n'
461
                    select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]',
462
                                                                   aircrafts.name,
463
                                                                   hangars.name,
464
                                                                   date(aircrafts.date, 'unixepoch'))
465
                                                     from aircrafts
466
                                                     inner join setxml, hangars
467
                                                     where
468
                                                       aircrafts.hangar = hangars.id
469
                                                     and
470
                                                       setxml.variantof = aircrafts.id
471
                                                     and (
472
                                                         setxml.file like '%$2%'
473
                                                       or
474
                                                         aircrafts.name like '%$2%'
475
                                                     )
476
                                                     order by aircrafts.date desc"); do
477
                        test -z "$ac" && continue
478
                    done
479
                    test -z "$ac" && return
480
                    declare -A hangar
481
                    eval $(sqlite3 $FGADDON/fgaddon.db <<< "select printf('hangar[type]=%s;hangar[url]=%s;', type, url)
482
                                                            from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
483
                    case ${hangar[type]} in
484
                        git)
485
                            git -C $FGADDON/Aircraft clone ${hangar[url]}/${${(@s/ /)ac}[1]}.git;;
486
                        svn)
487
                            svn checkout ${hangar[url]}/${${(@s/ /)ac}[1]} $FGADDON/Aircraft/${${(@s/ /)ac}[1]};;
488
                    esac
489
                    unset hangar
490
                    return
491
                    ;;
améliore lancement mumble et...
Sébastien MARQUE authored on 2022-01-21
492
                --mumble)
493
                    if pgrep -u $USER mumble > /dev/null; then
494
                        echo "there is already a mumble instance launched"
495
                    else
496
                        mumble_desktop_entry=($(if test -n "$XDG_DATA_DIRS"; then find "${(s/:/)XDG_DATA_DIRS}" -type f,l -iname "*mumble*desktop"; fi))
497
                        if test ${#mumble_desktop_entry[@]} -gt 0; then
498
                            echo lauching ${mumble_desktop_entry[1]}
499
                            nohup gtk-launch ${mumble_desktop_entry[1]##*/} > /dev/null 2>&1 &
500
                        else
501
                            echo "no desktop entry found for mumble (XDG_DATA_DIRS=$XDG_DATA_DIRS)"
502
                            return 1
503
                        fi
504
                    fi
505
                    ;& # on continue avec l'addon fgcom
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
506
                --fgcom)
améliore lancement mumble et...
Sébastien MARQUE authored on 2022-01-21
507
                    if test -r $fgfs_source/fgcom-mumble/client/fgfs-addon/addon-metadata.xml; then
508
                        fgfs_args+=("--addon=$fgfs_source/fgcom-mumble/client/fgfs-addon")
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
509
                    else
améliore lancement mumble et...
Sébastien MARQUE authored on 2022-01-21
510
                        echo "can't find addon fgcom-mumble"
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
511
                        return 1
512
                    fi
513
                    ;;
514
                --map|--lnm)
meilleure gestion de fgconne...
Sébastien MARQUE authored on 2022-03-06
515
                    if ! pgrep -u $USER -f "python3 ./fgconnect.py" > /dev/null; then
remplacement de littlefgconn...
Sébastien MARQUE authored on 2022-01-16
516
                        if test -d $FGADDON/Addons/littlenavmap -a -x $fgfs_source/fgconnect/fgconnect.py; then
meilleure gestion de fgconne...
Sébastien MARQUE authored on 2022-03-06
517
                            ( cd $fgfs_source/fgconnect; python3 ./fgconnect.py -s )&
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
518
                        else
remplacement de littlefgconn...
Sébastien MARQUE authored on 2022-01-16
519
                            echo "can't find FGconnect or littlenavmap addon"
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
520
                            return 1
521
                        fi
522
                    else
remplacement de littlefgconn...
Sébastien MARQUE authored on 2022-01-16
523
                        echo "FGconnect already lauched"
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
524
                    fi
525
                    fgfs_args+=("--addon=$FGADDON/Addons/littlenavmap")
526
                    ;;
527
                --addon=*)
528
                    addon_path="${fgfs_arg#*=}"
529
                    if test -d "$addon_path"; then
530
                        fgfs_args+=("--addon=$addon_path")
531
                    elif test -d "$FGADDON/Addons/$addon_path"; then
532
                        fgfs_args+=("--addon=$FGADDON/Addons/$addon_path")
533
                    else
534
                        echo "can't find requested addon in $addon_path or $FGADDON/$addon_path !"
535
                    fi
536
                    ;;
537
                *)
améliore la vérification des...
Sébastien MARQUE authored on 2021-11-12
538
                    completion_source="$FGDIR/install/flightgear/share/zsh/site-functions/_fgfs"
539
                    if test -r "$completion_source"; then
540
                        if egrep --quiet "^\s*'${fgfs_arg%=*}=?\[" "$completion_source"; then
541
                            fgfs_args+=($fgfs_arg)
542
                        else
543
                            echo unknown option: ${fgfs_arg%=*}
544
                            return 1
545
                        fi
546
                    else
547
                        fgfs_args+=($fgfs_arg)
548
                    fi
549
                    ;;
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
550
            esac
551
        fi
552
    done
553
    unset fgfs_arg
554
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
555
        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))
556
    fi
557

            
558
    ld_library_path
559

            
560
    fgfsrc=$HOME/.fgfs/fgfsrc
améliore l'affichage de la c...
Sébastien MARQUE authored on 2022-06-01
561
    echo ${fgfs_args[@]//$HOME/\$HOME} $(test -r $fgfsrc && sed -r "/^\s*(#|$)/d;s|$HOME|\$HOME|" $fgfsrc | tr '\n' ' ')
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
562
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
563
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
564
    
565
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
566
        fusermount -u $HOME/.fgfs/terrafs.d
567
    fi
568
    unset fgfs_args
569
}