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