config / .fgfs / fgfs_function /
Newer Older
351 lines | 18.612kb
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
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...
Sébastien MARQUE authored on 2020-08-24
11
            fgaddon)
12
                DB=$FGADDON/fgaddon.db $HOME/.fgfs/fgaddon
code rearrangement
Sébastien MARQUE authored on 2020-09-27
13
                ;;
14
            check)
15
                test -r $HOME/.fgfs/jenkins-status && bash $HOME/.fgfs/jenkins-status
16
                ;;
add RSS reader for FG code
Sébastien MARQUE authored on 2020-10-19
17
            rss)
18
                test -r $HOME/.fgfs/fgcoderss && bash $HOME/.fgfs/fgcoderss
19
                ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
20
            data)
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
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...
Sébastien MARQUE authored on 2020-04-16
30
                ;;
31
            source)
code rearrangement
Sébastien MARQUE authored on 2020-09-27
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...
Sébastien MARQUE authored on 2020-04-16
41
                done
42
                ;;
43
            build)
44
                local simultaneous=$(nproc)
45
                local previously_installed=()
46
                mkdir -p $fgfs_install
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
47
                for component in $(<$fgfs_source/.$2); do
code rearrangement
Sébastien MARQUE authored on 2020-09-27
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...
Sébastien MARQUE authored on 2020-04-16
53

            
code rearrangement
Sébastien MARQUE authored on 2020-09-27
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...
Sébastien MARQUE authored on 2020-04-16
63

            
some cosmetics
Sébastien MARQUE authored on 2020-11-07
64
                        title="*** ${component:u}${branch:+ [$branch]} ***"
65
                        printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
code rearrangement
Sébastien MARQUE authored on 2020-09-27
66
                        mkdir -p $fgfs_build/$component
67
                        cd $fgfs_build/$component
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
68

            
code rearrangement
Sébastien MARQUE authored on 2020-09-27
69
                        echo cmake ${cmake_options[@]} $fgfs_source/$component
70

            
71
                        cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
72
                        && make -j$simultaneous > /dev/null \
73
                        && make install \
74
                        || {
75
                            echo "erreur construction $component"
76
                            cd $FGDIR
77
                            return
78
                        }
fix return to path
Sébastien MARQUE authored on 2020-11-07
79

            
80
                        cd - > /dev/null
code rearrangement
Sébastien MARQUE authored on 2020-09-27
81
                    fi
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
82

            
83
                    previously_installed+=($component)
84
                done
85
                unset component
86
                ;;
87
        esac
88
    }
