config / .fgfs / fgfs_function /
Newer Older
262 lines | 12.176kb
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
13
            ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
14
            data)
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
15
                typeset -A control_system_data=(
16
                    git pull
17
                    svn up
18
                )
19
                for control_system update_command in ${(kv)control_system_data}; do
20
                    find $FGADDON \
21
                        -maxdepth 3 \
22
                        -mindepth 1 \
23
                        -type d \
24
                        -name .${control_system} \
25
                        -printf "\n[ %h ]\n" \
26
                        -execdir ${control_system} ${update_command} \;
27
                done
28
                unset control_system_data control_system update_command
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
29
                ;;
30
            source)
31
                typeset -A control_system_data=(
32
                    git pull
33
                    svn up
34
                )
35
                for control_system update_command in ${(kv)control_system_data}; do
36
                    find $fgfs_source \
37
                        -maxdepth 2 \
38
                        -mindepth 1 \
39
                        -type d \
40
                        -name .${control_system} \
41
                        -printf "\n[ %h ]\n" \
42
                        -execdir ${control_system} ${update_command} \;
43
                done
44
                unset control_system_data control_system update_command
45
                ;;
add fgfs build status from J...
Sébastien MARQUE authored on 2020-08-25
46
            check)
47
                typeset -A revision builtstatus
48
                for component in simgear flightgear; do
49
                    cd $fgfs_source/$component
50
                    revision[$component]=$(git rev-parse HEAD)
51
                    cd - > /dev/null 2>&1
52
                done
53
                xmlgetnext () {
54
                   local IFS='>'
55
                   read -d '<' TAG VALUE
56
                }
57
                unset entryid
58
                wget -qO- http://build.flightgear.org:8080/job/fgfs/rssAll | while xmlgetnext; do
59
                    case "$TAG" in
60
                        "entry")
61
                            let entryid++
62
                            unset stable jenkins_id updated
63
                            ;;
64
                        "title")
65
                            test -n "$entryid" && stable=$(sed -r 's/^.*\((.+)\)/\1/' <<< "$VALUE")
66
                            ;;
67
                        "id")
68
                            test -n "$entryid" && jenkins_id="${VALUE##*:}"
69
                            ;;
70
                        "updated")
71
                            test -n "$entryid" && updated="$VALUE"
72
                            ;;
73
                        "/entry")
74
                            joburl=http://build.flightgear.org:8080/job/fgfs/$jenkins_id
75
                            regex='s|^.+<strong>Revision:</strong> (.+)$|\1|p'
76
                            if test "$(wget -qO- $joburl/git-2/ | sed -rn $regex)" = ${revision[simgear]} -a \
77
                                    "$(wget -qO- $joburl/git-3/ | sed -rn $regex)" = ${revision[flightgear]}; then
78
                                echo $(date +"$stable (#$jenkins_id, updated %d %B, %H:%M)" -d "$updated")
79
                                unset revision builtstatus entryid
80
                                return 0
81
                            elif test $entryid -eq 5; then
82
                                echo $(date +"no build info found (last %d %B, %H:%M)" -d "$updated")
83
                                unset revision builtstatus entryid
84
                                return 1
85
                            fi
86
                            ;;
87
                    esac
88
                done
89
                ;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
90
            build)
91
                local simultaneous=$(nproc)
92
                local previously_installed=()
93
                mkdir -p $fgfs_install
94

            
95
                for component in $(<$fgfs_source/ordre); do
96
# TODO: prendre en compte les cas sans cmake
97
                    title="*** $component:u ***"
98
                    printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
99

            
100
                    local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component")
101
                    [[ ${#previously_installed[@]} -gt 0 ]] \
102
                        && cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}})
103
                    cmake_options+=("-j$simultaneous")
104
                    test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific
105

            
106
                    mkdir -p $fgfs_build/$component
107
                    cd $fgfs_build/$component
108

            
109
                    echo cmake ${cmake_options[@]} $fgfs_source/$component
110
                    
less verbose build
Sébastien MARQUE authored on 2020-05-29
111
                    cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
