- include deltainfo.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 # this should signal an error if there is a problem
8 set -e 
9
10 LANG=C
11 parser_options=${PARSER_OPTIONS:-}
12
13
14 dir="$1"
15 cd "$dir" || exit 1
16 if test -d repodata; then
17   cd repodata || exit 2
18
19   # This contains a primary.xml* and maybe patches
20   for i in primary.xml*; do
21     case $i in
22       *.gz) cmd="gzip -dc" ;;
23       *.bz2) cmd="bzip2 -dc" ;;
24       *) cmd="cat" ;;
25     esac
26     # only check the first primary.xml*, in case there are more
27     break
28   done
29   primfile="/nonexist"
30   if test -n "$cmd"; then
31     # we have some primary.xml*
32     primfile=`mktemp` || exit 3
33     $cmd $i | rpmmd2solv $parser_options > $primfile || exit 4
34   fi
35
36   # This contains a updateinfo.xml* and maybe patches
37   if test -f updateinfo.xml || test -f updateinfo.xml.gz || test -f updateinfo.xml.bz2 ; then
38       for i in updateinfo.xml*; do
39           case $i in
40               *.gz) cmd="gzip -dc" ;;
41               *.bz2) cmd="bzip2 -dc" ;;
42               *) cmd="cat" ;;
43           esac
44           # only check the first updateinfo.xml*, in case there are more
45           break
46       done
47       updateinfofile="/nonexist"
48       if test -n "$cmd"; then
49       # we have some updateinfo.xml*
50           updateinfofile=`mktemp` || exit 3
51           $cmd $i | updateinfoxml2solv $parser_options > $updateinfofile || exit 4
52       fi
53   fi
54
55   patchfile="/nonexist"
56   if test -f patches.xml; then
57     patchfile=`mktemp` || exit 3
58     (
59      echo '<patches>'
60      for i in patch-*.xml*; do
61        case $i in
62          *.gz) gzip -dc "$i" ;;
63          *.bz2) bzip2 -dc "$i" ;;
64          *) cat "$i" ;;
65        esac
66      done
67      echo '</patches>'
68     ) | grep -v '\?xml' | patchxml2solv $parser_options > $patchfile || exit 4
69   fi
70
71   # This contains a deltainfo.xml*
72   if test -f deltainfo.xml || test -f deltainfo.xml.gz || test -f deltainfo.xml.bz2 ; then
73       for i in deltainfo.xml*; do
74           case $i in
75               *.gz) cmd="gzip -dc" ;;
76               *.bz2) cmd="bzip2 -dc" ;;
77               *) cmd="cat" ;;
78           esac
79           # only check the first deltainfo.xml*, in case there are more
80           break
81       done
82       deltainfofile="/nonexist"
83       if test -n "$cmd"; then
84       # we have some deltainfo.xml*
85           deltainfofile=`mktemp` || exit 3
86           $cmd $i | deltainfoxml2solv $parser_options > $deltainfofile || exit 4
87       fi
88   fi
89
90   # Now merge primary, patches, updateinfo, and deltainfo
91   if test -s $primfile; then
92     m_primfile=$primfile
93   fi
94   if test -s $patchfile; then
95     m_patchfile=$patchfile
96   fi
97   if test -s $updateinfofile; then
98     m_updateinfofile=$updateinfofile
99   fi
100   if test -s $deltainfofile; then
101     m_deltainfofile=$deltainfofile
102   fi
103   mergesolv $m_primfile $m_patchfile $m_updateinfofile $m_deltainfofile
104   rm -f $primfile $patchfile $updateinfofile $deltainfofile
105
106 elif test -d suse/setup/descr && test -s content; then
107   olddir=`pwd`
108   cd suse/setup/descr || exit 2
109   (
110     # First packages
111     if test -s packages.gz; then
112       gzip -dc packages.gz
113     elif test -s packages.bz2; then
114       bzip2 -dc packages.bz2
115     elif test -s packages; then
116       cat packages
117     fi
118
119     # DU
120     if test -s packages.DU.gz; then
121       gzip -dc packages.DU.gz
122     elif test -s packages.DU.bz2; then
123       bzip2 -dc packages.DU.bz2
124     elif test -s packages.DU; then
125       cat packages.DU
126     fi
127
128     # Now default language
129     if test -s packages.en.gz; then
130       gzip -dc packages.en.gz
131     elif test -s packages.en.bz2; then
132       bzip2 -dc packages.en.bz2
133     elif test -s packages.en; then
134       cat packages.en
135     fi
136
137     # Now patterns.  Not simply those files matching *.pat{,.gz,bz2},
138     # but only those mentioned in the file 'patterns'
139     if test -f patterns; then
140       for i in `cat patterns`; do
141         test -s "$i" || continue
142         case $i in
143           *.gz) gzip -dc "$i" ;;
144           *.bz2) bzip2 -dc "$i" ;;
145           *) cat "$i" ;;
146         esac
147       done
148     fi
149
150     # Now all other packages.{lang}.  Needs to come last as it switches
151     # languages for all following susetags files
152     for i in packages.*; do
153       case $i in
154         *.gz) name="${i%.gz}" ; prog="gzip -dc" ;;
155         *.bz2) name="${i%.bz2}" ; prog="bzip2 -dc" ;;
156         *) name="$i"; prog=cat ;;
157       esac
158       case $name in
159         # ignore files we handled already
160         *.DU | *.en | *.FL | packages ) continue ;;
161         *) 
162           suff=${name#packages.}
163           echo "=Lan: $suff"
164           eval "$prog '$i'" ;;
165       esac
166     done
167
168   ) | susetags2solv -c "${olddir}/content" $parser_options || exit 4
169   cd "$olddir"
170 else
171   rpms=''
172   for r in *.rpm ; do
173     rpms="$rpms$r
174 "
175   done
176   if test -n "$rpms" ; then
177       echo "$rpms" | rpms2solv -m -
178   else
179       exit 1
180   fi
181 fi