config / .fgfs / fgaddon /
Newer Older
507 lines | 19.494kb
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
1
#!/bin/bash
2

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
3
set -e
4

            
5
declare -A data=(
6
        [/sim/description]=text
7
        [/sim/long-description]=text
8
        [/sim/author]=text
9
        [/sim/flight-model]=text
10
        [/sim/type]=text
11
        [/sim/model/path]=text
12
)
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
13
fgaddon_svn=https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft
many improvement
Sébastien MARQUE authored on 2020-09-08
14
fgaddon_path=$HOME/.fgfs/flightgear-fgaddon/Aircraft
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
15
database=${DB:-$0.db}
16
#locale=fr
17

            
18
test -r "$0.conf" && source $0.conf && echo config red
19

            
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
20
aircrafts=$(mktemp --dry-run /dev/shm/Aircraft-XXXXXXXXX)
21
aircraft=$(mktemp --dry-run /dev/shm/aircraft-XXXXXXX)
22
setxml=$(mktemp --dry-run /dev/shm/setxml-XXXXXXXX)
23
in_ram_database=$(mktemp --dry-run /dev/shm/XXXXXXX)
24

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
25
function xmlgetnext () {
26
    local IFS='>'
27
    read -d '<' TAG VALUE
28
    # by design, the first TAG/VALUE pair is empty
29
    # to avoid infinite loops at end of file parsing we return an error
30
    # the next time we find an empty TAG
31
    if test -z "$TAG"; then
better infinite loop check
Sébastien MARQUE authored on 2020-10-19
32
        test ${xmlgetnext_empty_tag:-0} -gt 0 && return 1
33
        xmlgetnext_empty_tag=$(( xmlgetnext_empty_tag + 1 ))
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
34
    fi
35
    # process $TAG only if necessary
36
    local _TAG=$(printf '%q' $TAG)
37
    if test ${_TAG:0:1} = '$'; then
38
        TAG=$(tr '\n' ' ' <<< $TAG | sed 's/  */ /g; s/ *$//')
39
    fi
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
40
}
41

            
keep journal of sqlite reque...
Sébastien MARQUE authored on 2020-10-19
42
rm -f /dev/shm/sqlite_request
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
43
function sqlite_request () {
keep journal of sqlite reque...
Sébastien MARQUE authored on 2020-10-19
44
    local delimiter=';'
45
    test ${1:0:1} == '.' && delimiter=''
46
    echo "${1}${delimiter}" >> /dev/shm/sqlite_request
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
47
    if ! sqlite3 "$in_ram_database" <<< "$1"; then
48
        register_state
49
    fi
50
}
51

            
52
function xmlremovecomments () {
53
    sed -ri 's/<(!--|script>)/\n&/;s/(<\/script|--)>/&\n/' $setxml
54
    sed -ri '/<(script>|!--).*(<\/script|--)>/d;/<(script>|!--)/,/(<\/script|--)>/d' $setxml
small stuff
Sébastien MARQUE authored on 2020-09-27
55
    sed -i 's/\xef\xbb\xbf//' $setxml # removes BOM
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
56
}
57

            
58
function trap_break () {
59
    trap '' INT
60
    echo "stop requested"
61
    register_state
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
62
}
63

            
64
function trap_exit () {
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
65
    trapped_rc=$?
66
    trap '' INT
67
    rm -f $aircrafts $aircraft $setxml
68
    if test ! -e $in_ram_database; then
69
        exit
70
    fi
71
    test $trapped_rc -ne 0 && register_state
many improvements
Sébastien MARQUE authored on 2020-09-02
72
    echo "updating installation status"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
73
    for ac in $(sqlite_request 'select printf("%i:%s/%s", aircrafts.id, aircrafts.name, setxml.file)
74
                                from aircrafts inner join setxml
75
                                where aircrafts.id = setxml.variantof and setxml.installed != 0;'); do
many improvements
Sébastien MARQUE authored on 2020-09-02
76
        ac_path=${ac#*:}
many improvement
Sébastien MARQUE authored on 2020-09-08
77
        if test ! -e $fgaddon_path/$ac_path-set.xml; then
78
            sqlite_request "update setxml set installed = 0 where file = '${ac_path#*/}' and variantof = ${ac%:*}"
79
        fi
80
    done
81
    for ac in $fgaddon_path/*/*-set.xml; do
82
        ac=${ac/$fgaddon_path}
83
        sx=${ac##*/}
84
        ac=${ac%/*}
85
        if test -d $fgaddon_path/$ac/.svn; then
86
            install_type=1
87
        elif test -d $fgaddon_path/$ac/.git; then
88
            install_type=2
89
        else
90
            install_type=3
91
        fi
92
        sqlite_request "update setxml set installed = $install_type
93
                        where exists (
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
94
                            select 1
95
                            from aircrafts
96
                            where name = '${ac/\/}' and setxml.variantof = id
many improvement
Sébastien MARQUE authored on 2020-09-08
97
                        )"
many improvements
Sébastien MARQUE authored on 2020-09-02
98
    done
cosmetics
Sébastien MARQUE authored on 2020-10-19
99
    local missing_setxml=$(sqlite_request "select printf(' - %s', name)
100
                                     from aircrafts
101
                                     where id not in (select variantof from setxml)")
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
102
    if test -n "$missing_setxml"; then
improve output for missing a...
Sébastien MARQUE authored on 2020-09-23
103
        echo -e "missing setxml config for :\n$missing_setxml"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
104
    fi
list missing models
Sébastien MARQUE authored on 2020-10-19
105
    local missing_model=$(sqlite_request 'select count(setxml.file)
106
                                          from aircrafts inner join setxml
107
                                          where aircrafts.id = setxml.variantof and setxml.`/sim/model/path` = ""')
108
    if test $missing_model -gt 0; then
109
        echo "$missing_model aircrafts without /sim/model/path information"
110
        if test $missing_model -le 10; then
111
            echo "aircrafts without /sim/model/path information:"
112
            sqlite_request 'select printf(" - %s/%s", aircrafts.name, setxml.file)
113
                            from aircrafts inner join setxml
114
                            where aircrafts.id = setxml.variantof and setxml.`/sim/model/path` = ""'
115
        fi
116
    fi
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
117
    if test -r "$database" && md5sum $in_ram_database | sed "s,$in_ram_database,$database," | md5sum --status -c -; then
118
        rm -f $in_ram_database
many improvements
Sébastien MARQUE authored on 2020-09-02
119
        echo "no changes in $database"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
120
    elif test -w "$database"; then
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
121
        sqlite_request "vacuum"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
122
        mv -f $in_ram_database "$database"
many improvements
Sébastien MARQUE authored on 2020-09-02
123
        echo "database $database updated"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
124
    elif ! test -e "$database"; then
125
        mv $in_ram_database "$database"
many improvements
Sébastien MARQUE authored on 2020-09-02
126
        echo "database $database created"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
127
    else
128
        rm -f $in_ram_database
many improvements
Sébastien MARQUE authored on 2020-09-02
129
        echo "nothing can be done with $database !"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
130
    fi
131
}
132

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
133
function register_state () {
134
    sqlite_request "drop table if exists recover_rev"
135
    sqlite_request "create table recover_rev (
136
                        revkey text,
137
                        revision integer,
138
                        revauthor text,
139
                        revdate integer
140
                    )"
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
141
    for revkey in ${!revindex[@]}; do
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
142
        sqlite_request "insert into recover_rev values (
143
                            '$revkey',
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
144
                            ${revindex[$revkey]:-0},
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
145
                            '${revauthor[$revkey]}',
146
                            ${revdate[$revkey]:-0}
147
                        )"
148
    done
149
    sqlite_request "drop table if exists recover_setxmlmodified"
150
    sqlite_request "create table if not exists recover_setxmlmodified (
151
                        sx text
152
                    )"
153
    for sx in ${!setxmlmodified[@]}; do
154
        sqlite_request "insert into recover_setxmlmodified values (
155
                            '$sx'
156
                        )"
157
    done
158
    exit
159
}
160

            
161
function update_database () {
162
    dbupdate=$(sqlite_request "select revision from aircrafts where name is '${ac:1}'")
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
163
    if test -z "$dbupdate"; then
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
164
        sqlite_request "insert into aircrafts (name, revision, date, author)
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
165
                        values ('${ac:1}', ${revindex[$ac]}, ${revdate[$ac]}, '${revauthor[$ac]}')"
166
    elif test $dbupdate -lt ${revindex[$ac]}; then
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
167
        sqlite_request "update aircrafts set
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
168
                            revision = ${revindex[$ac]},
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
169
                            author   = '${revauthor[$ac]}',
170
                            date = ${revdate[$ac]}
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
171
                        where name is '${ac:1}'"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
172
    fi
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
173
    id=$(sqlite_request "select id from aircrafts where name is '${ac:1}'")
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
174

            
try to fix left to do count
Sébastien MARQUE authored on 2020-10-19
175
    echo "[ ${#revindex[@]} ] ${ac:1}"
176
    unset revindex[$ac]
177

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
178
    for sx in ${!setxmlmodified[@]}; do
179
        unset include include_rootpath
180
        [[ "$sx" =~ ^"${ac:1}/" ]] || continue
181
        for col in ${!data[@]}; do
182
            data[$col]=
183
        done
184
        sx=${sx#*/}
remove -set.xml from filenam...
Sébastien MARQUE authored on 2020-09-02
185
        echo " -> $sx"
use svn cat instead of expor...
Sébastien MARQUE authored on 2020-10-19
186
        if ! svn cat $fgaddon_svn/${ac:1}/$sx-set.xml > $setxml; then
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
187
            register_state
188
        fi
189
        xmlremovecomments
better infinite loop check
Sébastien MARQUE authored on 2020-10-19
190
        unset xmlgetnext_empty_tag property
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
191
        while xmlgetnext; do
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
192
            case "${TAG:0:1}" in
193
                ''|'?'|'!')
194
                    continue;;
195
                /)
