- add support for the package's URL [bnc#402434]
[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 updateinfo.xml* and maybe patches
51   if test -f updateinfo.xml || test -f updateinfo.xml.gz || test -f updateinfo.xml.bz2 ; then
52       for i in updateinfo.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 updateinfo.xml*, in case there are more
59           break
60       done
61       updateinfofile="/nonexist"
62       if test -n "$cmd"; then
63       # we have some updateinfo.xml*
64           updateinfofile=`mktemp` || exit 3
65           $cmd $i | updateinfoxml2solv $parser_options > $updateinfofile || exit 4
66       fi
67   fi
68
69   patchfile="/nonexist"
70   if test -f patches.xml; then
71     patchfile=`mktemp` || exit 3
72     (
73      echo '<patches>'
74      for i in patch-*.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 '</patches>'
82     ) | grep -v '\?xml' | patchxml2solv $parser_options > $patchfile || exit 4
83   fi
84
85   # This contains a deltainfo.xml*
86   if test -f deltainfo.xml || test -f deltainfo.xml.gz || test -f deltainfo.xml.bz2 ; then
87       for i in deltainfo.xml*; do
88           case $i in
89               *.gz) cmd="gzip -dc" ;;
90               *.bz2) cmd="bzip2 -dc" ;;
91               *) cmd="cat" ;;
92           esac
93           # only check the first deltainfo.xml*, in case there are more
94           break
95       done
96       deltainfofile="/nonexist"
97       if test -n "$cmd"; then
98       # we have some deltainfo.xml*
99           deltainfofile=`mktemp` || exit 3
100           $cmd $i | deltainfoxml2solv $parser_options > $deltainfofile || exit 4
101       fi
102   fi
103
104   # Now merge primary, patches, updateinfo, and deltainfo
105   if test -s $primfile; then
106     m_primfile=$primfile
107   fi
108   if test -s $patchfile; then
109     m_patchfile=$patchfile
110   fi
111   if test -s $updateinfofile; then
112     m_updateinfofile=$updateinfofile
113   fi
114   if test -s $deltainfofile; then
115     m_deltainfofile=$deltainfofile
116   fi
117   mergesolv $m_primfile $m_patchfile $m_updateinfofile $m_deltainfofile
118   rm -f $primfile $patchfile $updateinfofile $deltainfofile
119
120 elif test_susetags; then
121   olddir=`pwd`
122   DESCR=`grep DESCRDIR content | cut -d ' ' -f 2`
123   if test -z $DESCR; then
124     DESCR=suse/setup/descr
125   fi
126   cd ${DESCR} || exit 2
127   (
128     # First packages
129     if test -s packages.gz; then
130       gzip -dc packages.gz
131     elif test -s packages.bz2; then
132       bzip2 -dc packages.bz2
133     elif test -s packages; then
134       cat packages
135     fi
136
137     # DU
138     if test -s packages.DU.gz; then
139       gzip -dc packages.DU.gz
140     elif test -s packages.DU.bz2; then
141       bzip2 -dc packages.DU.bz2
142     elif test -s packages.DU; then
143       cat packages.DU
144     fi
145
146     # Now default language
147     if test -s packages.en.gz; then
148       gzip -dc packages.en.gz
149     elif test -s packages.en.bz2; then
150       bzip2 -dc packages.en.bz2
151     elif test -s packages.en; then
152       cat packages.en
153     fi
154
155     # Now patterns.  Not simply those files matching *.pat{,.gz,bz2},
156     # but only those mentioned in the file 'patterns'
157     if test -f patterns; then
158       for i in `cat patterns`; do
159         test -s "$i" || continue
160         case $i in
161           *.gz) gzip -dc "$i" ;;
162           *.bz2) bzip2 -dc "$i" ;;
163           *) cat "$i" ;;
164         esac
165       done
166     fi
167
168     # Now all other packages.{lang}.  Needs to come last as it switches
169     # languages for all following susetags files
170     for i in packages.*; do
171       case $i in
172         *.gz) name="${i%.gz}" ; prog="gzip -dc" ;;
173         *.bz2) name="${i%.bz2}" ; prog="bzip2 -dc" ;;
174         *) name="$i"; prog=cat ;;
175       esac
176       case $name in
177         # ignore files we handled already
178         *.DU | *.en | *.FL | packages ) continue ;;
179         *) 
180           suff=${name#packages.}
181           echo "=Lan: $suff"
182           eval "$prog '$i'" ;;
183       esac
184     done
185
186   ) | susetags2solv -c "${olddir}/content" $parser_options || exit 4
187   cd "$olddir"
188 else
189   rpms=''
190   for r in *.rpm ; do
191     rpms="$rpms$r
192 "
193   done
194   if test -n "$rpms" ; then
195       echo "$rpms" | rpms2solv -m -
196   else
197       exit 1
198   fi
199 fi