config / .fgfs / fgfs_function /
Newer Older
188 lines | 8.396kb
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 () {
fix multiple instances on LD...
Sébastien MARQUE authored on 2020-07-01
67
        IFS_=$IFS
68
        IFS=$'\n'
69
        for lib in $(ls -d $FGDIR/install/*/lib); do
70
            egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
71
        done
72
        IFS=$IFS_
73
        export LD_LIBRARY_PATH
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
74
    }
75
    local aircrafts="$FGADDON/Aircraft"
76
    local fgfs_args=("--fg-root=$FGDIR/source/fgdata")
77
    local aircraft=
78
    local airport=
79
    if [[ -o BASH_REMATCH ]]; then
80
        local bash_rematch_set=1
81
    fi
82

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

            
90
############ APPAREIL DANS FGDIR/source/fgdata ?
91
            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
92
                fgfs_args+=("--aircraft=$fgfs_arg")
93
                fgfs_args+=("--aircraft-dir=$official_aircraft")
94
                unset official_aircraft
95

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

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

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

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

            
126
                local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}"
127
                if [[ -a "${airport_data}.threshold.xml" ]]; then
128
                    fgfs_args+=(--airport=$candidate_airport)
129
                    if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then
130
                        if test $candidate_parking = '?'; then
131
                          echo "Parkings ${candidate_airport:u}:"
132
                          sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml
133
                          return
134
                        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
135
                            fgfs_args+=("--parkpos='$candidate_parking'")
ajout fonction pour lancemen...
Sébastien MARQUE authored on 2020-04-16
136
                        fi
137
                    elif test -n "$candidate_runway"; then
138
                        if test $candidate_runway = '?'; then
139
                            echo "Runways ${candidate_airport:u}:"
140
                            sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml
141
                            return
142
                        elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then
143
                            fgfs_args+=("--runway=$candidate_runway")
144
                        fi
145
                    fi
146
                fi
147
            fi
148

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

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

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