config / .fgfs / fgfs_function /
Newer Older
288 lines | 14.586kb
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
                ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
17
            data)
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
18
                for control_system update_command in ${(kv)control_system_data}; do
19
                    find $FGADDON \
20
                        -maxdepth 3 \
21
                        -mindepth 1 \
22
                        -type d \
23
                        -name .${control_system} \
24
                        -printf "\n[ %h ]\n" \
25
                        -execdir ${control_system} ${update_command} \;
26
                done
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
27
                ;;
28
            source)
code rearrangement
Sébastien MARQUE authored on 2020-09-27
29
                for component in $(<$fgfs_source/.$2); do
30
                    for control_system update_command in ${(kv)control_system_data}; do
31
                        find $fgfs_source/$component \
32
                            -maxdepth 1 \
33
                            -type d \
34
                            -name .${control_system} \
35
                            -printf "\n[ %h ]\n" \
36
                            -execdir ${control_system} ${update_command} \;
37
                    done
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
38
                done
39
                ;;
40
            build)
41
                local simultaneous=$(nproc)
42
                local previously_installed=()
43
                mkdir -p $fgfs_install
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
44
                for component in $(<$fgfs_source/.$2); do
code rearrangement
Sébastien MARQUE authored on 2020-09-27
45
                    if test -d $fgfs_source/$component/.git; then
46
                        local branch=$(git -C $fgfs_source/$component name-rev --name-only --no-undefined --always HEAD)
47
                    elif test -d $fgfs_source/${component}/.svn; then
48
                        local branch=${${(s:/:)$(svn info --show-item relative-url $fgfs_source/$component)}[2]}
49
                    fi
50
                    title="*** ${component:u}${branch:+ [$branch]} ***"
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
51
                    printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
52

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

            
code rearrangement
Sébastien MARQUE authored on 2020-09-27
63
                        mkdir -p $fgfs_build/$component
64
                        cd $fgfs_build/$component
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
65

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

            
68
                        cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
69
                        && make -j$simultaneous > /dev/null \
70
                        && make install \
71
                        || {
72
                            echo "erreur construction $component"
73
                            cd $FGDIR
74
                            return
75
                        }
76
                    fi
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
77

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

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

            
107
############ APPAREIL DANS FGDIR/source/fgdata ?
108
            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
109
                fgfs_args+=("--aircraft=$fgfs_arg")
110
                fgfs_args+=("--aircraft-dir=$official_aircraft")
111
                unset official_aircraft
112

            
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
113
############ APPAREIL DANS FGADDON ?
114
            elif which sqlite3 > /dev/null 2>&1 \
115
            && test -r $FGADDON/fgaddon.db \
remove -set.xml from filenam...
Sébastien MARQUE authored on 2020-09-02
116
            && 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
117
                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
118
                read -q "REPLY?download $model ? (y/N) "
119
                if test -n "$REPLY" && test ${REPLY:l} = "y"; then
120
                    svn co https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft/$model $FGADDON/Aircraft/$model
121
                    fgfs_args+=("--aircraft=$fgfs_arg")
122
                else
123
                    echo "aircraft $fgfs_arg isn't installed"
124
                    return
125
                fi
126

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

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

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

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

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

            
180
######## AUTRE OPTION
181
        else
182
            case $fgfs_arg in
code rearrangement
Sébastien MARQUE authored on 2020-09-27
183
                --update(-data|-source|-build|))
184
                    if test -z "$2" || test ! -r $fgfs_source/.$2; then
185
                        echo "${2:+unknown set $2\n}usage: --update|--update-data|--update-source|--update-build <set>"
186
                        echo "available sets :" ${$(find $fgfs_source -maxdepth 1 -type f -name ".*" -printf "%f ")//#.}
187
                        return 1
188
                    fi
189
                    for component in $(<$fgfs_source/.$2); do
190
                        if ! test -d $fgfs_source/$component; then
191
                            echo component $component not found
192
                            return 1
193
                        fi
194
                    done
195
                    typeset -A control_system_data=(
196
                        git pull
197
                        svn up
198
                    )
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
199
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
200
                        update_fg $up ${2:-flightgear}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
201
                    done
code rearrangement
Sébastien MARQUE authored on 2020-09-27
202
                    unset control_system_data control_system update_command up
203
                    return
204
                    ;;
205
                --update-(fgaddon|check))
206
                    update_fg ${fgfs_arg#--update-}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
207
                    return
208
                    ;;
209
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
210
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
211
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
212
                        --help          --verbose
213
                    )
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
214
                    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
215
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
216
                    return
217
                    ;;
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
218
                --search)
219
                    command -v sqlite3 > /dev/null || return
220
                    sqlite3 $FGADDON/fgaddon.db <<< "select file from setxml where file like '%$2%'"
221
                    return
222
                    ;;
223
                --mp-list)
224
                    local mplist=$(mktemp --dry-run /dev/shm/XXXXXXXXX)
225
                    declare -A installed_model fgaddon_model unknown_model
226
                    local ac_name=
227
                    telnet mpserver01.flightgear.org 5001 2>/dev/null > $mplist
print number of online pilot...
Sébastien MARQUE authored on 2020-09-28
228
                    grep 'pilot(s) online' $mplist
229
                    echo
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
230
                    for model in $(awk '/@/{a[$NF]++}END{for (i in a) print i}' $mplist); do
231
                        if test -r $FGADDON/$model \
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
232
                             -o -r $FGDIR/source/fgdata/$model; then
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
233
                            installed_model[${${(s:/:)model}[2]}]=1
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
234
                        elif test -r $FGDIR/source/fgdata/AI/$model; then
235
                            installed_model[*${${(s:/:)model}[2]}]=1
236
                        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
237
                            ac_name=$(sqlite3 $FGADDON/fgaddon.db <<< 'select     printf("%s/%s", aircrafts.name, setxml.file)
238
                                                                       from       aircrafts
239
                                                                       inner join setxml
240
                                                                       where      aircrafts.id = setxml.variantof
241
                                                                       and        setxml.`/sim/model/path` = "'$model'"
242
                                                                       limit      1')
243
                            if test -n "$ac_name"; then
244
                                fgaddon_model[${ac_name}]=1
245
                            else
246
                                unknown_model[${model}]=1
247
                            fi
separation AI/real models, a...
Sébastien MARQUE authored on 2020-09-28
248
                        else
249
                            unknown_model[${model}]=1
add --search and --mp-list o...
Sébastien MARQUE authored on 2020-09-27
250
                        fi
251
                    done
252
                    if test ${#installed_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
253
                        echo "${(j:\n:)${(Ok)installed_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
254
                        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
255
                    fi
256
                    if test ${#fgaddon_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
257
                        echo "${(j:\n:)${(Ok)fgaddon_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
258
                        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
259
                    fi
260
                    if test ${#unknown_model[@]} -gt 0; then
improve output
Sébastien MARQUE authored on 2020-09-27
261
                        echo "${(j:\n:)${(Ok)unknown_model[@]}}" > $mplist
improve mplist output
Sébastien MARQUE authored on 2020-10-19
262
                        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
263
                    fi
264
                    unset installed_model unknown_model fgaddon_model
265
                    rm $mplist
266
                    return
267
                    ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
268
                *)
269
                    fgfs_args+=($fgfs_arg);;
270
            esac
271
        fi
272
    done
273
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
274
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
275
        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
276
    fi
277

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

            
280
    echo ${fgfs_args[@]}
281
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
282
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
283
    
284
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
285
        fusermount -u $HOME/.fgfs/terrafs.d
286
    fi
287
    unset fgfs_args
288
}