support for susedata.xml
[platform/upstream/libsolv.git] / tools / repo2solv.sh
1 #! /bin/sh
2 # repo2solv
3 #
4 # give it a directory of a local mirror of a repo and this
5 # tries to detect the repo type and generate one SOLV file on stdout
6
7 test_susetags() {
8   if test -s content; then
9     DESCR=`grep DESCRDIR content | cut -d ' ' -f 2`
10     if test -z $DESCR; then
11       DESCR=suse/setup/descr
12     fi
13     test -d $DESCR
14     return $?
15   else
16     return 1
17   fi
18 }
19
20 # this should signal an error if there is a problem
21 set -e 
22
23 LANG=C
24 unset CDPATH
25 parser_options=${PARSER_OPTIONS:-}
26
27
28 dir="$1"
29 cd "$dir" || exit 1
30 if test -d repodata; then
31   cd repodata || exit 2
32
33   # This contains a primary.xml* and maybe patches
34   for i in primary.xml*; do
35     case $i in
36       *.gz) cmd="gzip -dc" ;;
37       *.bz2) cmd="bzip2 -dc" ;;
38       *) cmd="cat" ;;
39     esac
40     # only check the first primary.xml*, in case there are more
41     break
42   done
43   primfile="/nonexist"
44   if test -n "$cmd"; then
45     # we have some primary.xml*
46     primfile=`mktemp` || exit 3
47     $cmd $i | rpmmd2solv $parser_options > $primfile || exit 4
48   fi
49
50   # This contains a susedata.xml* with extended primary data
51  if test -f susedata.xml || test -f susedata.xml.gz || test -f susedata.xml.bz2 ; then
52      for i in susedata.xml*; do
53          case $i in
54              *.gz) cmd="gzip -dc" ;;
55              *.bz2) cmd="bzip2 -dc" ;;
56              *) cmd="cat" ;;
57          esac
58     # only check the first susedata.xml*, in case there are more
59          break
60      done
61      susedatafile="/nonexist"
62      if test -n "$cmd"; then
63     # we have some susedata.xml*
64          susedatafile=`mktemp` || exit 3
65          $cmd $i | rpmmd2solv $parser_options > $susedatafile || exit 4
66      fi
67   fi
68
69   prodfile="/nonexist"
70   if test -f product.xml; then
71     prodfile=`mktemp` || exit 3
72     (
73      echo '<products>'
74      for i in product*.xml*; do
75        case $i in
76          *.gz) gzip -dc "$i" ;;
77          *.bz2) bzip2 -dc "$i" ;;
78          *) cat "$i" ;;
79        esac
80      done
81      echo '</products>'
82     ) | grep -v '\?xml' | rpmmd2solv $parser_options > $prodfile || exit 4
83   fi
84
85
86   # This contains repomd.xml
87   # for now we only read some keys like expiration
88   if test -f repomd.xml || test -f repomd.xml.gz || test -f repomd.xml.bz2 ; then
89       for i in repomd.xml*; do
90           case $i in
91               *.gz) cmd="gzip -dc" ;;
92               *.bz2) cmd="bzip2 -dc" ;;
93               *) cmd="cat" ;;
94           esac
95           # only check the first repomd.xml*, in case there are more
96           break
97       done
98
99       repomdfile="/nonexist"
100       if test -n "$cmd"; then
101       # we have some repomd.xml*
102           repomdfile=`mktemp` || exit 3
103           $cmd $i | repomdxml2solv $parser_options > $repomdfile || exit 4
104       fi
105   fi
106
107   # This contains a updateinfo.xml* and maybe patches
108   if test -f updateinfo.xml || test -f updateinfo.xml.gz || test -f updateinfo.xml.bz2 ; then
109       for i in updateinfo.xml*; do
110           case $i in
111               *.gz) cmd="gzip -dc" ;;
112               *.bz2) cmd="bzip2 -dc" ;;
113               *) cmd="cat" ;;
114           esac
115           # only check the first updateinfo.xml*, in case there are more
116           break
117       done
118       updateinfofile="/nonexist"
119       if test -n "$cmd"; then
120       # we have some updateinfo.xml*
121           updateinfofile=`mktemp` || exit 3
122           $cmd $i | updateinfoxml2solv $parser_options > $updateinfofile || exit 4
123       fi
124   fi
125
126   patchfile="/nonexist"
127   if test -f patches.xml; then
128     patchfile=`mktemp` || exit 3
129     (
130      echo '<patches>'
131      for i in patch-*.xml*; do
132        case $i in
133          *.gz) gzip -dc "$i" ;;
134          *.bz2) bzip2 -dc "$i" ;;
135          *) cat "$i" ;;
136        esac
137      done
138      echo '</patches>'
139     ) | grep -v '\?xml' | patchxml2solv $parser_options > $patchfile || exit 4
140   fi
141
142   # This contains a deltainfo.xml*
143   if test -f deltainfo.xml || test -f deltainfo.xml.gz || test -f deltainfo.xml.bz2 ; then
144       for i in deltainfo.xml*; do
145           case $i in
146               *.gz) cmd="gzip -dc" ;;
147               *.bz2) cmd="bzip2 -dc" ;;
148               *) cmd="cat" ;;
149           esac
150           # only check the first deltainfo.xml*, in case there are more
151           break
152       done
153       deltainfofile="/nonexist"
154       if test -n "$cmd"; then
155       # we have some deltainfo.xml*
156           deltainfofile=`mktemp` || exit 3
157           $cmd $i | deltainfoxml2solv $parser_options > $deltainfofile || exit 4
158       fi
159   fi
160
161   # Now merge primary, patches, updateinfo, and deltainfo
162   if test -s $repomdfile; then
163     m_repomdfile=$repomdfile
164   fi
165   if test -s $susedatafile; then
166     m_susedata=$susedatafile
167   fi
168   if test -s $primfile; then
169     m_primfile=$primfile
170   fi
171   if test -s $prodfile; then
172     m_prodfile=$prodfile
173   fi
174   if test -s $patchfile; then
175     m_patchfile=$patchfile
176   fi
177   if test -s $updateinfofile; then
178     m_updateinfofile=$updateinfofile
179   fi
180   if test -s $deltainfofile; then
181     m_deltainfofile=$deltainfofile
182   fi
183   mergesolv $m_repomdfile $m_primfile $m_susedatafile $m_prodfile $m_patchfile $m_updateinfofile $m_deltainfofile
184   rm -f $repomdfile $primfile $prodfile $patchfile $updateinfofile $deltainfofile
185
186 elif test_susetags; then
187   olddir=`pwd`
188   DESCR=`grep DESCRDIR content | cut -d ' ' -f 2`
189   if test -z $DESCR; then
190     DESCR=suse/setup/descr
191   fi
192   cd ${DESCR} || exit 2
193   (
194     # First packages
195     if test -s packages.gz; then
196       gzip -dc packages.gz
197     elif test -s packages.bz2; then
198       bzip2 -dc packages.bz2
199     elif test -s packages; then
200       cat packages
201     fi
202
203     # DU
204     if test -s packages.DU.gz; then
205       gzip -dc packages.DU.gz
206     elif test -s packages.DU.bz2; then
207       bzip2 -dc packages.DU.bz2
208     elif test -s packages.DU; then
209       cat packages.DU
210     fi
211
212     # Now default language
213     if test -s packages.en.gz; then
214       gzip -dc packages.en.gz
215     elif test -s packages.en.bz2; then
216       bzip2 -dc packages.en.bz2
217     elif test -s packages.en; then
218       cat packages.en
219     fi
220
221     # Now patterns.  Not simply those files matching *.pat{,.gz,bz2},
222     # but only those mentioned in the file 'patterns'
223     if test -f patterns; then
224       for i in `cat patterns`; do
225         test -s "$i" || continue
226         case $i in
227           *.gz) gzip -dc "$i" ;;
228           *.bz2) bzip2 -dc "$i" ;;
229           *) cat "$i" ;;
230         esac
231       done
232     fi
233
234     # Now all other packages.{lang}.  Needs to come last as it switches
235     # languages for all following susetags files
236     for i in packages.*; do
237       case $i in
238         *.gz) name="${i%.gz}" ; prog="gzip -dc" ;;
239         *.bz2) name="${i%.bz2}" ; prog="bzip2 -dc" ;;
240         *) name="$i"; prog=cat ;;
241       esac
242       case $name in
243         # ignore files we handled already
244         *.DU | *.en | *.FL | packages ) continue ;;
245         *) 
246           suff=${name#packages.}
247           echo "=Lan: $suff"
248           eval "$prog '$i'" ;;
249       esac
250     done
251
252   ) | susetags2solv -c "${olddir}/content" $parser_options || exit 4
253   cd "$olddir"
254 else
255   rpms=''
256   for r in *.rpm ; do
257     rpms="$rpms$r
258 "
259   done
260   if test -n "$rpms" ; then
261       echo "$rpms" | rpms2solv -m -
262   else
263       exit 1
264   fi
265 fi