Showing 1 changed files with 49 additions and 23 deletions
+49 -23
.fgfs/fgaddon
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 fgaddon_url=https://sourceforge.net/p/flightgear/fgaddon/HEAD/tree/trunk/Aircraft
4 4
 fgaddon_svn=https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft
5
-fgaddon_path=$HOME/.fgfs/flightgear-addons/Aircraft
5
+fgaddon_path=$HOME/.fgfs/flightgear-fgaddon/Aircraft
6 6
 
7 7
 aircrafts=$(mktemp --dry-run /dev/shm/Aircraft-XXXXXXXXX)
8 8
 aircraft=$(mktemp --dry-run /dev/shm/aircraft-XXXXXXX)
... ...
@@ -10,7 +10,7 @@ setxml=$(mktemp --dry-run /dev/shm/setxml-XXXXXXXX)
10 10
 in_ram_database=$(mktemp --dry-run /dev/shm/XXXXXXX)
11 11
 database=${DB:-$0.db}
12 12
 
13
-attributes=(description long_description author flight_model type)
13
+attributes=(description long-description author flight-model type)
14 14
 
15 15
 xmlgetnext () {
16 16
    local IFS='>'
... ...
@@ -24,11 +24,27 @@ function sqlite_request () {
24 24
 
25 25
 function trap_exit () {
26 26
     echo "updating installation status"
27
-    for ac in $(sqlite_request 'select printf("%i:%s/%s", aircrafts.id, aircrafts.name, setxml.file) from aircrafts inner join setxml where aircrafts.id = setxml.variantof;'); do
27
+    for ac in $(sqlite_request 'select printf("%i:%s/%s", aircrafts.id, aircrafts.name, setxml.file) from aircrafts inner join setxml where aircrafts.id = setxml.variantof and setxml.installed != 0;'); do
28 28
         ac_path=${ac#*:}
29
-        test ! -e $fgaddon_path/$ac_path-set.xml
30
-        installed=$?
31
-        sqlite_request "update setxml set installed = $installed where file = '${ac_path#*/}' and variantof = ${ac%:*}"
29
+        if test ! -e $fgaddon_path/$ac_path-set.xml; then
30
+            sqlite_request "update setxml set installed = 0 where file = '${ac_path#*/}' and variantof = ${ac%:*}"
31
+        fi
32
+    done
33
+    for ac in $fgaddon_path/*/*-set.xml; do
34
+        ac=${ac/$fgaddon_path}
35
+        sx=${ac##*/}
36
+        ac=${ac%/*}
37
+        if test -d $fgaddon_path/$ac/.svn; then
38
+            install_type=1
39
+        elif test -d $fgaddon_path/$ac/.git; then
40
+            install_type=2
41
+        else
42
+            install_type=3
43
+        fi
44
+        sqlite_request "update setxml set installed = $install_type
45
+                        where exists (
46
+                            select 1 from aircrafts where name = '${ac/\/}' and setxml.variantof = id
47
+                        )"
32 48
     done
33 49
     if test -r "$database" && md5sum $in_ram_database | sed "s,$in_ram_database,$database," | md5sum --status -c -; then
34 50
         rm -f $in_ram_database
... ...
@@ -71,20 +87,26 @@ update_database () {
71 87
         echo " -> $sx"
72 88
         svn export --quiet --force --revision ${revision[$ac]} $fgaddon_svn/$ac/$sx-set.xml $setxml
73 89
         while xmlgetnext; do
74
-            case "$TAG" in
75
-                ${attributes_case:0:${#attributes_case}-1})
76
-                    test -n "$in_sim" && eval "${TAG//-/_}=\"$VALUE\""
77
-                    test -n "$description" \
78
-                      -a -n "$long_description" \
79
-                      -a -n "$author" \
80
-                      -a -n "$flight_model" \
81
-                      -a -n "$type" && break
82
-                ;;
83
-                'sim') in_sim=1;;
84
-                '/sim') break;;
85
-            esac
90
+            if [[ "$TAG" = @($attributes_case) ]]; then
91
+                test -n "$in_sim" && eval "${TAG//-/_}=\"$VALUE\""
92
+                test -n "$description" \
93
+                  -a -n "$long_description" \
94
+                  -a -n "$author" \
95
+                  -a -n "$flight_model" \
96
+                  -a -n "$type" && break
97
+            elif test "$TAG" = 'sim'; then
98
+                in_sim=1
99
+            elif test "$TAG" = '/sim'; then
100
+                break
101
+            fi
86 102
         done < $setxml
87 103
 
104
+        test -z "$description" \
105
+          -a -z "$long_description" \
106
+          -a -z "$author" \
107
+          -a -z "$flight_model" \
108
+          -a -z "$type" && echo "WARNING: no info found, skipping" && continue
109
+
88 110
         if test -n "$description" -a -z "$flight_model"; then
89 111
             grep -qi 'jsbsim' <<< "$description" && flight_model='jsb'
90 112
             grep -qi 'yasim' <<< "$description" && flight_model='yasim'
... ...
@@ -99,14 +121,12 @@ update_database () {
99 121
             for attribute in ${attributes[@]}; do
100 122
                 dbvalue=$(sqlite_request "select $attribute from setxml where file is '$sx'")
101 123
                 eval "wgvalue=\$$attribute"
102
-                if test "$dbvalue" != "$wgvalue"; then
124
+                if test "$dbvalue" != "$wgvalue" -a -n "$wgvalue"; then
103 125
                     sqlite_request "update setxml set $attribute = '$wgvalue' where file is '$sx'"
104 126
                 fi
105 127
             done
106 128
         else
107
-            test ! -e $fgaddon_path/$ac/$sx-set.xml
108
-            installed=$?
109
-            sqlite_request "insert into setxml values ('$sx', $id, '$description', '$long_description', '$author', '$type', '$flight_model', $installed)"
129
+            sqlite_request "insert into setxml values ('$sx', $id, '$description', '$long_description', '$author', '$type', '$flight_model', 0)"
110 130
         fi
111 131
     done
112 132
 }
... ...
@@ -118,7 +138,8 @@ test -e $database && cp $database $in_ram_database
118 138
 sqlite_request "create table if not exists aircrafts (id integer primary key, name text, revision integer, date integer, author text)"
119 139
 sqlite_request "create table if not exists setxml (file text, variantof integer, description text, long_description text, author text, type text, flight_model text, installed integer)"
120 140
 
121
-attributes_case=$(printf "'%s'|" "${attributes[@]}")
141
+attributes_case=$(printf "%s|" "${attributes[@]}")
142
+attributes_case=${attributes_case:0:-1}
122 143
 latest_revision=$(sqlite_request "select max(revision) from aircrafts")
123 144
 
124 145
 echo "downloading FGADDON history from revision ${latest_revision:-0}"
... ...
@@ -173,6 +194,11 @@ while xmlgetnext; do
173 194
             declare -A _sx
174 195
             for ac in "${!revision[@]}"; do
175 196
                 update_database
197
+                if test -d $fgaddon_path/$ac/.svn \
198
+                && test "$(svn info --show-item=url $fgaddon_path/$ac)" != "$fgaddon_svn/$ac" \
199
+                || test -d $fgaddon_path/$ac -a ! -d $fgaddon_path/$ac/.svn; then
200
+                    echo "INFO: local $ac installed out from repo" >&2
201
+                fi
176 202
             done
177 203
             break
178 204
         ;;