scripts / flightgear / fgfs_function /
Newer Older
585 lines | 31.924kb
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")
option --callsign déterminée...
Sébastien MARQUE authored on 2022-06-02
175
                if test -n "$(ls -rt1 $HOME/.fgfs/autosave_*.xml | tail -1)"; then
176
                    callsign=$(sed -rn 's/^.*<callsign.*>(.+)<.callsign>.*$/\1/p' $(ls -rt1 $HOME/.fgfs/autosave_*.xml | tail -1))
177
                fi
178
                if test -n "$callsign"; then
179
                    fgfs_args+=("--callsign=$callsign")
180
                fi
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
181
                test -z "$bash_rematch_set" && set +o BASH_REMATCH
182

            
183
############ DEMANDE DE TRACE DE VOL ?
184
            elif [[ $fgfs_arg == "log" ]]; then
185
                # option construite plus tard avec nom de l'appareil
186
                local log_requested=1
187

            
188
############ AEROPORT ?
189
            else 
190
                local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
191
                local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
192
                local candidate_runway=${fgfs_arg#*+};  [[ $candidate_runway  == $fgfs_arg ]] && unset candidate_runway
193
                local terrafs=${candidate_airport#-}
194

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

            
207
                local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
208
                if ! test -r "${airport_data}.threshold.xml"; then
209
                    echo "airport ${candidate_airport:u} not found !"
210
                fi
211

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

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

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

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

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

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

            
435
                        elif test -n "$(command -v sqlite3)" -a -r $FGADDON/fgaddon.db; then
436
                            ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select     printf("%s/%s", aircrafts.name, setxml.file)
437
                                                                       from       aircrafts
438
                                                                       inner join setxml
439
                                                                       where      aircrafts.id = setxml.variantof
440
                                                                       and        setxml.`/sim/model/path` = "'${model% *}'"
441
                                                                       limit      1')
442
                            if test -n "$ac_name"; then
443
                                ((++fgaddon_model[${ac_name} ${model#* }]))
444
                            else
445
                                ((++unknown_model[${model}]))
446
                            fi
447

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

            
574
    ld_library_path
575

            
576
    fgfsrc=$HOME/.fgfs/fgfsrc
améliore l'affichage de la c...
Sébastien MARQUE authored on 2022-06-01
577
    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
578
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
579
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
580
    
581
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
582
        fusermount -u $HOME/.fgfs/terrafs.d
583
    fi
584
    unset fgfs_args
585
}