ajout fonction pour lancemen...
|
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...
|
11 |
fgaddon) |
12 |
DB=$FGADDON/fgaddon.db $HOME/.fgfs/fgaddon |
|
13 |
;; |
|
ajout fonction pour lancemen...
|
14 |
data) |
ajout de gestion de bdd pour...
|
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...
|
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 |
;; |
|
46 |
build) |
|
47 |
local simultaneous=$(nproc) |
|
48 |
local previously_installed=() |
|
49 |
mkdir -p $fgfs_install |
|
50 | ||
51 |
for component in $(<$fgfs_source/ordre); do |
|
52 |
# TODO: prendre en compte les cas sans cmake |
|
53 |
title="*** $component:u ***" |
|
54 |
printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}" |
|
55 | ||
56 |
local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component") |
|
57 |
[[ ${#previously_installed[@]} -gt 0 ]] \ |
|
58 |
&& cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}}) |
|
59 |
cmake_options+=("-j$simultaneous") |
|
60 |
test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific |
|
61 | ||
62 |
mkdir -p $fgfs_build/$component |
|
63 |
cd $fgfs_build/$component |
|
64 | ||
65 |
echo cmake ${cmake_options[@]} $fgfs_source/$component |
|
66 |
|
|
less verbose build
|
67 |
cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \ |
68 |
&& make -j$simultaneous > /dev/null \ |
|
ajout fonction pour lancemen...
|
69 |
&& make install \ |
70 |
|| { |
|
71 |
echo "erreur construction $component" |
|
72 |
return |
|
73 |
} |
|
74 | ||
75 |
previously_installed+=($component) |
|
76 |
cd - |
|
77 |
done |
|
78 |
unset component |
|
79 |
;; |
|
80 |
esac |
|
81 |
} |
|
82 |
function ld_library_path () { |
|
fix multiple instances on LD...
|
83 |
IFS_=$IFS |
84 |
IFS=$'\n' |
|
85 |
for lib in $(ls -d $FGDIR/install/*/lib); do |
|
86 |
egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" |
|
87 |
done |
|
88 |
IFS=$IFS_ |
|
89 |
export LD_LIBRARY_PATH |
|
ajout fonction pour lancemen...
|
90 |
} |
91 |
local aircrafts="$FGADDON/Aircraft" |
|
92 |
local fgfs_args=("--fg-root=$FGDIR/source/fgdata") |
|
93 |
local aircraft= |
|
94 |
local airport= |
|
95 |
if [[ -o BASH_REMATCH ]]; then |
|
96 |
local bash_rematch_set=1 |
|
97 |
fi |
|
98 | ||
99 |
for fgfs_arg in $@; do |
|
100 |
if test ${fgfs_arg#--} = ${fgfs_arg}; then |
|
101 |
############ APPAREIL DANS FGADDON ? |
|
102 |
if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then |
|
103 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
104 |
fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft") |
|
105 | ||
106 |
############ APPAREIL DANS FGDIR/source/fgdata ? |
|
107 |
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 |
|
108 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
109 |
fgfs_args+=("--aircraft-dir=$official_aircraft") |
|
110 |
unset official_aircraft |
|
111 | ||
ajout de gestion de bdd pour...
|
112 |
############ APPAREIL DANS FGADDON ? |
113 |
elif which sqlite3 > /dev/null 2>&1 \ |
|
114 |
&& test -r $FGADDON/fgaddon.db \ |
|
115 |
&& test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}-set.xml'") -eq 1; then |
|
116 |
model=$(sqlite3 $FGADDON/fgaddon.db <<< "select name from aircrafts inner join setxml on aircrafts.id = setxml.variantof where setxml.file is '${fgfs_arg}-set.xml'") |
|
117 |
read -q "REPLY?download $model ? (y/N) " |
|
118 |
read |
|
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...
|
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
|
130 |
fgfs_args+=("--callsign=f-zakh") |
ajout fonction pour lancemen...
|
131 |
test -z "$bash_rematch_set" && set +o BASH_REMATCH |
132 | ||
ajout trace de vol
|
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...
|
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
|
166 |
fgfs_args+=("--parkpos='$candidate_parking'") |
ajout fonction pour lancemen...
|
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 |
|
ajout de gestion de bdd pour...
|
183 |
--update(-data|-source|-build|-fgaddon|)) |
ajout fonction pour lancemen...
|
184 |
for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do |
185 |
update_fg $up |
|
186 |
done |
|
187 |
unset up |
|
188 |
return |
|
189 |
;; |
|
190 |
--(show-aircraft|help)) |
|
ajout trace de vol
|
191 |
local -A complement=( |
ajout fonction pour lancemen...
|
192 |
--show-aircraft --fg-aircraft=$FGADDON/Aircraft |
193 |
--help --verbose |
|
194 |
) |
|
fix multiple instances on LD...
|
195 |
ld_library_path |
ajout fonction pour lancemen...
|
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
|
205 |
if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then |
ajout trace de vol (2)
|
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
|
207 |
fi |
208 | ||
fix multiple instances on LD...
|
209 |
ld_library_path |
ajout fonction pour lancemen...
|
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 |
} |