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 |
;; |
|
add fgfs build status from J...
|
46 |
check) |
47 |
typeset -A revision builtstatus |
|
48 |
for component in simgear flightgear; do |
|
49 |
cd $fgfs_source/$component |
|
50 |
revision[$component]=$(git rev-parse HEAD) |
|
51 |
cd - > /dev/null 2>&1 |
|
52 |
done |
|
53 |
xmlgetnext () { |
|
54 |
local IFS='>' |
|
55 |
read -d '<' TAG VALUE |
|
56 |
} |
|
57 |
unset entryid |
|
58 |
wget -qO- http://build.flightgear.org:8080/job/fgfs/rssAll | while xmlgetnext; do |
|
59 |
case "$TAG" in |
|
60 |
"entry") |
|
61 |
let entryid++ |
|
62 |
unset stable jenkins_id updated |
|
63 |
;; |
|
64 |
"title") |
|
65 |
test -n "$entryid" && stable=$(sed -r 's/^.*\((.+)\)/\1/' <<< "$VALUE") |
|
66 |
;; |
|
67 |
"id") |
|
68 |
test -n "$entryid" && jenkins_id="${VALUE##*:}" |
|
69 |
;; |
|
70 |
"updated") |
|
71 |
test -n "$entryid" && updated="$VALUE" |
|
72 |
;; |
|
73 |
"/entry") |
|
74 |
joburl=http://build.flightgear.org:8080/job/fgfs/$jenkins_id |
|
75 |
regex='s|^.+<strong>Revision:</strong> (.+)$|\1|p' |
|
76 |
if test "$(wget -qO- $joburl/git-2/ | sed -rn $regex)" = ${revision[simgear]} -a \ |
|
77 |
"$(wget -qO- $joburl/git-3/ | sed -rn $regex)" = ${revision[flightgear]}; then |
|
78 |
echo $(date +"$stable (#$jenkins_id, updated %d %B, %H:%M)" -d "$updated") |
|
79 |
unset revision builtstatus entryid |
|
80 |
return 0 |
|
81 |
elif test $entryid -eq 5; then |
|
82 |
echo $(date +"no build info found (last %d %B, %H:%M)" -d "$updated") |
|
83 |
unset revision builtstatus entryid |
|
84 |
return 1 |
|
85 |
fi |
|
86 |
;; |
|
87 |
esac |
|
88 |
done |
|
89 |
;; |
|
ajout fonction pour lancemen...
|
90 |
build) |
91 |
local simultaneous=$(nproc) |
|
92 |
local previously_installed=() |
|
93 |
mkdir -p $fgfs_install |
|
94 | ||
95 |
for component in $(<$fgfs_source/ordre); do |
|
96 |
# TODO: prendre en compte les cas sans cmake |
|
97 |
title="*** $component:u ***" |
|
98 |
printf "\n%s\n%s\n%s\n" "${(l:${#title}::*:)}" "$title" "${(l:${#title}::*:)}" |
|
99 | ||
100 |
local cmake_options=("-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=$fgfs_install/$component") |
|
101 |
[[ ${#previously_installed[@]} -gt 0 ]] \ |
|
102 |
&& cmake_options+=(${(j. .)${:--DCMAKE_PREFIX_PATH=$fgfs_install/${^previously_installed}}}) |
|
103 |
cmake_options+=("-j$simultaneous") |
|
104 |
test -e $fgfs_source/${component}.specific && source $fgfs_source/${component}.specific |
|
105 | ||
106 |
mkdir -p $fgfs_build/$component |
|
107 |
cd $fgfs_build/$component |
|
108 | ||
109 |
echo cmake ${cmake_options[@]} $fgfs_source/$component |
|
110 |
|
|
less verbose build
|
111 |
cmake ${cmake_options[@]} $fgfs_source/$component > /dev/null \ |
112 |
&& make -j$simultaneous > /dev/null \ |
|
ajout fonction pour lancemen...
|
113 |
&& make install \ |
114 |
|| { |
|
115 |
echo "erreur construction $component" |
|
116 |
return |
|
117 |
} |
|
118 | ||
119 |
previously_installed+=($component) |
|
120 |
cd - |
|
121 |
done |
|
122 |
unset component |
|
123 |
;; |
|
124 |
esac |
|
125 |
} |
|
126 |
function ld_library_path () { |
|
fix multiple instances on LD...
|
127 |
IFS_=$IFS |
128 |
IFS=$'\n' |
|
129 |
for lib in $(ls -d $FGDIR/install/*/lib); do |
|
130 |
egrep -q "(^|:)$lib(:|$)" <<< "${LD_LIBRARY_PATH}" || LD_LIBRARY_PATH="${lib}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" |
|
131 |
done |
|
132 |
IFS=$IFS_ |
|
133 |
export LD_LIBRARY_PATH |
|
ajout fonction pour lancemen...
|
134 |
} |
135 |
local aircrafts="$FGADDON/Aircraft" |
|
136 |
local fgfs_args=("--fg-root=$FGDIR/source/fgdata") |
|
137 |
local aircraft= |
|
138 |
local airport= |
|
139 |
if [[ -o BASH_REMATCH ]]; then |
|
140 |
local bash_rematch_set=1 |
|
141 |
fi |
|
142 | ||
143 |
for fgfs_arg in $@; do |
|
144 |
if test ${fgfs_arg#--} = ${fgfs_arg}; then |
|
145 |
############ APPAREIL DANS FGADDON ? |
|
146 |
if test -n "$(find $aircrafts -maxdepth 2 -type f -name ${fgfs_arg}-set.xml -print -quit)"; then |
|
147 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
148 |
fgfs_args+=("--fg-aircraft=$FGADDON/Aircraft") |
|
149 | ||
150 |
############ APPAREIL DANS FGDIR/source/fgdata ? |
|
151 |
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 |
|
152 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
153 |
fgfs_args+=("--aircraft-dir=$official_aircraft") |
|
154 |
unset official_aircraft |
|
155 | ||
ajout de gestion de bdd pour...
|
156 |
############ APPAREIL DANS FGADDON ? |
157 |
elif which sqlite3 > /dev/null 2>&1 \ |
|
158 |
&& test -r $FGADDON/fgaddon.db \ |
|
159 |
&& test $(sqlite3 $FGADDON/fgaddon.db <<< "select count(file) from setxml where file is '${fgfs_arg}-set.xml'") -eq 1; then |
|
160 |
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'") |
|
161 |
read -q "REPLY?download $model ? (y/N) " |
|
162 |
read |
|
163 |
if test -n "$REPLY" && test ${REPLY:l} = "y"; then |
|
164 |
svn co https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft/$model $FGADDON/Aircraft/$model |
|
165 |
fgfs_args+=("--aircraft=$fgfs_arg") |
|
166 |
else |
|
167 |
echo "aircraft $fgfs_arg isn't installed" |
|
168 |
return |
|
169 |
fi |
|
170 | ||
ajout fonction pour lancemen...
|
171 |
############ SERVEUR MULTIPLAY ? |
172 |
elif set -o BASH_REMATCH && [[ $fgfs_arg =~ "^mp([0-9]+)$" ]]; then |
|
173 |
fgfs_args+=("--multiplay=out,10,mpserver${BASH_REMATCH[2]}.flightgear.org,5000") |
|
fix some fgfs options
|
174 |
fgfs_args+=("--callsign=f-zakh") |
ajout fonction pour lancemen...
|
175 |
test -z "$bash_rematch_set" && set +o BASH_REMATCH |
176 | ||
ajout trace de vol
|
177 |
############ DEMANDE DE TRACE DE VOL ? |
178 |
elif [[ $fgfs_arg == "log" ]]; then |
|
179 |
# option construite plus tard avec nom de l'appareil |
|
180 |
local log_requested=1 |
|
181 | ||
ajout fonction pour lancemen...
|
182 |
############ AEROPORT ? |
183 |
else |
|
184 |
local candidate_airport=${fgfs_arg%:*}; [[ $candidate_airport == $fgfs_arg ]] && candidate_airport=${fgfs_arg%+*} |
|
185 |
local candidate_parking=${fgfs_arg#*:}; [[ $candidate_parking == $fgfs_arg ]] && unset candidate_parking |
|
186 |
local candidate_runway=${fgfs_arg#*+}; [[ $candidate_runway == $fgfs_arg ]] && unset candidate_runway |
|
187 |
local terrafs=${candidate_airport#-} |
|
188 | ||
189 |
if [[ $terrafs != $candidate_airport && -x $HOME/.fgfs/terrafs && -d $HOME/.fgfs/terrafs.d ]]; then |
|
190 |
candidate_airport=$terrafs |
|
191 |
$HOME/.fgfs/terrafs $HOME/.fgfs/terrafs.d |
|
192 |
fgfs_args+=(--fg-scenery=$HOME/.fgfs/terrafs.d) |
|
193 |
fgfs_args+=(--disable-terrasync) |
|
194 |
local scenes_dir=$HOME/.fgfs/terrafs.d |
|
195 |
else |
|
196 |
fgfs_args+=(--terrasync-dir=$HOME/.fgfs/TerraSync) |
|
197 |
fgfs_args+=(--enable-terrasync) |
|
198 |
local scenes_dir=$HOME/.fgfs/TerraSync |
|
199 |
fi |
|
200 | ||
201 |
local airport_data="$scenes_dir/Airports/$candidate_airport[1]:u/$candidate_airport[2]:u/$candidate_airport[3]:u/${candidate_airport:u}" |
|
202 |
if [[ -a "${airport_data}.threshold.xml" ]]; then |
|
203 |
fgfs_args+=(--airport=$candidate_airport) |
|
204 |
if [[ -a "${airport_data}.groundnet.xml" && -n "$candidate_parking" ]]; then |
|
205 |
if test $candidate_parking = '?'; then |
|
206 |
echo "Parkings ${candidate_airport:u}:" |
|
207 |
sed -rn "/<parkingList/,/parkingList>/s/^.* name=\"([^\"]+).*$/\1/p" ${airport_data}.groundnet.xml |
|
208 |
return |
|
209 |
elif sed -rn "/<parkingList/,/parkingList>/p" ${airport_data}.groundnet.xml | grep -q "name=\"${candidate_parking}\""; then |
|
fix some fgfs options
|
210 |
fgfs_args+=("--parkpos='$candidate_parking'") |
ajout fonction pour lancemen...
|
211 |
fi |
212 |
elif test -n "$candidate_runway"; then |
|
213 |
if test $candidate_runway = '?'; then |
|
214 |
echo "Runways ${candidate_airport:u}:" |
|
215 |
sed -rn 's|^.*<rwy>(.+)</rwy>.*$|\1|p' ${airport_data}.threshold.xml |
|
216 |
return |
|
217 |
elif grep -q "<rwy>${candidate_runway}</rwy>" ${airport_data}.threshold.xml; then |
|
218 |
fgfs_args+=("--runway=$candidate_runway") |
|
219 |
fi |
|
220 |
fi |
|
221 |
fi |
|
222 |
fi |
|
223 | ||
224 |
######## AUTRE OPTION |
|
225 |
else |
|
226 |
case $fgfs_arg in |
|
add fgfs build status from J...
|
227 |
--update(-data|-source|-build|-fgaddon|-check|)) |
ajout fonction pour lancemen...
|
228 |
for up in ${${=${fgfs_arg#--update}:-data source build}#-}; do |
229 |
update_fg $up |
|
230 |
done |
|
231 |
unset up |
|
232 |
return |
|
233 |
;; |
|
234 |
--(show-aircraft|help)) |
|
ajout trace de vol
|
235 |
local -A complement=( |
ajout fonction pour lancemen...
|
236 |
--show-aircraft --fg-aircraft=$FGADDON/Aircraft |
237 |
--help --verbose |
|
238 |
) |
|
fix multiple instances on LD...
|
239 |
ld_library_path |
ajout fonction pour lancemen...
|
240 |
$FGDIR/install/flightgear/bin/fgfs $fgfs_arg ${complement[$fgfs_arg]} 2>/dev/null | pager |
241 |
return |
|
242 |
;; |
|
243 |
*) |
|
244 |
fgfs_args+=($fgfs_arg);; |
|
245 |
esac |
|
246 |
fi |
|
247 |
done |
|
248 |
unset fgfs_arg |
|
ajout trace de vol
|
249 |
if [[ -n "$log_requested" && -z "${fgfs_args[(r)--igc=*]}" ]]; then |
ajout trace de vol (2)
|
250 |
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
|
251 |
fi |
252 | ||
fix multiple instances on LD...
|
253 |
ld_library_path |
ajout fonction pour lancemen...
|
254 | |
255 |
echo ${fgfs_args[@]} |
|
256 |
# TODO: ne lancer avec primusrun que si c'est nécesaire, d'autres solution existent ? |
|
257 |
primusrun $FGDIR/install/flightgear/bin/fgfs ${fgfs_args[@]} |
|
258 |
|
|
259 |
if grep -q $HOME/.fgfs/terrafs.d /proc/mounts; then |
|
260 |
fusermount -u $HOME/.fgfs/terrafs.d |
|
261 |
fi |
|
262 |
unset fgfs_args |
|
263 |
} |