config / .fgfs / fgfs_function /
Newer Older
221 lines | 10.281kb
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)
better status check
Sébastien MARQUE authored on 2020-09-23
47
                test -r $HOME/.fgfs/jenkins-status && bash $HOME/.fgfs/jenkins-status;;
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
48
            build)
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
49
                test -r $fgfs_source/.$2 || return 1
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
50
                local simultaneous=$(nproc)
51
                local previously_installed=()
52
                mkdir -p $fgfs_install
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
53
                for component in $(<$fgfs_source/.$2); do
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
54
# TODO: prendre en compte les cas sans cmake
55
                    title="*** $component:u ***"
56
                    printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
57

            
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
add include path of previous...
Sébastien MARQUE authored on 2020-09-23
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

            
66
                    mkdir -p $fgfs_build/$component
67
                    cd $fgfs_build/$component
68

            
69
                    echo cmake ${cmake_options[@]} $fgfs_source/$component
70
                    
less verbose build
Sébastien MARQUE authored on 2020-05-29
71
                    cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
72
                    && make -j$simultaneous > /dev/null \
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
73
                    && make install \
74
                    || {
75
                        echo "erreur construction $component"
returns to the root path of ...
Sébastien MARQUE authored on 2020-09-23
76
                        cd $FGDIR
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
77
                        return
78
                    }
79

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

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

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

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

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

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

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

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

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

            
182
######## AUTRE OPTION
183
        else
184
            case $fgfs_arg in
add fgfs build status from J...
Sébastien MARQUE authored on 2020-08-25
185
                --update(-data|-source|-build|-fgaddon|-check|))
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
186
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
187
                        update_fg $up ${2:-flightgear}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
188
                    done
189
                    unset up
190
                    return
191
                    ;;
192
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
193
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
194
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
195
                        --help          --verbose
196
                    )
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
197
                    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
198
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
199
                    return
200
                    ;;
201
                *)
202
                    fgfs_args+=($fgfs_arg);;
203
            esac
204
        fi
205
    done
206
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
207
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
208
        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
209
    fi
210

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

            
213
    echo ${fgfs_args[@]}
214
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
215
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
216
    
217
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
218
        fusermount -u $HOME/.fgfs/terrafs.d
219
    fi
220
    unset fgfs_args
221
}