config / .fgfs / fgaddon /
Newer Older
467 lines | 18.161kb
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
)
complete rewrite
Sébastien MARQUE authored on 2020-11-07
13

            
14
missing_data_check=( /sim/model/path )
15

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
16
database=${DB:-$0.db}
complete rewrite
Sébastien MARQUE authored on 2020-11-07
17
test -r "$0.conf" && source "$0.conf"
18

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
19
#locale=fr
20

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
21
tempid=$(mktemp --dry-run XXXXXXX)
22
temppath=/dev/shm
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
23

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
24
setxml=$temppath/setxml-$tempid
25
json_file=$temppath/github_json-$tempid
26
in_ram_database=$temppath/${database##*/}-$tempid
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
27

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

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
45
function json () {
46
    jq --raw-output "$1" < ${2:-${json_file:?}}
47
}
48

            
49
rm -f $temppath/sqlite_request
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
50
function sqlite_request () {
complete rewrite
Sébastien MARQUE authored on 2020-11-07
51
    echo -e "## REQ $(( ++sqlite_request_count ))\n${1}\n" >> $temppath/sqlite_request
52
    sqlite3 "$in_ram_database" <<< "$1"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
53
}
54

            
55
function xmlremovecomments () {
56
    sed -ri 's/<(!--|script>)/\n&/;s/(<\/script|--)>/&\n/' $setxml
57
    sed -ri '/<(script>|!--).*(<\/script|--)>/d;/<(script>|!--)/,/(<\/script|--)>/d' $setxml
complete rewrite
Sébastien MARQUE authored on 2020-11-07
58
    sed -i 's/\xef\xbb\xbf//;s/\r//' $setxml # removes BOM and ^M
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
59
}
60

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

            
66
function trap_exit () {
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
67
    trapped_rc=$?
68
    trap '' INT
complete rewrite
Sébastien MARQUE authored on 2020-11-07
69

            
70
    if declare -f on_exit > /dev/null; then
71
        on_exit
72
    fi
73

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
74
    if test ! -e $in_ram_database; then
75
        exit
76
    fi
many improvements
Sébastien MARQUE authored on 2020-09-02
77
    echo "updating installation status"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
78
    for ac in $(sqlite_request 'select printf("%i:%s/%s", aircrafts.id, aircrafts.name, setxml.file)
79
                                from aircrafts inner join setxml
80
                                where aircrafts.id = setxml.variantof and setxml.installed != 0;'); do
many improvements
Sébastien MARQUE authored on 2020-09-02
81
        ac_path=${ac#*:}
complete rewrite
Sébastien MARQUE authored on 2020-11-07
82
        if test ! -e ${hangar[path]}/$ac_path-set.xml; then
many improvement
Sébastien MARQUE authored on 2020-09-08
83
            sqlite_request "update setxml set installed = 0 where file = '${ac_path#*/}' and variantof = ${ac%:*}"
84
        fi
85
    done
complete rewrite
Sébastien MARQUE authored on 2020-11-07
86
    for ac in ${hangar[path]}/*/*-set.xml; do
87
        ac=${ac/${hangar[path]}}
many improvement
Sébastien MARQUE authored on 2020-09-08
88
        sx=${ac##*/}
89
        ac=${ac%/*}
complete rewrite
Sébastien MARQUE authored on 2020-11-07
90
        if test -d ${hangar[path]}/$ac/.svn; then
many improvement
Sébastien MARQUE authored on 2020-09-08
91
            install_type=1
complete rewrite
Sébastien MARQUE authored on 2020-11-07
92
        elif test -d ${hangar[path]}/$ac/.git; then
many improvement
Sébastien MARQUE authored on 2020-09-08
93
            install_type=2
94
        else
95
            install_type=3
96
        fi
97
        sqlite_request "update setxml set installed = $install_type
98
                        where exists (
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
99
                            select 1
100
                            from aircrafts
101
                            where name = '${ac/\/}' and setxml.variantof = id
many improvement
Sébastien MARQUE authored on 2020-09-08
102
                        )"
many improvements
Sébastien MARQUE authored on 2020-09-02
103
    done
complete rewrite
Sébastien MARQUE authored on 2020-11-07
104
    local missing_setxml=$(sqlite_request "select printf(' - %s (%s)', aircrafts.name, hangars.name)
105
                                     from aircrafts inner join hangars
106
                                     where hangars.id = aircrafts.hangar and aircrafts.id not in (select variantof from setxml)")
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
107
    if test -n "$missing_setxml"; then
improve output for missing a...
Sébastien MARQUE authored on 2020-09-23
108
        echo -e "missing setxml config for :\n$missing_setxml"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
109
    fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
110

            
111
    for data_presence_check in ${missing_data_check[@]}; do
112
        if [[ -v data[$data_presence_check] ]]; then
113
            local missing_data=$(sqlite_request "select count(setxml.file)
114
                                                 from aircrafts inner join setxml
115
                                                 where aircrafts.id = setxml.variantof and setxml.\`$data_presence_check\` = ''")
116
            if test $missing_data -gt 0; then
117
                echo "$missing_data aircrafts without $data_presence_check information"
118
                if test $missing_data -le 10; then
119
                    echo "aircrafts without $data_presence_check information:"
120
                    sqlite_request "select printf(' - %s/%s (%s)', aircrafts.name, setxml.file, hangars.name)
121
                                    from aircrafts inner join setxml, hangars
122
                                    where
123
                                        aircrafts.id = setxml.variantof
124
                                    and
125
                                        aircrafts.hangar = hangars.id
126
                                    and
127
                                        setxml.\`$data_presence_check\` = ''"
128
                fi
129
            fi
list missing models
Sébastien MARQUE authored on 2020-10-19
130
        fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
131
    done
132

            
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
133
    if test -r "$database" && md5sum $in_ram_database | sed "s,$in_ram_database,$database," | md5sum --status -c -; then
many improvements
Sébastien MARQUE authored on 2020-09-02
134
        echo "no changes in $database"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
135
    elif test -w "$database"; then
complete rewrite
Sébastien MARQUE authored on 2020-11-07
136
        rm -f "$database"
137
        sqlite_request '.dump' | sqlite3 "$database"
many improvements
Sébastien MARQUE authored on 2020-09-02
138
        echo "database $database updated"
complete rewrite
Sébastien MARQUE authored on 2020-11-07
139
    elif test ! -e "$database" -a -w ${database%/*}; then
140
        sqlite_request '.dump' | sqlite3 "$database"
many improvements
Sébastien MARQUE authored on 2020-09-02
141
        echo "database $database created"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
142
    else
many improvements
Sébastien MARQUE authored on 2020-09-02
143
        echo "nothing can be done with $database !"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
144
    fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
145
    rm -f $temppath/*-$tempid
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
146
}
147

            
148
function update_database () {
complete rewrite
Sébastien MARQUE authored on 2020-11-07
149
    sqlite_request "insert into aircrafts (name, author, revision, date, hangar)
150
                    select  name, author, revision, date, hangar from recover_aircrafts
151
                        where recover_aircrafts.name = '$ac' and recover_aircrafts.hangar = ${hangar[id]}
152
                    on conflict (name, hangar) where aircrafts.name = '$ac' and aircrafts.hangar = ${hangar[id]} do
153
                        update set
154
                            author   = (select author   from recover_aircrafts where name = '$ac'),
155
                            revision = (select revision from recover_aircrafts where name = '$ac'),
156
                            date     = (select date     from recover_aircrafts where name = '$ac')
157
                        where aircrafts.name = '$ac' and aircrafts.hangar = ${hangar[id]}"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
158

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
159
    id=$(sqlite_request "select id from aircrafts where name is '${ac}' and hangar = ${hangar[id]}")
try to fix left to do count
Sébastien MARQUE authored on 2020-10-19
160

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
161
    echo $(sqlite_request "select printf('[ %i/%i ] $ac', count(sx), count(distinct ac)) from recover_setxml")
162

            
fix when aircraft updated mu...
Sébastien MARQUE authored on 2020-11-13
163
    for sx in $(sqlite_request "select distinct sx from recover_setxml where ac = '$ac'"); do
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
164
        for col in ${!data[@]}; do
165
            data[$col]=
166
        done
complete rewrite
Sébastien MARQUE authored on 2020-11-07
167

            
remove -set.xml from filenam...
Sébastien MARQUE authored on 2020-09-02
168
        echo " -> $sx"
complete rewrite
Sébastien MARQUE authored on 2020-11-07
169
        getfromrepo ${ac}/$sx-set.xml > $setxml
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
170

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
171
        unset xmlgetnext_empty_tag property include include_rootpath ac_save
172
        while xmlgetnext; do
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
173
            if [[ "$TAG" =~ ^"PropertyList include=" ]]; then
174
                include_rootpath=${include%/*}
175
                test $include = $include_rootpath && unset include_rootpath
complete rewrite
Sébastien MARQUE authored on 2020-11-07
176

            
177
                eval $(echo ${TAG#* }) # include="..."
178

            
179
                if [[ "$include" =~ ^Aircraft/Generic/ ]]; then
180
                    unset include include_rootpath
181
                    continue
182

            
183
                elif [[ "$include" =~ ^'../' ]]; then
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
184
                    if test -n "$include_rootpath"; then
185
                        if [[ "$include_rootpath" =~ '/' ]]; then
186
                            include_rootpath=${include_rootpath%/*}
187
                        else
188
                            unset include_rootpath
189
                        fi
190
                    else
191
                        ac_save=$ac
192
                        unset ac
193
                    fi
194
                    include=${include/\.\.\/}
195
                fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
196
                getfromrepo ${ac}/${include_rootpath:+$include_rootpath/}$include >> $setxml
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
197
            fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
198
        done < $setxml
199

            
200
        test -n "$ac_save" && ac=$ac_save
201

            
202
# some aircrafts (mostly from the helijah's files architecture template)
203
# break because of infinite loop in middle of file
204
# I can't find the reason of this infinite loop
205
# this is the reason of this double-pass
206
        unset xmlgetnext_empty_tag property
207
        while xmlgetnext; do
208
        case "${TAG:0:1}" in
209
                ''|'?'|'!')
210
                    continue;;
211
                /)
212
                    property=${property%/*};;
213
                *)
214
                    if test "${TAG: -1}" != '/'; then
215
                        property+=/${TAG%% *}
216
                    fi;;
217
            esac
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
218

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

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

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
233
        if eval "test -z \"$data_test_null\""; then
234
            echo "WARNING: no info found, skipping"
complete rewrite
Sébastien MARQUE authored on 2020-11-07
235
            mkdir -p $temppath/no-data-ac
236
            cp -f $setxml $temppath/no-data-ac/${ac}-${sx}
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
237
        else
complete rewrite
Sébastien MARQUE authored on 2020-11-07
238
            insert_values="'$sx', $id, "
239
            insert_col='file, variantof, '
240
            update_values=''
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
241
            for col in ${!data[@]}; do
complete rewrite
Sébastien MARQUE authored on 2020-11-07
242
                insert_col+="\`$col\`, "
243
                insert_values+="'${data[$col]//\'/\'\'}', "
244
                if test -n "${data[$col]}"; then
245
                    update_values+="\`$col\` = '${data[$col]//\'/\'\'}', "
246
                fi
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
247
            done
complete rewrite
Sébastien MARQUE authored on 2020-11-07
248
            sqlite_request "insert into setxml (${insert_col%,*}, installed) values (${insert_values%,*}, 0)
249
                            on conflict (file, variantof) where file = '$sx' and variantof = $id do
250
                                update set
251
                                    ${update_values%,*}, installed = 0
252
                                where
253
                                    file = '$sx' and variantof = $id"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
254
        fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
255

            
256
        sqlite_request "delete from recover_setxml where ac = '$ac' and sx = '$sx'"
257
    done
258
}
259

            
260
function add_record () {
261
    ac_ass_array[$1]="$2"
262
}
263

            
264
function get_record () {
265
    if test -n "$1"; then
266
        echo "${ac_ass_array[$1]}"
267
    else
268
        for k in ${!ac_ass_array[@]}; do
269
            echo $k = ${ac_ass_array[$k]}
270
        done
271
    fi
272
}
273

            
274
function add_aircraft () {
275
    for key in name revision date author; do
276
        test -n "${ac_ass_array[$key]}" # exit if missing data
277
    done
278
    sqlite_request "insert into recover_aircrafts (name, revision, date, author, hangar)
279
                        values (
280
                        '${ac_ass_array[name]}',
281
                         ${ac_ass_array[revision]},
282
                         ${ac_ass_array[date]},
283
                        '${ac_ass_array[author]}',
284
                         ${hangar[id]})"
285
    for key in name revision date author; do
286
        ac_ass_array[$key]=''
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
287
    done
288
}
289

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
290
function add_setxml_for_aircraft () {
291
    sqlite_request "insert into recover_setxml values ('$1', '${2/%-set.xml}')"
292
}
293

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
294
function apply_revision () {
complete rewrite
Sébastien MARQUE authored on 2020-11-07
295
    for ac in $(sqlite_request "select name from recover_aircrafts"); do
296
        # delete aircrafts that have been deleted from the repo
297
        sqlite_request "delete from setxml
298
                        where (file, variantof) in (
299
                            select file, variantof from setxml
300
                              inner join aircrafts
301
                              where aircrafts.id = setxml.variantof
302
                                and aircrafts.name = '$ac'
303
                                and aircrafts.hangar = ${hangar[id]}
304
                                and setxml.file not in (
305
                                    select sx from recover_setxml where ac = '$ac'
306
                                )
307
                            )"
308

            
309
        # delete aircrafts without setxml found
310
        sqlite_request "delete from recover_aircrafts
311
                        where name not in (select distinct ac from recover_setxml)"
312

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
313
        update_database
complete rewrite
Sébastien MARQUE authored on 2020-11-07
314
        if test -d ${hangar[path]}/${ac}/.${hangar[type]} \
315
        && \
316
        case ${hangar[type]} in
317
           svn) test "$(svn info --show-item=url ${hangar[path]}/${ac})" != "${hangar[url]}/${ac}";;
318
           git) test "$(git -C ${hangar[path]}/${ac} config --get remote.origin.url)" != "${hangar[url]}/${ac}";;
319
        esac \
320
        || test -d ${hangar[path]}/${ac} -a ! -d ${hangar[path]}/${ac}/.${hangar[type]}; then
321
            echo "INFO: local ${ac} installed out from repo" >&2
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
322
        fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
323
        sqlite_request "delete from recover_aircrafts where name = '$ac'"
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
324
    done
325
}
326

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

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

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
332
declare -A hangar
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
333
data_pattern=$(printf "%s|" ${!data[@]})
334
data_pattern=${data_pattern:0:-1}
335
data_test_null=$(printf '${data[%s]}' ${!data[@]})
336

            
337
if test -e $database; then
338
    cp $database $in_ram_database
complete rewrite
Sébastien MARQUE authored on 2020-11-07
339

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
340
    sql_cols=$(sqlite_request "pragma table_info(setxml)" | awk -F'|' '{printf("%s %s ", $2, $3)}')
341
    script_cols="file text variantof integer "
342
    for col in ${!data[@]}; do
343
        script_cols+="$col ${data["$col"]} "
344
    done
345
    script_cols+="installed integer " # last space is important
346
    if test "$sql_cols" != "$script_cols"; then
347
        echo "ALERT: datbase version mismatch !"
348
        exit 1
349
    fi
complete rewrite
Sébastien MARQUE authored on 2020-11-07
350
    if sqlite_request '.tables' | grep -q 'recover_'; then
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
351
        echo "recovering from previous saved state"
complete rewrite
Sébastien MARQUE authored on 2020-11-07
352
        hangar[id]=$(sqlite_request "select hangar from recover_aircrafts limit 1")
353
        eval $(sqlite_request "select printf('hangar[name]=%s;hangar[url]=%s;hangar[type]=%s;hangar[source]=%s',
354
                                              name,           url,           type,           source)
355
                               from hangars
356
                               where id = '${hangar[id]}'")
357
        source $(grep -l "^\s*hangar\[name\]=${hangar[name]}\s*$" ${0%*/}.d/*.hangar)
358
        eval "getfromrepo () {$(declare -f getfromrepo | sed '1,2d;$d'); xmlremovecomments;}"
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
359
        apply_revision
360
        exit
361
    fi
362
fi
363

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
364
sqlite_request "create table if not exists hangars (
365
                    id     integer primary key,
366
                    name   text,
367
                    source text,
368
                    type   text,
369
                    url    text,
370
                    path   text,
371
                    active integer)"
372

            
373
sqlite_request 'create unique index if not exists "index_hangars" on hangars (url)'
374

            
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
375
sqlite_request "create table if not exists aircrafts (
cosmetics
Sébastien MARQUE authored on 2020-10-19
376
                    id       integer primary key,
377
                    name     text,
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
378
                    revision integer,
cosmetics
Sébastien MARQUE authored on 2020-10-19
379
                    date     integer,
complete rewrite
Sébastien MARQUE authored on 2020-11-07
380
                    author   text,
381
                    hangar   integer)"
382

            
383
sqlite_request 'create unique index if not exists "index_aircrafts" on aircrafts (name, hangar)'
ajout de gestion de bdd pour...
Sébastien MARQUE authored on 2020-08-24
384

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

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
391
sqlite_request 'create unique index if not exists "index_setxml" on setxml (file, variantof)'
392

            
393
for file in $(find ${0%*/}.d -type f -name "*.hangar"); do
394
    unset hangar error_message
395
    unset -f getfromrepo parse_repo_history
396
    declare -A hangar
397
    source $file
398

            
399
    test -n "${hangar[name]}"      \
400
      -a -n "${hangar[source]}"    \
401
      -a -n "${hangar[type]}"      \
402
      -a -n "${hangar[url]}"       \
403
      -a -n "${hangar[active]}" || \
404
        error_message="${error_message:+$error_message, }missing hangar data"
405

            
406
    declare -f getfromrepo > /dev/null || \
407
        error_message="${error_message:+$error_message, }missing getfromrepo function"
408

            
409
    declare -f parse_repo_history > /dev/null || \
410
        error_message="${error_message:+$error_message, }missing parse_repo_history function"
411

            
412
    if test -n "$error_message"; then
413
        echo "file $file isn't a valid hangar ($error_message)"
414
        continue
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
415
    fi
416

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
417
    sqlite_request "insert into hangars (name, source, type, url, path, active)
418
                    values (
419
                        '${hangar[name]}', '${hangar[source]}', '${hangar[type]}',
420
                        '${hangar[url]}',  '${hangar[path]}',    ${hangar[active]})
421
                    on conflict (url) where url = '${hangar[url]}' do
422
                    update set
423
                        name = '${hangar[name]}',
424
                        path = '${hangar[path]}',
425
                        active = ${hangar[active]}
426
                    where url = '${hangar[url]}'"
427
done
428

            
429
unset hangar
430
unset -f getfromrepo parse_repo_history
431
declare -A hangar ac_ass_array
432
for h_id in $(sqlite_request "select id from hangars where active = 1"); do
433

            
434
    sqlite_request 'create table if not exists recover_aircrafts (
435
                        name     text,
436
                        revision integer,
437
                        date     integer,
438
                        author   text,
439
                        hangar   integer)'