112
                    && make -j$simultaneous > /dev/null \
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
113
                    && make install \
114
                    || {
115
                        echo "erreur construction $component"
116
                        return
117
                    }
118

            
119
                    previously_installed+=($component)
120
                    cd -
121
                done
122
                unset component
123
                ;;
124
        esac
125
    }
126
    function ld_library_path () {
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
127
        IFS_=$IFS
128
        IFS=$'\n'
129
        for lib in $(ls -d $FGDIR/install/*/lib); do
130
            egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
131
        done
132
        IFS=$IFS_
133
        export LD_LIBRARY_PATH
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
134
    }
135
    local aircrafts="$FGADDON/Aircraft"
136
    local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
137
    local aircraft=
138
    local airport=
139
    if [[ -o BASH_REMATCH ]]; then
140
        local bash_rematch_set=1
141
    fi
142

            
143
    for fgfs_arg in $@; do
144
        if test ${fgfs_arg#--} = ${fgfs_arg}; then
145
############ APPAREIL DANS FGADDON ?
146
            if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then
147
                fgfs_args+=("--aircraft=$fgfs_arg")
148
                fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
149

            
150
############ APPAREIL DANS FGDIR/source/fgdata ?
151
            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
152
                fgfs_args+=("--aircraft=$fgfs_arg")
153
                fgfs_args+=("--aircraft-dir=$official_aircraft")
154
                unset official_aircraft
155

            
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
156
############ APPAREIL DANS FGADDON ?
157
            elif which sqlite3 > /dev/null 2>&1 \
158
            && test -r $FGADDON/fgaddon.db \
remove -set.xml from filenam...
Sébastien MARQUE authored on 2020-09-02
159
            && 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
160
                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
161
                read -q "REPLY?download $model ? (y/N) "
162
                if test -n "$REPLY" && test ${REPLY:l} = "y"; then
163
                    svn co https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft/$model $FGADDON/Aircraft/$model
164
                    fgfs_args+=("--aircraft=$fgfs_arg")
165
                else
166
                    echo "aircraft $fgfs_arg isn't installed"
167
                    return
168
                fi
169

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

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

            
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
181
############ AEROPORT ?
182
            else 
183
                local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
184
                local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
185
                local candidate_runway=${fgfs_arg#*+};  [[ $candidate_runway  == $fgfs_arg ]] && unset candidate_runway
186
                local terrafs=${candidate_airport#-}
187

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

            
200
                local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
201
                if [[ -a "${airport_data}.threshold.xml" ]]; then
202
                    fgfs_args+=(--airport=$candidate_airport)
203
                    if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then
204
                        if test $candidate_parking = '?'; then
205
                          echo "Parkings ${candidate_airport:u}:"
206
                          sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml
207
                          return
208
                        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
209
                            fgfs_args+=("--parkpos='$candidate_parking'")
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
210
                        fi
211
                    elif test -n "$candidate_runway"; then
212
                        if test $candidate_runway = '?'; then
213
                            echo "Runways ${candidate_airport:u}:"
214
                            sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml
215
                            return
216
                        elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then
217
                            fgfs_args+=("--runway=$candidate_runway")
218
                        fi
219
                    fi
220
                fi
221
            fi
222

            
223
######## AUTRE OPTION
224
        else
225
            case $fgfs_arg in
add fgfs build status from J...
Sébastien MARQUE authored on 2020-08-25
226
                --update(-data|-source|-build|-fgaddon|-check|))
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
227
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
228
                        update_fg $up
229
                    done
230
                    unset up
231
                    return
232
                    ;;
233
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
234
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
235
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
236
                        --help          --verbose
237
                    )
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
238
                    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
239
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
240
                    return
241
                    ;;
242
                *)
243
                    fgfs_args+=($fgfs_arg);;
244
            esac
245
        fi
246
    done
247
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
248
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
249
        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
250
    fi
251

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

            
254
    echo ${fgfs_args[@]}
255
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
256
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
257
    
258
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
259
        fusermount -u $HOME/.fgfs/terrafs.d
260
    fi
261
    unset fgfs_args
262
}