196
                    property=${property%/*};;
197
                *)
198
                    if test "${TAG: -1}" != '/'; then
199
                        property+=/${TAG%% *}
fix syntax mistake
Sébastien MARQUE authored on 2020-09-21
200
                    fi;;
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
201
            esac
202

            
203
            if [[ "$TAG" =~ ^"PropertyList include=" ]]; then
204
                include_rootpath=${include%/*}
205
                test $include = $include_rootpath && unset include_rootpath
206
                eval $(echo ${TAG#* })
207
                [[ "$include" =~ ^Aircraft/Generic/ ]] && unset include include_rootpath && continue
208
                if [[ "$include" =~ ^'../' ]]; then
209
                    if test -n "$include_rootpath"; then
210
                        if [[ "$include_rootpath" =~ '/' ]]; then
211
                            include_rootpath=${include_rootpath%/*}
212
                        else
213
                            unset include_rootpath
214
                        fi
215
                    else
216
                        ac_save=$ac
217
                        unset ac
218
                    fi
219
                    include=${include/\.\.\/}
220
                fi
221
                if ! svn cat $fgaddon_svn/${ac:1}/${include_rootpath:+$include_rootpath/}$include >> $setxml; then
222
                    register_state
223
                fi
224
                xmlremovecomments
225
            fi
226

            
227
            if [[ "$property" = /PropertyList@($data_pattern) ]]; then
fix overriding descs with in...
Sébastien MARQUE authored on 2020-09-27
228
                if test -z "${data[${property/\/PropertyList}]}"; then
229
                    eval "data[${property/\/PropertyList}]=\"${VALUE//\"/\\\"}\""
230
                    data[${property/\/PropertyList}]=$(tr '\n' ' ' <<< ${data[${property/\/PropertyList}]} | sed -r 's/^\s*//;s/\s+/ /g;s/\s*$//')
231
                fi
many improvement
Sébastien MARQUE authored on 2020-09-08
232
            fi
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
233

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
234
            # continue parsing (while loop) until everything's found
235
            for col in ${!data[@]}; do
236
                test -z "${data[$col]}" && continue 2
237
            done
238
            break # everything's found
239
        done < $setxml
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
240

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
241
        if eval "test -z \"$data_test_null\""; then
242
            echo "WARNING: no info found, skipping"
243
            continue
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
244
        fi
245

            
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
246
        known=$(sqlite_request "select variantof from setxml where file is '$sx'")
247
        if test -n "$known"; then
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
248
            for col in ${!data[@]}; do
fix sqlite column name
Sébastien MARQUE authored on 2020-10-19
249
                dbvalue=$(sqlite_request "select \`$col\`
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
250
                                          from setxml
251
                                          where file is '$sx' and variantof = $known")
252
                if test "$dbvalue" != "${data[$col]}" -a -n "${data[$col]}"; then
253
                    sqlite_request "update setxml
fix sqlite column name
Sébastien MARQUE authored on 2020-10-19
254
                                    set \`$col\` = '${data[$col]//\'/\'\'}'
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
255
                                    where file is '$sx' and variantof = $known"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
256
                fi
257
            done
258
        else
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
259
            values="'$sx', $id, "
260
            for col in ${!data[@]}; do
261
                values+="'${data[$col]//\'/\'\'}', "
262
            done
263
            values+=0
264
            sqlite_request "insert into setxml values ($values)"
265
        fi
266
        test -n "$ac_save" && ac=$ac_save
267
        unset setxmlmodified[${ac:1}/$sx]
268
    done
269
}
270

            
271
function apply_revision () {
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
272
    for ac in "${!revindex[@]}"; do
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
273
        update_database
274
        if test -d $fgaddon_path/${ac:1}/.svn \
275
        && test "$(svn info --show-item=url $fgaddon_path/${ac:1})" != "$fgaddon_svn/${ac:1}" \
276
        || test -d $fgaddon_path/${ac:1} -a ! -d $fgaddon_path/${ac:1}/.svn; then
277
            echo "INFO: local ${ac:1} installed out from repo" >&2
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
278
        fi
279
    done
280
}
281

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
282
trap trap_break INT
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
283
trap trap_exit EXIT
284

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
285
stty -echoctl
286

            
better deletion handling
Sébastien MARQUE authored on 2020-10-19
287
declare -A revindex revauthor revdate setxmlmodified revpath
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
288
data_pattern=$(printf "%s|" ${!data[@]})
289
data_pattern=${data_pattern:0:-1}
290
data_test_null=$(printf '${data[%s]}' ${!data[@]})
291

            
292
if test -e $database; then
293
    cp $database $in_ram_database
294
    sql_cols=$(sqlite_request "pragma table_info(setxml)" | awk -F'|' '{printf("%s %s ", $2, $3)}')
295
    script_cols="file text variantof integer "
296
    for col in ${!data[@]}; do
297
        script_cols+="$col ${data["$col"]} "
298
    done
299
    script_cols+="installed integer " # last space is important
300
    if test "$sql_cols" != "$script_cols"; then
301
        echo "ALERT: datbase version mismatch !"
302
        exit 1
303
    fi
304
    if sqlite_request '.tables' | grep -q 'recover_' && test -z "$1"; then
305
        echo "recovering from previous saved state"
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
306
        eval $(sqlite_request "select printf('revindex[%s]=%u;revauthor[%s]=%s;revdate[%s]=%u;',
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
307
                                       revkey, revision,
308
                                       revkey, revauthor,
309
                                       revkey, revdate)
310
                               from recover_rev")
311
        eval $(sqlite_request "select printf('setxmlmodified[%s]=1;', sx)
312
                               from recover_setxmlmodified")
313
        sqlite_request "drop table recover_rev"
314
        sqlite_request "drop table recover_setxmlmodified"
315
        apply_revision
316
        exit
317
    fi
318
fi
319

            
320
sqlite_request "create table if not exists aircrafts (
cosmetics
Sébastien MARQUE authored on 2020-10-19
321
                    id       integer primary key,
322
                    name     text,
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
323
                    revision integer,
cosmetics
Sébastien MARQUE authored on 2020-10-19
324
                    date     integer,
325
                    author   text)"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
326

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
327
sqlite_request "create table if not exists setxml (
328
                    file text,
329
                    variantof integer,
330
                    $(for col in ${!data[@]}; do printf "'%s' %s, " $col ${data[$col]}; done)
331
                    installed integer)"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
332

            
search for next revision
Sébastien MARQUE authored on 2020-10-19
333
latest_revision=$(( $(sqlite_request "select max(revision) from aircrafts") + 1 ))
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
334

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
335
# for debugging purpose
336
if test -n "$2"; then
337
    ac=_${1%/*}
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
338
    revindex[$ac]=1
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
339
    revdate[$ac]=0
340
    revauthor[$ac]=foobar
341
    setxmlmodified[${ac:1}/${1#*/}]=1
342
    set -x
343
    update_database
344
    set +x
345
    exit
346
elif test -n "$1"; then
347
    ac=_${1%/*}
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
348
    eval $(sqlite_request "select printf('revindex[_%s]=%s;revdate[_%s]=%i;revauthor[_%s]=%s;',
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
349
                                            name, revision,
350
                                            name, date,
351
                                            name, author)
352
                           from aircrafts
353
                           where name = '${ac:1}'")
354
    setxmlmodified[${ac:1}/${1#*/}]=1
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
355
    if test -z "${revindex[$ac]}"; then
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
356
        echo "aircraft ${ac:1} not found"
357
        rm $in_ram_database
358
        exit
359
    fi
360
    update_database
corrective proposition for s...
Sébastien MARQUE authored on 2020-10-19
361
########################################
362
# TO KEEP SETXML uncomment below lines:
363
########################################
364
#    mkdir -p /dev/shm/aircrafts/${1%/*}
365
#    ln -f $setxml /dev/shm/aircrafts/$1
366
########################################
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
367
    exit
368
fi
369

            
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
370
echo "downloading FGADDON history from revision ${latest_revision:-0}"
371
svn log --revision ${latest_revision:-0}:HEAD --xml --verbose $fgaddon_svn > $aircrafts
372

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
373
total=$(grep -c '<logentry' $aircrafts)
374
progress=0
375

            
376
echo parsing history
377

            
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
378
while xmlgetnext; do
379
    case "$TAG" in
380
        'logentry revision='*)
381
            eval $(echo ${TAG#* })
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
382
            for action in ${!revpath[@]}; do
383
                unset revpath[$action]
384
            done
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
385
        ;;
386
        'author')
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
387
            revauthor=${VALUE//\'/\'\'}
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
388
        ;;
389
        'date')
390
            revdate=$(date +%s -d "$VALUE")
391
        ;;
392
        'path '*)
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
393
            TAG=${TAG#* }
394
            TAG=${TAG// /;}
395
            TAG=${TAG//-/_}
396
            eval $(echo ${TAG// /;})
397
            path=(${VALUE//\// })
398
            if test $kind = 'file' -a ${#path[@]} -gt 3; then
399
                revpath[$action]+="$VALUE "
400
            elif test $kind = 'dir' -a ${#path[@]} -eq 3 -a $action = 'D'; then
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
401
                unset revindex[_${path[2]}] revauthor[_${path[2]}] revdate[_${path[2]}]
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
402
                for sx in ${!setxmlmodified[@]}; do
403
                    [[ "$sx" =~ "${path[2]}/" ]] && unset setxmlmodified[$sx]
404
                done
better deletion handling
Sébastien MARQUE authored on 2020-10-19
405
                sqlite_request "delete from aircrafts where name = '${path[2]}'"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
406
            fi
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
407
        ;;
408
        '/logentry')
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
409
            for item in ${revpath[D]}; do
410
                path=(${item//\// })
manage aircraft deletion
Sébastien MARQUE authored on 2020-09-23
411
                if [[ "${path[3]}" =~ "-set.xml" ]]; then
412
                    unset setxmlmodified[${path[2]}/${path[3]/-set.xml}]
413
                    sqlite_request "delete from setxml where file = '${path[3]/-set.xml}'"
414
                fi
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
415
            done
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
416
            for action in A M R; do
417
                for item in ${revpath[$action]}; do
418
                    path=(${item//\// })
better deletion handling
Sébastien MARQUE authored on 2020-10-19
419
                    test -z "${path[2]}" && continue # avoid empty
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
420
                    revindex[_${path[2]}]=$revision
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
421
                    revauthor[_${path[2]}]=$revauthor
422
                    revdate[_${path[2]}]=$revdate
423
                    [[ "${path[3]}" =~ "-set.xml" ]] && setxmlmodified[${path[2]}/${path[3]/-set.xml}]=1
424
                done
425
            done
426
            newprogress=$((++logentry * 100 / $total))
427
            if test $(( $newprogress - $progress )) -ge ${progress_granularity:-1}; then
428
                progress=$newprogress
fix variable name conflict
Sébastien MARQUE authored on 2020-09-23
429
                echo "$progress% (${#revindex[@]})"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
430
            fi
431
        ;;
432
        '/log')
433
            apply_revision
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
434
            break
435
        ;;
436
    esac
437
done < $aircrafts
corrective proposition for s...
Sébastien MARQUE authored on 2020-10-19
438

            
439
########################################################################
440
# some aircrafts (mostly from the helijah's files architecture template)
441
# break because of infinite loop in middle of file
442
# I can't find the reason of this infinite loop
443
# these are the steps (some may be scripted)
444
# sorry about inconvenience...
445
# STEPS TO FOLLOW
446
# 1 - the following lines may be copied in a separate file (e.g /dev/shm/foo)
447
# 2 - uncomment by removing the FIRST column only and save the file
448
# 3 - uncomment the lines dedicated to save the setxml content in this script
449
# 4 - find the empty /sim/model/path:
450
#     sqlite3 /your/database <<< 'select printf("%s/%s", aircrafts.name, setxml.file)
451
#                                 from aircrafts inner join setxml
452
#                                 where aircrafts.id = setxml.variantof and setxml.`/sim/model/path` = ""'
453
# 5 - play $ DB=/your/database ./fgaddon aicrafts_name/setxml_file
454
# 6 - play $ /dev/shm/foo aicrafts_name/setxml_file
455
# 7 - play $ sqlite3 /your/database <<< "update setxml set `/sim/model/path` = '<the path found>' where file = 'setxml_file'"
456
#
457
# exemple of one-line CLI:
458
# for i in $(sqlite3 .fgfs/flightgear-fgaddon/fgaddon.db <<< 'select printf("%s/%s", aircrafts.name, setxml.file) from aircrafts inner join setxml where aircrafts.id = setxml.variantof and setxml.`/sim/model/path` = ""'); do DB=.fgfs/flightgear-fgaddon/fgaddon.db .fgfs/fgaddon $i; sim_model_path=$(/dev/shm/foo $i | awk '/^\/sim\/model\/path/{print $NF}'); test -n "$sim_model_path" && sqlite3 .fgfs/flightgear-fgaddon/fgaddon.db <<< "update setxml set \`/sim/model/path\` = '$sim_model_path' where file = '${i#*/}'"; done
459

            
460
##!/bin/bash
461
#
462
#declare -A data=(
463
#        [/sim/model/path]=text
464
#)
465
#data_pattern=$(printf "%s|" ${!data[@]})
466
#data_pattern=${data_pattern:0:-1}
467
#for col in ${!data[@]}; do
468
#    data[$col]=
469
#done
470
#
471
#function xmlgetnext () {
472
#    local IFS='>'
473
#    read -d '<' TAG VALUE
474
#    # by design, the first TAG/VALUE pair is empty
475
#    # to avoid infinite loops at end of file parsing we return an error
476
#    # the next time we find an empty TAG
477
#    if test -z "$TAG"; then
478
#        test ${xmlgetnext_empty_tag:-0} -gt 0 && return 1
479
#        xmlgetnext_empty_tag=$(( xmlgetnext_empty_tag + 1 ))
480
#    fi
481
#    # process $TAG only if necessary
482
#    local _TAG=$(printf '%q' $TAG)
483
#    if test ${_TAG:0:1} = '$'; then
484
#        TAG=$(tr '\n' ' ' <<< $TAG | sed 's/  */ /g; s/ *$//')
485
#    fi
486
#}
487
#
488
#while xmlgetnext; do
489
#    case "${TAG:0:1}" in
490
#        ''|'?'|'!')
491
#            continue;;
492
#        /)
493
#            property=${property%/*};;
494
#        *)
495
#            if test "${TAG: -1}" != '/'; then
496
#                property+=/${TAG%% *}
497
#            fi;;
498
#    esac
499
#
500
#    if [[ "$property" = /PropertyList@($data_pattern) ]]; then
501
#        if test -z "${data[${property/\/PropertyList}]}"; then
502
#            eval "data[${property/\/PropertyList}]=\"${VALUE//\"/\\\"}\""
503
#            data[${property/\/PropertyList}]=$(tr '\n' ' ' <<< ${data[${property/\/PropertyList}]} | sed -r 's/^\s*//;s/\s+/ /g;s/\s*$//')
504
#            echo "${property/\/PropertyList} : ${data[${property/\/PropertyList}]}"
505
#        fi
506
#    fi
507
#done < /dev/shm/aircrafts/$1