complete rewrite (use svn in...
Sébastien MARQUE authored on 2020-09-07
440

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
441
    sqlite_request 'create table if not exists recover_setxml (
442
                        ac text,
443
                        sx text)'
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
444

            
complete rewrite
Sébastien MARQUE authored on 2020-11-07
445
    eval $(sqlite_request "select printf('hangar[id]=%i;hangar[source]=%s;', id, source)
446
                           from hangars
447
                           where id = '${h_id}'")
448

            
449
    source $(grep -l "^\s*hangar\[source\]=${hangar[source]}\s*$" ${0%*/}.d/*.hangar)
450

            
451
    eval "getfromrepo () {$(declare -f getfromrepo | sed '1,2d;$d'); xmlremovecomments;}"
452

            
453
    echo -e "=${hangar[name]//?/=}=\n ${hangar[name]} \n=${hangar[name]//?/=}="
454

            
455
    latest_revision=$(( $(sqlite_request "select max(revision)
456
                                          from aircrafts inner join hangars
457
                                          where hangars.id = aircrafts.hangar and hangars.name = '${hangar[name]}'") + 1 ))
458

            
459
    parse_repo_history
460

            
461
    if declare -f on_exit > /dev/null; then
462
        on_exit
463
    fi
464
    sqlite_request "drop table recover_aircrafts"
465
    sqlite_request "drop table recover_setxml"
466
done
ré-écriture complète
Sébastien MARQUE authored on 2020-09-20
467