config / .fgfs / fgfs_function /
Newer Older
219 lines | 10.132kb
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
                    [[ ${#previously_installed[@]} -gt 0 ]] \
60
                        && cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}})
61
                    cmake_options+=("-j$simultaneous")
62
                    test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific
63

            
64
                    mkdir -p $fgfs_build/$component
65
                    cd $fgfs_build/$component
66

            
67
                    echo cmake ${cmake_options[@]} $fgfs_source/$component
68
                    
less verbose build
Sébastien MARQUE authored on 2020-05-29
69
                    cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
70
                    && make -j$simultaneous > /dev/null \
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
71
                    && make install \
72
                    || {
73
                        echo "erreur construction $component"
returns to the root path of ...
Sébastien MARQUE authored on 2020-09-23
74
                        cd $FGDIR
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
75
                        return
76
                    }
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
add fgfs build status from J...
Sébastien MARQUE authored on 2020-08-25
183
                --update(-data|-source|-build|-fgaddon|-check|))
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
184
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
make possible to compile dif...
Sébastien MARQUE authored on 2020-09-23
185
                        update_fg $up ${2:-flightgear}
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
186
                    done
187
                    unset up
188
                    return
189
                    ;;
190
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
191
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
192
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
193
                        --help          --verbose
194
                    )
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
195
                    ld_library_path
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
196
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
197
                    return
198
                    ;;
199
                *)
200
                    fgfs_args+=($fgfs_arg);;
201
            esac
202
        fi
203
    done
204
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
205
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
206
        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
207
    fi
208

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

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