Now that I can read content files, let's use that.
[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 LANG=C
8
9 dir="$1"
10 cd "$dir" || exit 1
11 if test -d repodata; then
12   cd repodata || exit 2
13
14   # This contains a primary.xml* and maybe patches
15   for i in primary.xml*; do
16     case $i in
17       *.gz) cmd="gzip -dc" ;;
18       *.bz2) cmd="bzip2 -dc" ;;
19       *) cmd="cat" ;;
20     esac
21     # only check the first primary.xml*, in case there are more
22     break
23   done
24   primfile="/nonexist"
25   if test -n "$cmd"; then
26     # we have some primary.xml*
27     primfile=`mktemp` || exit 3
28     $cmd $i | rpmmd2solv > $primfile
29   fi
30
31   patchfile="/nonexist"
32   if test -f patches.xml; then
33     patchfile=`mktemp` || exit 3
34     (
35      echo '<patches>'
36      for i in patch-*.xml*; do
37        case $i in
38          *.gz) gzip -dc "$i" ;;
39          *.bz2) bzip2 -dc "$i" ;;
40          *) cat "$i" ;;
41        esac
42      done
43      echo '</patches>'
44     ) | grep -v '\?xml' | patchxml2solv > $patchfile
45   fi
46
47   # Now merge primary and patches
48   if test -s $primfile && test -s $patchfile; then
49     mergesolv $primfile $patchfile
50   elif test -s $primfile; then
51     cat $primfile
52   elif test -s $patchfile; then
53     cat $patchfile
54   fi
55   rm -f $primfile $patchfile
56 elif test -d suse/setup/descr && test -s content; then
57   olddir=`pwd`
58   cd suse/setup/descr || exit 2
59   filepack=`mktemp` || exit 3
60   filecont=`mktemp` || exit 3
61   (
62     # First packages
63     if test -s packages.gz; then
64       gzip -dc packages.gz
65     elif test -s packages.bz2; then
66       bzip2 -dc packages.bz2
67     elif test -s packages; then
68       cat packages
69     fi
70
71     # XXX need to do something with packages.DU and packages.{lang}
72
73     # Now patterns.  Not simply those files matching *.pat{,.gz,bz2},
74     # but only those mentioned in the file 'patterns'
75     if test -f patterns; then
76       for i in `cat patterns`; do
77         test -s "$i" || continue
78         case $i in
79           *.gz) gzip -dc "$i" ;;
80           *.bz2) bzip2 -dc "$i" ;;
81           *) cat "$i" ;;
82         esac
83       done
84     fi
85   ) | susetags2solv > $filepack
86   cd "$olddir"
87   content2solv < content > $filecont
88   mergesolv $filecont $filepack
89   rm -f $filepack $filecont
90 fi