config / .fgfs / fgfs_function /
Newer Older
183 lines | 8.377kb
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
11
            data)
12
                svn up $FGADDON
13
                ;;
14
            source)
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 $fgfs_source \
21
                        -maxdepth 2 \
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
29
                ;;
30
            build)
31
                local simultaneous=$(nproc)
32
                local previously_installed=()
33
                mkdir -p $fgfs_install
34

            
35
                for component in $(<$fgfs_source/ordre); do
36
# TODO: prendre en compte les cas sans cmake
37
                    title="*** $component:u ***"
38
                    printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}"
39

            
40
                    local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component")
41
                    [[ ${#previously_installed[@]} -gt 0 ]] \
42
                        && cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}})
43
                    cmake_options+=("-j$simultaneous")
44
                    test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific
45

            
46
                    mkdir -p $fgfs_build/$component
47
                    cd $fgfs_build/$component
48

            
49
                    echo cmake ${cmake_options[@]} $fgfs_source/$component
50
                    
less verbose build
Sébastien MARQUE authored on 2020-05-29
51
                    cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \
52
                    && make -j$simultaneous > /dev/null \
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
53
                    && make install \
54
                    || {
55
                        echo "erreur construction $component"
56
                        return
57
                    }
58

            
59
                    previously_installed+=($component)
60
                    cd -
61
                done
62
                unset component
63
                ;;
64
        esac
65
    }
66
    function ld_library_path () {
67
# TODO: prendre en compte les éventuels caractères gênants comme "espace" ou ":" dans $FGDIR
68
# TODO: ne pas surajouter si déjà présent dans LD_LIBRARY_PATH
69
        print ${(j,:,):-$(ls -d $FGDIR/install/*/lib)}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}
70
    }
71
    local aircrafts="$FGADDON/Aircraft"
72
    local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
73
    local aircraft=
74
    local airport=
75
    if [[ -o BASH_REMATCH ]]; then
76
        local bash_rematch_set=1
77
    fi
78

            
79
    for fgfs_arg in $@; do
80
        if test ${fgfs_arg#--} = ${fgfs_arg}; then
81
############ APPAREIL DANS FGADDON ?
82
            if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then
83
                fgfs_args+=("--aircraft=$fgfs_arg")
84
                fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft")
85

            
86
############ APPAREIL DANS FGDIR/source/fgdata ?
87
            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
88
                fgfs_args+=("--aircraft=$fgfs_arg")
89
                fgfs_args+=("--aircraft-dir=$official_aircraft")
90
                unset official_aircraft
91

            
92
############ SERVEUR MULTIPLAY ?
93
            elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then
94
                fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000")
95
                test -z "$bash_rematch_set" && set +o BASH_REMATCH
96

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

            
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
102
############ AEROPORT ?
103
            else 
104
                local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*}
105
                local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking
106
                local candidate_runway=${fgfs_arg#*+};  [[ $candidate_runway  == $fgfs_arg ]] && unset candidate_runway
107
                local terrafs=${candidate_airport#-}
108

            
109
                if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then
110
                    candidate_airport=$terrafs
111
                    $HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d
112
                    fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d)
113
                    fgfs_args+=(--disable-terrasync)
114
                    local scenes_dir=$HOME/.fgfs/terrafs.d
115
                else
116
                    fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync)
117
                    fgfs_args+=(--enable-terrasync)
118
                    local scenes_dir=$HOME/.fgfs/TerraSync
119
                fi
120

            
121
                local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
122
                if [[ -a "${airport_data}.threshold.xml" ]]; then
123
                    fgfs_args+=(--airport=$candidate_airport)
124
                    if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then
125
                        if test $candidate_parking = '?'; then
126
                          echo "Parkings ${candidate_airport:u}:"
127
                          sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml
128
                          return
129
                        elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then
130
                            fgfs_args+=("--parking-id='$candidate_parking'")
131
                        fi
132
                    elif test -n "$candidate_runway"; then
133
                        if test $candidate_runway = '?'; then
134
                            echo "Runways ${candidate_airport:u}:"
135
                            sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml
136
                            return
137
                        elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then
138
                            fgfs_args+=("--runway=$candidate_runway")
139
                        fi
140
                    fi
141
                fi
142
            fi
143

            
144
######## AUTRE OPTION
145
        else
146
            case $fgfs_arg in
147
                --update(-data|-source|-build|))
148
                    for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do
149
                        update_fg $up
150
                    done
151
                    unset up
152
                    return
153
                    ;;
154
                --(show-aircraft|help))
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
155
                    local -A complement=(
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
156
                        --show-aircraft --fg-aircraft=$FGADDON/Aircraft
157
                        --help          --verbose
158
                    )
159
                    export LD_LIBRARY_PATH=$(ld_library_path)
160
                    $FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager
161
                    return
162
                    ;;
163
                *)
164
                    fgfs_args+=($fgfs_arg);;
165
            esac
166
        fi
167
    done
168
    unset fgfs_arg
ajout trace de vol
Sébastien MARQUE authored on 2020-04-18
169
    if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then
ajout trace de vol (2)
Sébastien MARQUE authored on 2020-04-18
170
        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
171
    fi
172

            
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
173
    export LD_LIBRARY_PATH=$(ld_library_path)
174

            
175
    echo ${fgfs_args[@]}
176
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ?
177
    primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]}
178
    
179
    if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then
180
        fusermount -u $HOME/.fgfs/terrafs.d
181
    fi
182
    unset fgfs_args
183
}