config / .fgfs / fgfs_function /
Newer Older
220 lines | 10.128kb
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"
74
                        return
75
                    }
76

            
77
                    previously_installed+=($component)
78
                    cd -
79
                done
80
                unset component
81
                ;;
82
        esac
83
    }
84
    function ld_library_path () {
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
85
        IFS_=$IFS
86
        IFS=$'\n'
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
        IFS=$IFS_
91
        export LD_LIBRARY_PATH
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
92
    }
93
    local aircrafts="$FGADDON/Aircraft"
94
    local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
95
    local aircraft=
96
    local airport=
97
    if [[ -o BASH_REMATCH ]]; then
98
        local bash_rematch_set=1
99
    fi
100

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

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

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

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

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

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

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

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

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

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

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