config / .fgfs / fgfs_function /
Newer Older
298 lines | 14.975kb
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
53
                    title="*** ${component:u}${branch:+ [$branch]} ***"
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
54
                    printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
55

            
code rearrangement
Sébastien MARQUE authored on 2020-09-27
56
# TODO: prendre en compte les cas sans cmake
57
                    if test -r $fgfs_source/$component/CMakeLists.txt; then
58
                        local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component")
59
                        test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific
60
                        if test ${#previously_installed[@]} -gt 0; then
61
                            cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}})
62
                            cmake_options+=(${(j. .)${:--DCMAKE_INCLUDE_PATH=$fgfs_install/${^previously_installed}/include}})
63
                        fi
64
                        cmake_options+=("-j$simultaneous")
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
65

            
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
                        }
79
                    fi
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
80

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

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

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

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

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

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

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

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

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

            
184
######## AUTRE OPTION
185
        else
186
            case $fgfs_arg in
code rearrangement
Sébastien MARQUE authored on 2020-09-27
187
                --update(-data|-source|-build|))
188
                    if test -z "$2" || test ! -r $fgfs_source/.$2; then
189
                        echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>"
190
                        echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.}
191
                        return 1
192
                    fi
193
                    for component in $(<$fgfs_source/.$2); do
194
                        if ! test -d $fgfs_source/$component; then
195
                            echo component $component not found
196
                            return 1
197
                        fi
198
                    done
199
                    typeset -A control_system_data=(
200
                        git pull
201
                        svn up
202
                    )
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
203
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
204
                        update_fg $up ${2:-flightgear}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
205
                    done
code rearrangement
Sébastien MARQUE authored on 2020-09-27
206
                    unset control_system_data control_system update_command up
207
                    return
208
                    ;;
add RSS reader for FG code
Sébastien MARQUE authored on 2020-10-19
209
                --update-(fgaddon|check|rss))
code rearrangement
Sébastien MARQUE authored on 2020-09-27
210
                    update_fg ${fgfs_arg#--update-}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
211
                    return
212
                    ;;
213
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
214
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
215
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
216
                        --help          --verbose
217
                    )
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
218
                    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
219
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
220
                    return
221
                    ;;
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
222
                --search)
223
                    command -v sqlite3 > /dev/null || return
show more info for search re...
Sébastien MARQUE authored on 2020-10-25
224
                    sqlite3 $FGADDON/fgaddon.db <<< "select printf('%s (%s): %s', file, \`/sim/flight-model\`, \`/sim/description\`) from setxml where file like '%$2%'"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
225
                    return
226
                    ;;
227
                --mp-list)
228
                    local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX)
229
                    declare -A installed_model fgaddon_model unknown_model
230
                    local ac_name=
231
                    telnet mpserver01.flightgear.org 5001 2>/dev/null > $mplist
print number of online pilot...
Sébastien MARQUE authored on 2020-09-28
232
                    grep 'pilot(s) online' $mplist
233
                    echo
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
234
                    local IFS=$'\n'
235
                    for model in $(awk '/@/{a[$NF]++}END{for (i in a) printf("%s (%i)\n", i, a[i])}' $mplist); do
236
                        if test -r $FGADDON/${model% *} \
237
                             -o -r $FGDIR/source/fgdata/${model% *}; then
238

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

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

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

            
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
245
                        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
246
                            ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select     printf("%s/%s", aircrafts.name, setxml.file)
247
                                                                       from       aircrafts
248
                                                                       inner join setxml
249
                                                                       where      aircrafts.id = setxml.variantof
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
250
                                                                       and        setxml.`/sim/model/path` = "'${model% *}'"
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
251
                                                                       limit      1')
252
                            if test -n "$ac_name"; then
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
253
                                ((++fgaddon_model[${ac_name} ${model#* }]))
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
254
                            else
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
255
                                ((++unknown_model[${model}]))
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
256
                            fi
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
257

            
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
258
                        else
show connected pilots for ea...
Sébastien MARQUE authored on 2020-10-25
259
                            ((++unknown_model[${model}]))
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
260
                        fi
261
                    done
262
                    if test ${#installed_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
263
                        echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
264
                        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
265
                    fi
266
                    if test ${#fgaddon_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
267
                        echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
268
                        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
269
                    fi
270
                    if test ${#unknown_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
271
                        echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
272
                        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
273
                    fi
274
                    unset installed_model unknown_model fgaddon_model
275
                    rm $mplist
276
                    return
277
                    ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
278
                *)
279
                    fgfs_args+=($fgfs_arg);;
280
            esac
281
        fi
282
    done
283
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
284
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
285
        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
286
    fi
287

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

            
290
    echo ${fgfs_args[@]}
291
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
292
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
293
    
294
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
295
        fusermount -u $HOME/.fgfs/terrafs.d
296
    fi
297
    unset fgfs_args
298
}