89
    function ld_library_path () {
smarter use of IFS
Sébastien MARQUE authored on 2020-09-23
90
        local IFS=$'\n'
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
91
        for lib in $(ls -d $FGDIR/install/*/lib); do
92
            egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
93
        done
94
        export LD_LIBRARY_PATH
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
95
    }
96
    local aircrafts="$FGADDON/Aircraft"
97
    local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
98
    local aircraft=
99
    local airport=
100
    if [[ -o BASH_REMATCH ]]; then
101
        local bash_rematch_set=1
102
    fi
103

            
104
    for fgfs_arg in $@; do
105
        if test ${fgfs_arg#--} = ${fgfs_arg}; then
106
############ APPAREIL DANS FGADDON ?
107
            if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then
108
                fgfs_args+=("--aircraft=$fgfs_arg")
109
                fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
110

            
111
############ APPAREIL DANS FGDIR/source/fgdata ?
112
            elif official_aircraft=$(find "$fgfs_source/fgdata/Aircraft" -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -printf "%h" -quit) && test -n "$official_aircraft"; then
113
                fgfs_args+=("--aircraft=$fgfs_arg")
114
                fgfs_args+=("--aircraft-dir=$official_aircraft")
115
                unset official_aircraft
116

            
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
117
############ APPAREIL DANS FGADDON ?
118
            elif which sqlite3 > /dev/null 2>&1 \
119
            && test -r $FGADDON/fgaddon.db \
remove -set.xml from filenam...
Sébastien MARQUE authored on 2020-09-02
120
            && test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}'") -eq 1; then
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
121
                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...
Sébastien MARQUE authored on 2020-08-24
122
                read -q "REPLY?download $model ? (y/N) "
123
                if test -n "$REPLY" && test ${REPLY:l} = "y"; then
124
                    svn co https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft/$model $FGADDON/Aircraft/$model
125
                    fgfs_args+=("--aircraft=$fgfs_arg")
fix won't start on freshly d...
Sébastien MARQUE authored on 2020-10-25
126
                    fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
127
                else
128
                    echo "aircraft $fgfs_arg isn't installed"
129
                    return
130
                fi
131

            
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
132
############ SERVEUR MULTIPLAY ?
133
            elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then
134
                fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000")
fix some fgfs options
Sébastien MARQUE authored on 2020-06-21
135
                fgfs_args+=("--callsign=f-zakh")
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
136
                test -z "$bash_rematch_set" && set +o BASH_REMATCH
137

            
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
138
############ DEMANDE DE TRACE DE VOL ?
139
            elif [[ $fgfs_arg == "log" ]]; then
140
                # option construite plus tard avec nom de l'appareil
141
                local log_requested=1
142

            
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
143
############ AEROPORT ?
144
            else 
145
                local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
146
                local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
147
                local candidate_runway=${fgfs_arg#*+};  [[ $candidate_runway  == $fgfs_arg ]] && unset candidate_runway
148
                local terrafs=${candidate_airport#-}
149

            
150
                if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then
151
                    candidate_airport=$terrafs
152
                    $HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d
153
                    fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d)
154
                    fgfs_args+=(--disable-terrasync)
155
                    local scenes_dir=$HOME/.fgfs/terrafs.d
156
                else
157
                    fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync)
158
                    fgfs_args+=(--enable-terrasync)
159
                    local scenes_dir=$HOME/.fgfs/TerraSync
160
                fi
161

            
162
                local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
163
                if [[ -a "${airport_data}.threshold.xml" ]]; then
164
                    fgfs_args+=(--airport=$candidate_airport)
165
                    if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then
166
                        if test $candidate_parking = '?'; then
167
                          echo "Parkings ${candidate_airport:u}:"
168
                          sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml
169
                          return
170
                        elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then
fix some fgfs options
Sébastien MARQUE authored on 2020-06-21
171
                            fgfs_args+=("--parkpos='$candidate_parking'")
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
172
                        fi
173
                    elif test -n "$candidate_runway"; then
174
                        if test $candidate_runway = '?'; then
175
                            echo "Runways ${candidate_airport:u}:"
176
                            sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml
177
                            return
178
                        elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then
179
                            fgfs_args+=("--runway=$candidate_runway")
180
                        fi
181
                    fi
182
                fi
183
            fi
184

            
185
######## AUTRE OPTION
186
        else
187
            case $fgfs_arg in
code rearrangement
Sébastien MARQUE authored on 2020-09-27
188
                --update(-data|-source|-build|))
189
                    if test -z "$2" || test ! -r $fgfs_source/.$2; then
190
                        echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>"
191
                        echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.}
192
                        return 1
193
                    fi
194
                    for component in $(<$fgfs_source/.$2); do
195
                        if ! test -d $fgfs_source/$component; then
196
                            echo component $component not found
197
                            return 1
198
                        fi
199
                    done
200
                    typeset -A control_system_data=(
201
                        git pull
202
                        svn up
203
                    )
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
204
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
205
                        update_fg $up ${2:-flightgear}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
206
                    done
code rearrangement
Sébastien MARQUE authored on 2020-09-27
207
                    unset control_system_data control_system update_command up
208
                    return
209
                    ;;
add RSS reader for FG code
Sébastien MARQUE authored on 2020-10-19
210
                --update-(fgaddon|check|rss))
code rearrangement
Sébastien MARQUE authored on 2020-09-27
211
                    update_fg ${fgfs_arg#--update-}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
212
                    return
213
                    ;;
214
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
215
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
216
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
217
                        --help          --verbose
218
                    )
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
219
                    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
220
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
221
                    return
222
                    ;;
add --show-thumbnail
Sébastien MARQUE authored on 2020-11-07
223
                --show-thumbnail)
224
                    local PS3='which aircraft ? (Ctrl-D to quit) '
225
                    local IFS=$'\n'
226
                    select ac in $(sqlite3 $FGADDON/fgaddon.db <<< "select distinct printf('%s [%s, %s]',
227
                                                                   aircrafts.name,
228
                                                                   hangars.name,
229
                                                                   date(aircrafts.date, 'unixepoch'))
230
                                                     from aircrafts
231
                                                     inner join setxml, hangars
232
                                                     where
233
                                                       aircrafts.hangar = hangars.id
234
                                                     and
235
                                                       setxml.variantof = aircrafts.id
236
                                                     and (
237
                                                         setxml.file like '%$2%'
238
                                                       or
239
                                                         aircrafts.name like '%$2%'
240
                                                     )
241
                                                     order by aircrafts.date desc"); do
242
                        test -z "$ac" && continue
243
                        local url=$(sqlite3 $FGADDON/fgaddon.db <<< "select printf('%s/${${(@s/ /)ac}[1]}', url)
244
                                                                     from hangars where name = '${${(@s/ /)ac}[2]:1:-1}'")
245
                        if test ${${(@s/ /)ac}[2]:1:-1} = 'FGMEMBERS'; then
246
                            url="https://raw.githubusercontent.com/FGMEMBERS/${${(@s/ /)ac}[1]}/master"
247
                        fi
248
                        if wget --quiet --spider "$url/thumbnail.jpg"; then
249
                            curl -s "$url/thumbnail.jpg" \
250
                            | convert - -resize '200%' -normalize -sharpen '0.0x1.0' - \
251
                            | display
252
                        else
253
                            echo "can't find or get thumbnail for ${${(@s/ /)ac}[1]} (${${(@s/ /)ac}[2]:1:-1}'s hangar)"
254
                        fi
255
                    done
256
                    return
257
                    ;;
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
258
                --search)
259
                    command -v sqlite3 > /dev/null || return
some cosmetics
Sébastien MARQUE authored on 2020-11-07
260
                    sqlite3 $FGADDON/fgaddon.db <<< "select printf('[%s, %s] %s (%s): %s ',
261
                                                                   hangars.name,
262
                                                                   date(aircrafts.date, 'unixepoch'),
263
                                                                   setxml.file,
264
                                                                   setxml.\`/sim/flight-model\`,
265
                                                                   setxml.\`/sim/description\`)
266
                                                     from setxml
267
                                                     inner join aircrafts, hangars
268
                                                     where
269
                                                       aircrafts.hangar = hangars.id
270
                                                     and
271
                                                       setxml.variantof = aircrafts.id
272
                                                     and (
273
                                                         setxml.file like '%$2%'
274
                                                       or
275
                                                         aircrafts.name like '%$2%'
276
                                                     )
277
                                                     order by aircrafts.date desc"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
278
                    return
279
                    ;;
280
                --mp-list)
281
                    local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX)
282
                    declare -A installed_model fgaddon_model unknown_model
283
                    local ac_name=
284
                    telnet mpserver01.flightgear.org 5001 2>/dev/null > $mplist
print number of online pilot...
Sébastien MARQUE authored on 2020-09-28
285
                    grep 'pilot(s) online' $mplist
286
                    echo
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
287
                    local IFS=$'\n'
288
                    for model in $(awk '/@/{a[$NF]++}END{for (i in a) printf("%s (%i)\n", i, a[i])}' $mplist); do
289
                        if test -r $FGADDON/${model% *} \
290
                             -o -r $FGDIR/source/fgdata/${model% *}; then
291

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

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

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

            
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
298
                        elif test -n "$(command -v sqlite3)" -a -r $FGADDON/fgaddon.db; then
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
299
                            ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select     printf("%s/%s", aircrafts.name, setxml.file)
300
                                                                       from       aircrafts
301
                                                                       inner join setxml
302
                                                                       where      aircrafts.id = setxml.variantof
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
303
                                                                       and        setxml.`/sim/model/path` = "'${model% *}'"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
304
                                                                       limit      1')
305
                            if test -n "$ac_name"; then
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
306
                                ((++fgaddon_model[${ac_name} ${model#* }]))
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
307
                            else
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
308
                                ((++unknown_model[${model}]))
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
309
                            fi
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
310

            
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
311
                        else
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
312
                            ((++unknown_model[${model}]))
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
313
                        fi
314
                    done
315
                    if test ${#installed_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
316
                        echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
317
                        echo -e "${#installed_model[@]} models installed (*AI model only):\n$(column -c$(tput cols) $mplist)\n"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
318
                    fi
319
                    if test ${#fgaddon_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
320
                        echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
321
                        echo -e "${#fgaddon_model[@]} models available in FGADDON:\n$(column -c$(tput cols) $mplist)\n"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
322
                    fi
323
                    if test ${#unknown_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
324
                        echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
325
                        echo -e "${#unknown_model[@]} unknown models:\n$(column -c$(tput cols) $mplist)"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
326
                    fi
327
                    unset installed_model unknown_model fgaddon_model
328
                    rm $mplist
329
                    return
330
                    ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
331
                *)
332
                    fgfs_args+=($fgfs_arg);;
333
            esac
334
        fi
335
    done
336
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
337
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
338
        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
Sébastien MARQUE authored on 2020-04-18
339
    fi
340

            
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
341
    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
342

            
343
    echo ${fgfs_args[@]}
344
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
345
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
346
    
347
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
348
        fusermount -u $HOME/.fgfs/terrafs.d
349
    fi
350
    unset fgfs_args
351
}